Writing to form in DLL

Posted on 2004-11-10
Last Modified: 2010-04-05

I am not sure what I am doing wrong.

I have made a DLL.

Inside the DLL I have include a form and unit1. On the form is a Memo control.

My guess is I have some kind of scoping issue. I can create the form, show the form, but when I go to write in the Memo control the program crashes.

I have to fully qualify the Memo for intellisense to work. Form1.Memo1.Lines.add(s);

I am guessing that it is because once I leave the procedure that creates the form that the form is no longer recognized?

Can someone show me the proper way to create a form in a DLL and be able to write to a memo from procedures.

I have something along the lines of: (I just sketched this out.. probably not accurate on class names)

Procedure WriteMemo(s:string);

Procedure DoTheWork();
  Form1 : TForm;
  Form1 := TForm.Create(nil);

I am calling DoTheWork from the Library unit.

Any help is appreciated.

Question by:KentDRuddick
    LVL 14

    Accepted Solution

    if Form1 is a var declared in DoTheWork, how can WriteMemo access Form1?

    perhaps you can modify WriteMemo to take, as parameter, a TMemo and a String? as in

    procedure WriteMemo(Memo: TMemo; const S: string);

    and your code will be

    Form1 := TForm1.Create(nil);
    WriteMemo(Form1.Memo, 'SomeText');
    LVL 14

    Expert Comment

    or, instead of local, you can make your Form1 to be global, so that both procedures are accessing the same Form1 variable. I think you might have 2 declarations of Form1 in your unit, one global and one local, hence the crash.
    LVL 4

    Assisted Solution

    your problem is indeed that you declared Form1 as a local var in Procedure DoTheWork();

    AND if your create your form by code only ( Form1 := TForm.Create(nil))
    you also need to create the Memo on the form.

    best way would probably be to add a new form to the project and design it there and then call that form from main dll project.

    Author Comment


    I split the points because both answers led me to my solution.

    It was definitely a lack of understanding of the language and some creative programming on my part.

    Thanks for the help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    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…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now