Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


How do I programatically create Indy components

Posted on 2009-04-08
Medium Priority
Last Modified: 2012-05-06
Hi experts, I am trying to create a service and creating the indy components (tcpserver, udpserver) from code rather than dropping a component on a form.  I'm looking for some code sample that shows how to do this.

Question by:viziopoint
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
  • 3
  • 2
  • 2
LVL 13

Assisted Solution

ThievingSix earned 100 total points
ID: 24104193

procedure Button1Click(Sender: TObject);
  IRC : TidIRC;
  IRC := TidIRC.Create(...);
  blah blah

Remember to include the correct units associated with the component in your uses for it to work.
LVL 38

Accepted Solution

Geert Gruwez earned 400 total points
ID: 24104567
GExperts has a very nice feature for this http://www.gexperts.org
after installing it into the Delphi IDE, do this:
put a component on your form as you normally do
then right click on the component
(gexperts will have added extra menu options)
Components to Code

This creates a variable, the component creation with the constructor and the properties

I got this, from 3 clicks and a Ctrl-V to paste:

  IdTCPClient1: TIdTCPClient;

  IdTCPClient1 := TIdTCPClient.Create(Self);
  with IdTCPClient1 do
    Name := 'IdTCPClient1';
    MaxLineAction := maException;
    ReadTimeout := 0;
    Port := 0;

LVL 13

Expert Comment

ID: 24104986
Hey, that's really useful!

Thanks Geert_Gruwez =D

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 24113562
The GeExpert tip is indeed a very really useful tip! - Thanks!

I'm getting some odd results though like:

Bindings := <>;
It tried to replace the <> with nil - compiles but does not work (crashes) so I just commented them out and it seems to work.

I also had problems with assigning event handlers since I don't have a form.  I was able to fix this with a little trick that I think is fine:

   TEventHandlers = class // create a dummy class
       procedure UDPServerUDPRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle);
   EvHandlers : TEventHandlers;
IdUDPSever1.OnUDPRead := EvHandlers.UDPServerUDPRead

to the component created with the GeExpert code and it seems to work.

I'll continue to test and report back.

Thanks again for the help.
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24113885
you don't have a form and you want to use an event handler ?

the way you do it with the dummy class is actually the solution!

why you may ask ... well because how the event handler is defined
a event handler is a method, and a method is a procedure of a object

TNotifyEvent = procedure (Sender: TObject) of object;

the *of object* at the end means it must be defined inside a class.

you will have to create a instance of EvHandlers at runtime too...

LVL 13

Expert Comment

ID: 24113977
Actually you should have the indy component in the event handler dummy class.

Author Comment

ID: 24154860
Just wanted to confirm that following the tips above, everything worked fine.  Thanks Again!

Featured Post

Industry Leaders: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

604 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