Solved

Using Visual Components in DLL

Posted on 2004-11-02
245 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
Question by:KentDRuddick
    6 Comments
     
    LVL 17

    Assisted Solution

    by:geobul
    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
    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
    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
     
    LVL 5

    Accepted Solution

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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    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…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

    875 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

    11 Experts available now in Live!

    Get 1:1 Help Now