Solved

How to create a Indy9 TIdTCPClient componnent in run time?

Posted on 2006-07-04
3
1,118 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

679 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