[Lazarus] Application.QueueAsyncCall and "conversion between ordinals and pointers is not portable"

Luca Olivetti luca at wetron.es
Fri Nov 26 13:15:07 CET 2021


Hello,

Application.QueueAsyncCall is defined as

procedure Application.QueueAsyncCall(const AMethod:TDataEvent; Data: 
PtrInt);

When I want to pass a string or a big structure as "Data", I create a 
pointer and use that, casting it as PtrInt, then I use and free it in 
the Async Method., e.g.

procedure TServerThread.Log(const msg:string);
var
   s: PString;
begin
   new(s);
   s^:=msg;
   Application.QueueAsyncCall(@MainForm.LogServer, ptrint(s));
end;

procedure TMainForm.LogServer(data: ptrint);
var s:PString;
begin
   ptruint(s):=data; //ptrint here gives a warning "use an unsigned type"
   LogMemo.Lines.Add(s^);
   Dispose(s);
end;


But that gives a hint "conversion between ordinals and pointers is not 
portable". The suggestion I found is to use {%H-} to silence that hint 
(which I did), but is there a better way?

Why Data is defined as PtrInt and not pointer?

Bye
-- 
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007


More information about the lazarus mailing list