[Lazarus] Windows.PostMessage vs Application.QueueAsyncCall

Joao Morais l at joaomorais.com.br
Tue Mar 18 17:52:22 CET 2014


Em 18/03/14 10:47, Marcos Douglas escreveu:
> a form needs to notify many windows
> using asynchronous messages. PostMessage do that but some programmers
> say this is an old Windowish approach so, I'm searching another method
> to do the same PostMessage does and making the code more cross.

I missed the "async" part, sorry. What about reuse App.QueueAsyncCall 
with interface?

======>>>======

type
   IProcCallback = interface
     procedure ASync(data: ptrint);
   end;

   TProc = class(TObject)
   private
     FCallback: IProcCallback;
   public
     constructor Create(const ACallback: IProcCallback);
     procedure DoStuff;
   end;

constructor TProc.Create(const ACallback: IProcCallback);
begin
   inherited Create;
   FCallback := ACallback;
end;

procedure TProc.DoStuff;
begin
   //...
   Application.QueueAsyncCall(@FCallback.ASync, 0);
end;

======<<<======

You can also use {$interfaces corba} if you don't use objects with refcount.

Following this architecture, the responsible for creating TProc instance 
(let's say, TMain) needs to know someone that implements IProcCallback, 
which can be itself (TMain) of course. TMain knows TProc. TProc, TMain 
and others know IProcCallback, and IProcCallback doesn't know anyone.






More information about the Lazarus mailing list