<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v = 
"urn:schemas-microsoft-com:vml" xmlns:o = 
"urn:schemas-microsoft-com:office:office" xmlns:w = 
"urn:schemas-microsoft-com:office:word" xmlns:m = 
"http://schemas.microsoft.com/office/2004/12/omml" xmlns:ns0 = 
"urn:schemas-microsoft-com:office:smarttags"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4943.400" name=GENERATOR>
<STYLE>@font-face {
        font-family: Cambria Math;
}
@font-face {
        font-family: Calibri;
}
@page Section1 {size: 612.0pt 792.0pt; margin: 72.0pt 72.0pt 72.0pt 72.0pt; }
P.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
LI.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
DIV.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.EmailStyle17 {
        COLOR: windowtext; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal-compose
}
.MsoChpDefault {
        mso-style-type: export-only
}
DIV.Section1 {
        page: Section1
}
</STYLE>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=EN-NZ vLink=purple link=blue bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi Stacey,</FONT></DIV>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  <A title=stacey@cjntech.co.nz href="mailto:stacey@cjntech.co.nz">Stacey 
  Verner</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A title=delphi@ns3.123.co.nz 
  href="mailto:delphi@ns3.123.co.nz">NZ Borland Developers Group - Delphi 
  List</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Friday, February 16, 2007 11:34 
  AM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> [DUG] Delphi Calling Convetion 
  is Weird!!</DIV>
  <DIV><FONT face=Arial size=2></FONT><BR></DIV>
  <DIV class=Section1>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">After an odd bug 
  and a bit of testing I have found that the parameters in Delphi (tested 6 and 
  2006) are evaluated very strangely.<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">The 3<SUP>rd</SUP> 
  parameter is evaluated first followed by 4, 5, 6 etc and then the 
  2<SUP>nd</SUP> and then the 1<SUP>st</SUP>.</SPAN></P></DIV></BLOCKQUOTE>
<P class=MsoNormal><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">Always this order? Or 
does it vary sometimes if there are a different number of parameters? or if the 
mix of parameters varies, ie between static values, in-line expressions, 
function invocations?</SPAN></P>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">This appears to be 
  because the default calling convention is <B>register</B> which (from the 
  documentation) puts up to 3 parameters in registers and the rest on the stack. 
  It seems to process the stack ones first from parameters 3 onwards (Why 3? 
  Shouldn’t it be 4 if we are putting 3 into registers. Must be only putting 2 
  in the registers), and then the first 2 in reverse order into the registers. 
  </SPAN></P></BLOCKQUOTE>
<P class=MsoNormal><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">It may be that the 
two registers it uses for parameters 1 and 2 are also used in calculating 
parameter addresses in any call; or used in evaluating expressions in 
parameters;&nbsp;if so, parameters 1 and 2 can't be set into the registers until 
all the rest of the parameters have been evaluated.&nbsp;Also, registers 
containing parameters of the main function can't be set before calling any 
functions in the parameters, if they will be used for parameters of those 
functions.</SPAN></P>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">The documentation 
  also says that is supposed to pass the from left to right, but it obviously 
  doesn’t.</SPAN></P></BLOCKQUOTE>
<P class=MsoNormal><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">Do you mean the order 
in which parameter expressions are evaluated? Yes, if that's defined, the 
compiler should respect it. Or the documentation should be changed to included a 
caveat about the possible results of the compiler's optimisation.</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">You'd be safest to 
call your functions and save their results in temporary variables which you then 
pass to the main function. That way you can control the order of the side 
effects yourself and it'll work whatever the compiler does.</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">Brian</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"></SPAN>&nbsp;</P>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">You can download an 
  example to see for yourself!<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><A 
  href="http://www.verner.co.nz/download/FunctionCall.zip">http://www.verner.co.nz/download/FunctionCall.zip</A><o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">If you are 
  interested how we found this, we have a simple function that strips the first 
  delimited item from a string returning the item and removing it from the input 
  string. You can have a string something like:<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">LString := 
  ‘Stacey,G,Verner’;<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">and 
  call:<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">LFirstName := 
  Extract(LString, ‘,’);<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">LInitial := 
  Extract(LString, ‘,’);<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">LLastName := 
  Extract(LString, ‘,’);<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">In this case if we 
  had a function like:<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">function 
  FullName(PFirstName, PInitial, PLastName: String): 
  String;<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">and you call it 
  with:<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">LName := 
  FullName(Extract(LString, ‘,’), Extract(LString, ‘,’), Extract(LString, 
  ‘,’));<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">then we’ll get the 
  wrong result.<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"><o:p>&nbsp;</o:p></SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-US 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'">Stacey</SPAN><o:p></o:p></P>
  <P class=MsoNormal><o:p>&nbsp;</o:p></P>
  <P class=MsoNormal><SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Stacey 
  Verner&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  Ph:&nbsp;&nbsp; +64-9-4154790<BR>Software 
  Developer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fax:&nbsp; 
  +64-9-4154791<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  DDI:&nbsp; 
  +64-9-4154797<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp;&nbsp; Email: </SPAN><SPAN 
  style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"><A 
  title=mailto:stacey@cjntech.co.nz 
  href="BLOCKED::mailto:stacey@cjntech.co.nz"><SPAN 
  style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">stacey@cjntech.co.nz</SPAN></A><o:p></o:p></SPAN></P>
  <DIV class=Section1>
  <P class=MsoNormal><SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">CJN Technologies 
  Ltd.</SPAN><SPAN 
  style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"><o:p></o:p></SPAN></P></DIV>
  <P class=MsoNormal><SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><ns0:Street><ns0:address>PO 
  Box 302-278, North</ns0:address></ns0:Street> Harbour, 
  <ns0:City>Auckland</ns0:City> 1330, <ns0:place><ns0:country-region>New 
  Zealand</ns0:country-region></ns0:place><BR><ns0:Street><ns0:address>12 
  Piermark Drive, North</ns0:address></ns0:Street> Harbour, 
  <ns0:place><ns0:City>Auckland</ns0:City>, <ns0:country-region>New 
  Zealand</ns0:country-region></ns0:place><BR>Visit our website at </SPAN><SPAN 
  style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"><A 
  title=http://www.cjntech.co.nz/ 
  href="BLOCKED::http://www.cjntech.co.nz/"><SPAN 
  style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">http://www.cjntech.co.nz/</SPAN></A></SPAN><o:p></o:p></P>
  <P>
  <HR>

  <P></P>_______________________________________________<BR>Delphi mailing 
  list<BR>Delphi@ns3.123.co.nz<BR>http://ns3.123.co.nz/mailman/listinfo/delphi<BR></BLOCKQUOTE></BODY></HTML>