Home > Back-end >  (Delphi) casts and the combination of the generic type for help!
(Delphi) casts and the combination of the generic type for help!

Time:09-23

Currently have a project to call in Delphi series of Webservice (Delphi), normal we are written like this:

MHttpRio:=THTTPRIO. Create (nil);
XXXXXXXXXXXXXXX mHttpRio. URL:=' ';
Result:=(mHttpRio as ITest). The Test;

Think Delphi is generic, then design a function:
GetRemoteService : T;
The begin
MHttpRio:=THTTPRIO. Create (nil);
XXXXXXXXXXXXXXX mHttpRio. URL:=' ';
//the problem comes, how do I put in for mHttpRio into T type back??
end;

I only need when actual call;
Var
MService: ITest;
The begin
MService:=GetRemoteService;
Result:=mService. Test;
end;

Note: I design the purpose of this function: 1, the number of web service interface type is not the same;
2, each Webservice url is not the same, but you can to get through the interface type

CodePudding user response:

Own within 5 minutes after Posting address:
The function GetRemoteService : T;
The begin
MHttpRio:=THTTPRIO. Create (nil);
XXXXXXXXXXXXXXX mHttpRio. URL:=' ';
mHttpRio. QueryInterface (GetTypeData (TypeInfo (T)). The Guid, Result);
end;

CodePudding user response:

Posting really contribute to the solution of the problem, GetTypeData (TypeInfo (T)). The Guid the good

CodePudding user response:

Resolved, that,,

CodePudding user response:

Generics are not ripe,
By the way, the Supports can't use?

CodePudding user response:

Good! And learn a recruit!

CodePudding user response:

Still use D7 passing, generics are good
  • Related