Writing to form in DLL


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.

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.

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');

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
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.
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.
KentDRuddickAuthor Commented:

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

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.