How to create a Indy9 TIdTCPClient componnent in run time?

Hi!
I am writing a TCP/IP App and I am using the Indy 9 components.
The problem is that most of the doc is in delphi.
I am trying to create a connection in run time on the client side.

TIdTCPClient *TCPConn = ????;

In delphi i have found the following code:

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
  Cli: TIdTCPClient;
begin
  try
    Cli := nil;
    try
      { Create & Connect to Server }
      Cli := TIdTCPClient.Create(nil);
      Cli.Host := 'www.borland.com';
      Cli.Port := 80;
    finally
      if Assigned(Cli) then
      begin
        Cli.Disconnect;
        Cli.Free;
      end;
      { Disconnect real client }
      AThread.Connection.Disconnect;
    end;
  except
  end;
end;

mikrodidaktAsked:
Who is Participating?
 
George TokasCommented:
Lets get started with translation:

TIdTCPClient *TCPConn = new TidTCPClient(0);//It will be better instead of "0" to use "this"
TCPConm->Host = .....;
TCPConn->Posrt = .....;
....//Do what you want here and then
delete TCPConn;

George Tokas.
0
 
mikrodidaktAuthor Commented:
Thanks!
But i can't find the description of the constructor the only thing that i could find was the create method.
And if i use this instead of 0 is this then the owner?


0
 
George TokasCommented:
The "this" parameter specifies the control owner the "new" line is located.
If it is anywhere in Form1(default form) then Form1 is the owner.
There are times that you want to create an instance of a component in runtime but not owned by the default main form, in example inside a class by adding the apropreate headers...
That is why I propose to use "this" instead of 0 or NULL....

George Tokas.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.