Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, I'm trying to use a dll to hold forms & code and instantiate them from an exe.

 

I can successfully do it when there is only one form in the dll. The problem I am having is when there are multiple forms in the one dll.

 

I load the dll to form 1. The user clicks a button and the code is supposed to open up form2 and execute some code. The error I am getting is:

 

"An unhandled exception of type 'System.NullReferenceException' occurred in add transactions.dll

 

Additional information: Object reference not set to an instance of an object."

 

When this dll is built as an exe, it loads up on a module that has the "Sub Main" module in it and all forms work properly in an exe.

 

My question is, how do I have forms successfully interacting with each other under a dll environment? Or, Can I get the loading exe to call the "Sub Main" module first in the dll?

 

Your help is appreciated.

 

Thank you

Posted
see attached solution

SharedForms.zip

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted (edited)

@ PlausiblyDamp

I have form 1 (Add_Transaction) and form 2 (Insert_Line)

 

I have tried to declare form 2 as new frmInsertLine.

 

form 1 is the initial form loade up from the dll. In this form, the user selects a button and some code plus this one is executed. When the code in form 1 gets to this code, I get the afore mentioned error.

 

intX = frmInsertLine.Variable_Hold("0", "no", "Add") - 1

 

When I Break the error and hover my mouse over frmInsertLine, it says that frmInsertLine = Nothing. If I understand this correctly, it means that I haven't instantiated an instance of form 2 yet.

 

I am wondering how I get form 1 to know what form 2 is & vice versa. I wan't to instantiate each form once & then pass code between the two forms whilst in the dll evironment. Once the user is finished with all forms, I want the dll to close until needed later.

 

I tried Joe Mamma's code and it I don't think I'll be able to use it. If I understand correctly, Form2 & Form3 inherit Form1's class and only modify the text. Thank you Joe Mamma

 

In what I want, my forms are completely different but they need to be able to talk to each other as if they were in an exe project.

 

Thank you again for looking at this & helping me.

 

I have attached the project that I am trying to run. Please excuse the sloppy programming as I am very new to this & am still learning. - Thanks

Add_Trans.zip

Edited by PlausiblyDamp
  • Administrators
Posted

Only had a quick glance but it looks like you are never instantiating the form - there is code in the sub main but I don't think that routine is ever called.

Is there a reason why the main application is just an empty form and all the other forms are in the DLL? It just seems a bit confusing in that respect.

also when it comes to passing information between various forms you may want to consider overloading the form's sub new to allow you pass a reference to the calling form. Clicky may be worth a read just to get familiar with the ideas involved.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
I tried Joe Mamma's code and it I don't think I'll be able to use it. If I understand correctly' date=' Form2 & Form3 inherit Form1's class and only modify the text. Thank you Joe Mamma[/quote']thats irrelevant.

 

They could be independent. . .

 

Drop the VB6 mindset.

on your other issue:

pass the form to another form via a property or method.

 

Man, VB6 really impeded software development.

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...