Memory error in Assembly code with newer version of Delphi

163 Views Asked by At

Can anyone tell me why this code works in Delphi 7, but in version 10.4 it has a memory error?

procedure ChatPrintf(ChatPrintMSG: PChar);
var
  ChatPrint: Cardinal;

  procedure ChatPrintASM(ChatPrintMSG: PChar); assembler;
  asm
    lea edx, [ChatPrintMSG]
    push edx
    call [ChatPrint]
    pop edx
  end;
begin
  ChatPrint := $009E0C30;
  ChatPrintASM(ChatPrintMSG);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  ChatPrintf('it: works');
end;
1

There are 1 best solutions below

4
Rohit Gupta On

As Andreas has mentioned, the default string type has changed. The easiest way to fix it, is to replace pchar with pansichar

The new definition would be

procedure ChatPrintASM(ChatPrintMSG: PAnsiChar);