Stacey,

They broke this in D3. I had to rewrite a lot of my old Borland Pascal code at that time. Borland also made a statement that the order of evaluation is not defined in the language and should not be relied on. It has nothing to do with the calling convention.

Its a pain only for string manipulation.  :-)

Stacey Verner wrote:

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.

The 3^rd parameter is evaluated first followed by 4, 5, 6 etc and then the 2^nd and then the 1^st .

This appears to be because the default calling convention is *register* 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. The documentation also says that is supposed to pass the from left to right, but it obviously doesn't.

You can download an example to see for yourself!

http://www.verner.co.nz/download/FunctionCall.zip

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:

LString := 'Stacey,G,Verner';

and call:

LFirstName := Extract(LString, ',');

LInitial := Extract(LString, ',');

LLastName := Extract(LString, ',');

In this case if we had a function like:

function FullName(PFirstName, PInitial, PLastName: String): String;

and you call it with:

LName := FullName(Extract(LString, ','), Extract(LString, ','), Extract(LString, ','));

then we'll get the wrong result.

Stacey

Stacey Verner             Ph:   +64-9-4154790
Software Developer        Fax:  +64-9-4154791
                          DDI:  +64-9-4154797
Email: [EMAIL PROTECTED] <BLOCKED::mailto:[EMAIL PROTECTED]>

CJN Technologies Ltd.

PO Box 302-278, North Harbour, Auckland 1330, New Zealand
12 Piermark Drive, North Harbour, Auckland, New Zealand
Visit our website at http://www.cjntech.co.nz/ <BLOCKED::http://www.cjntech.co.nz/>

------------------------------------------------------------------------

_______________________________________________
Delphi mailing list
Delphi@ns3.123.co.nz
http://ns3.123.co.nz/mailman/listinfo/delphi

--
*Rohit Gupta*
* B.E. Elec.   M.E.   Mem IEEE    Associate IEE*
*Technical Manager*
*Computer Fanatics Limited*
** *Tel* +64 9 4892280
*Fax*    +64 9 4892290
*Email  [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>**
*Web    *www.cfl.co.nz <http://www.cfl.co.nz/>

------------------------------------------------------------------------
This email and any attachments contain information, which is confidential and may be subject to legal privilege and copyright. If you are not the intended recipient, you must not use, distribute or copy this email or attachments. If you have received this in error, please notify us immediately by return email and then delete this email and any attachments.
_______________________________________________
Delphi mailing list
Delphi@ns3.123.co.nz
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to