Using anonymous methods on AsyncEx calls

delphi

(estebanp) #1

Hello,

Delphi, Tokyo, latest release - 1.

Can we use anonymous methods on the AsyncEx calls generated on the Intf files?

A normal declaration will look something like:
fService.AsyncCallEx.BeginRequest(aParameter, aCallBackMethod);

aCallbackMethod is declared on RO as TROAsyncCallBack = procedure (const aRequest: IROAsyncRequest)

If it is possible, how do you do it? I might be trying it all wrong.

It is my understanding that in order for it to happen TROAsyncCallBack has to be declared as
TROAsyncCallBack = reference to procedure(const aRequest:IROAsyncRequest)

So we can do something like

fService.AsyncCallEx.BeginRequest(aParameter,
procedure (aRequest:IROAsyncRequest)
begin
fService.AsyncCallEx.EndRequest(aRequest);
fLogger.Log(‘Done’);
end);

If it is not supported, it is a nice and simple thing to add and keep things modern.

Thank you.


(EvgenyK) #2

pls review the Phone Photo Server sample.

we can’t use anonymous methods here because they aren’t supported by old versions of Delphi.


EDIT: you can try to declare it locally as

  TROAsyncCallback = reference to procedure (const aRequest: IROAsyncRequest);

for using anonymous methods


(estebanp) #3

Thank you Evgeny.

Probably that will work. I thought reference to procedure supports not only TProcedure, but also Procedure of object.

So adding,
{$IFDEF DELPHIXE2UP} // or whatever version it was fully supported, probably D2010
TROAsyncCallback = reference to procedure (const aRequest: IROAsyncRequest);
{$ELSE}
TROAsyncCallback = procedure (const aRequest: IROAsyncRequest) of object;
{$ENDIF}

will work transparently, am i wrong? the uRO units already have the switches everywhere, any reason why not to add it by default to the uROAsync unit?


(EvgenyK) #4

our code won’t be portable between D7 and modern versions of Delphi.
for example the Phone Photo Server sample will be broken …
we will review possibility to adding a special condition into RemObjects.inc that can change this behavior


(RemObjects) #5

Thanks, logged as bugs://82056


(RemObjects) #6

bugs://82056 got closed with status fixed.