Best practice for manually creating client components in Delphi?


I’ve got the following code in my application:

Channel := TROIndyHTTPChannel.Create(nil);

Channel.TargetUrl := 'http://' + Host + ':' + IntToStr(Port) + '/bin/';

BinMsg := TROBinMessage.Create;

Service := TRORemoteService.Create(nil);

Service.Channel := Channel;
Service.Message := BinMsg;

PrintService := (Service as IPrintService);

The server exposes multiple services, so is it possible to cast the Service to the appropriate services?

PrintService := (Service as IPrintService);
DataService := (Service as IDataService);

And what is the difference between this and what is shown below?

Channel := TROIndyHTTPChannel.Create(nil);

Channel.TargetUrl := 'http://' + Host + ':' + IntToStr(Port) + '/bin/';

BinMsg := TROBinMessage.Create;

PrintService := CoPrintService.Create(BinMsg, Channel);
DataService := CoDataService.Create(BinMsg, Channel);


both pieces of code are equal only when RemoteService.ServiceName is empty
second one will be executed a bit faster because RemoteService shouldn’t detect correspondent proxy class and create it.

also, you can simplify your code to

sUrl := 'http://' + Host + ':' + IntToStr(Port) + '/bin/';
PrintService := CoPrintService.Create(sUrl);
DataService := CoDataService.Create(sUrl);

in this case, proxy will use TROIndyHTTPChannel and TROBinMessage


Could someone elaborate on this? I am using TRODynamicRequest and I am not sure of how to hook it in this scenario.

assign MethodName and call RefreshParams. after this, you can assign values to parameters.

Do I correctly understood what you need?

Hi EvgenyK

So, I am not figuring out how to hook TRoDynamicRequest in the code you provided. I am currently using this code to hook everything together:

 Url := 'http://' + Host + ':' + IntToStr(Porta) + '/bin/';
 FCanal := TROIndyHTTPChannel.Create(nil);
 Fcanal.TargetUrl := Url;
 Fmsg := TROBinMessage.Create;

 FServico := TRoRemoteService.Create(nil);
 FServico.ServiceName := ServiceName;
 FServico.Channel := FCanal;
 FServico.Message := FMsg;

 FRequest := TRoDynamicRequest.Create(nil);
 FRequest.RemoteService := FServico;
 FRequest.MethodName := methodName;

Is there a simple way to to that?

DynamicRequest requires TRORemoteService so you can’t simplify your code.

w/o DynamicRequest, you could do direct call like

sUrl := 'http://' + Host + ':' + IntToStr(Port) + '/bin/';

Does TRODynamicRequest support out/var parameter?


yes, it does