Solved

How to create a Indy9 TIdTCPClient componnent in run time?

Posted on 2006-07-04
3
1,128 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

724 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