Solved

How to create a Indy9 TIdTCPClient componnent in run time?

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now