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

x
?
Solved

Using Visual Components in DLL

Posted on 2004-11-02
6
Medium Priority
?
256 Views
Last Modified: 2010-04-05

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
0
Comment
Question by:KentDRuddick
[X]
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
  • 2
  • 2
  • 2
6 Comments
 
LVL 17

Assisted Solution

by:geobul
geobul earned 189 total points
ID: 12473082
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
 
LVL 17

Expert Comment

by:geobul
ID: 12473117
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
 

Author Comment

by:KentDRuddick
ID: 12475344
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
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!

 
LVL 5

Accepted Solution

by:
paulb1989 earned 186 total points
ID: 12478475
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
 

Author Comment

by:KentDRuddick
ID: 12479167

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
 
LVL 5

Expert Comment

by:paulb1989
ID: 12487127
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

636 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