<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr">Dennis <<a href="mailto:dec12@avidsoft.com.hk">dec12@avidsoft.com.hk</a>> schrieb am Mi., 18. Juli 2018, 17:19:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The following delphi code when compiled by FPC, raised these errors:<br>
Compile Project, Target: lib\x86_64-win64\Project1.exe: Exit code 1, <br>
Errors: 10, Warnings: 2<br>
StrBuffer.pas(100,19) Error: Unknown identifier "EAX"<br>
StrBuffer.pas(100,23) Error: Assembler syntax error in operand<br>
StrBuffer.pas(100,24) Error: Unknown identifier "EBP"<br>
StrBuffer.pas(100,29) Error: Invalid constant expression<br>
StrBuffer.pas(100,29) Error: Invalid reference syntax<br>
StrBuffer.pas(100,29) Warning: No size specified and unable to determine <br>
the size of the operands, using DWORD as default<br>
StrBuffer.pas(207,19) Error: Unknown identifier "EAX"<br>
StrBuffer.pas(207,23) Error: Assembler syntax error in operand<br>
StrBuffer.pas(207,24) Error: Unknown identifier "EBP"<br>
StrBuffer.pas(207,29) Error: Invalid constant expression<br>
StrBuffer.pas(207,29) Error: Invalid reference syntax<br>
StrBuffer.pas(207,29) Warning: No size specified and unable to determine <br>
the size of the operands, using DWORD as default<br>
<br>
Can anyone help me?<br>
<br>
class procedure TStrBuffer.Error(const Msg: string; Data: Integer);<br>
<br>
   function ReturnAddr: Pointer;<br>
   asm<br>
           MOV     EAX,[EBP+4]<br>
   end;<br>
<br>
begin<br>
   raise EListError.CreateFmt(Msg, [Data])at ReturnAddr;<br>
end;<br></blockquote></div><div dir="auto"><br></div><div dir="auto">There are two ways to solve this.</div><div dir="auto"><br></div><div dir="auto">The first one is an easy one, however the code still won't be platform independent due to the assembly code. For this simply add "{$asmmode intel}" at the top. </div><div dir="auto"><br></div><div dir="auto">The second solution is cross platform and with correct checks also Delphi compatible:</div><div dir="auto"><br></div><div dir="auto">=== code begin ===</div><div dir="auto"><span style="font-family:sans-serif">raise EListError.CreateFmt(Msg, [Data]) at</span><br></div><div dir="auto"><span style="font-family:sans-serif">{$ifdef fpc} </span></div><div dir="auto">get_caller_addr(get_frame),  <br style="">    get_caller_frame(get_frame)</div><div dir="auto">{$else}</div><div dir="auto">ReturnAddr</div><div dir="auto">{$endif} ;<br></div><div dir="auto">=== code end ===</div><div dir="auto"><br></div><div dir="auto">Disable the ReturnAddr function also with "{$ifndef fpc}...{$endif}" and you should be set. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div>