Solved

How to create a Indy9 TIdTCPClient componnent in run time?

Posted on 2006-07-04
3
1,114 Views
Last Modified: 2013-11-17
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;

0
Comment
Question by:mikrodidakt
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
George Tokas earned 250 total points
ID: 17037892
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
 

Author Comment

by:mikrodidakt
ID: 17040558
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
 
LVL 16

Expert Comment

by:George Tokas
ID: 17041588
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

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question