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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geobulCommented:
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
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

paulb1989Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.