Using Visual Components in DLL


Not sure how hard this question is....

I just got Delphi, and there seems to be many components to download and use. They add icons on VCL bar across the top. I am interested in using those components in programs that do not have a form. i.e. DLL. How do you use these components?

I am guessing you create an instance of the class/object by calling the create method. I can't seem to get it correct.

Thanks in advance.
Kent
KentDRuddickAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
paulb1989Connect With a Mentor Commented:
If you don't need your DLL to be very small (IE have no VCL) then you could create a new form using the file menu, place all of your components on there and just create the form as below to have access to the components. You don't have to show the form, it can just be created so that the components have a parent.

var
  Form1: TForm1;
begin
  Form1:=TForm1.Create(Application);

  Form1.MyComponent.Method;
end;

And when you're finished using the components don't forget to use Form1.Free;
0
 
geobulConnect With a Mentor Commented:
Hi,

Usually these components need an owner in its Create method. That owner is the form when you put them there on design-time. In order to create and use such components in run-time without a form just set its owner to nil:

var
  c: TSomeComponent;
begin
  c := TSomeComponent.Create(nil);
  try
    c.Parent := nil; // might be also important
    c.SomeMethod; // do something with it here
    ...
  finally
    c.Free;
  end;
end;

Regards, Geo
0
 
geobulCommented:
Forgot to say that you had to add the unit name (where that component is defined) in the 'uses' clause of the current unit.
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
KentDRuddickAuthor Commented:
That is pretty much how I am trying to access the component. The program compiles but crashes. The only thing I am currently trying to do with the component is create it. I am not calling any of it's methods.

Kent
0
 
KentDRuddickAuthor Commented:

I had thought about doing something like that.. kind of like always having a form in a VB application.

Is there no way to create or instanciate this component as if it was on a form? I will close this question tomorrow if no one has any other suggestions. I don't feel geobul is wrong... just not getting me past my sticking point.

Thanks

Kent
0
 
paulb1989Commented:
The only way the component will be as if it were on the form is if it is on a form.

Some components will work when created with nil as the owner, but a lot won't, so I think the form is the best way to go.
0
All Courses

From novice to tech pro — start learning today.