Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2021-11

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

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti

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

Reply by email

Mattias Gaertner
to Luca Olivetti
Show quoted text 34 lines
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?

Sometimes you need an integer, sometimes a pointer, and afair at the time when it was added the compiler did not warn typecasting PtrInt to Pointer.

Mattias

Bye

Reply by email

Luca Olivetti
to Mattias Gaertner

El 29/11/21 a les 17:54, Mattias Gaertner via lazarus ha escrit:

Show quoted text 41 lines
On Fri, 26 Nov 2021 13:15:07 +0100 Luca Olivetti via lazarus wrote: > 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? Sometimes you need an integer, sometimes a pointer, and afair at the time when it was added the compiler did not warn typecasting PtrInt to Pointer.

True. I checked and now it even gives an hint for an integer typecasted to a pointer, so defining it as a pointer would not solve the problem if you need to pass a bare integer as data :-(

Bye

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

Reply by email