Thanks to my son (in Cape Town: South Africa who was programming in machine code at the age of 12 on my Sharp 3201) I (now in Melbourne Australia) now have the total solution to this problem. Which I think is worth adding here and is as as I got it from him
The first thing to do is backup all your source, because you are going to be messing around a lot with the innards of your program.
Next, Open your project in Delpi and open the Delphi Project menu and choose Options. A form will come up, make sure you are looking at the Forms tab.
There are 2 columns. I suspect all your forms are sitting in the left column. Herein lies the problem. Delphi is "auto-creating" all those forms for you. Move them all over to the right hand column.
THEN, select the form which is the first form the user must see when he runs your program in the RIGHT hand column and MOVE IT BACK to the LEFT hand column.
Then click OK.
What you have done now is tell Delphi to desist from AutoCreating the forms for you. Because you are going to do it yourself dynamically during execution of your program.
Next : Go to all the places in your program where you call the .ShowModal or .Show methods and replace them.
This sort of thing : frmDbtrs.ShowModal
must change to
Code:
frmDbtrs := TFrmDbtrs.Create(nil);
frmDbtrs.ShowModal;
Remembering that QuickReport forms are treated the same way - as follows (Note the "T")
Code:
QuickReportCB := TQuickReportCB.Create(nil);
QuickReportCB.Print;
When you've changed all of those, you need to go to each of the forms which you create this way and go and add this in the OnClose event of
those forms :
This is where the real fun stuff starts. The reason you are going to pick them up at this stage is that previously ALL the forms were being created in memory by Delphi
before the program even started running, so it was possible for you to reference an object on a different form quite easily, simply by making sure the "other form"'s name was in the Uses clause.
The problem now is, you can no longer rely on that "other form" even existing yet in memory, and the moment your program tries to access something which doesn't yet exist in memory, you will hit an exception or access violation error.
This is not actually a bad thing. What you would have done up until this point (by changing everything the way I showed you earlier) is "compartmentalise" and isolate everything (each form) nicely into it's own box - which is what a good object oriented program is all about. Each
object (or unit/form) should ideally not have any dependencies on OTHER forms or units. This has NOTHING to do with how your program works - it's simply more technically correct OBJECT ORIENTED thing programmatically -whether it's Delphi, C++ or Java - the same applies.
However, sometimes, you simply HAVE to do this to share info or whatever between forms. This is why Borland came up with the idea of the DATA MODULE (don't know if you use them yet, but now you must I think, if you aren't already).
The idea is to move all your "common" things (things / data/ objects / queries / tables / whatever) which you want to SHARE amongst different units / forms into a DATA MODULE.
THAT data module must then sit in the left hand column of the Project/Options/Forms screen AT THE TOP and BEFORE your startup form.
To get this right is inevitably going to involve a bit of a code "walk through" and you might have to rethink some of your logic - it will help to draw diagrams on paper of how the different units/forms need to interact with each other before starting, so you can more quickly identify just WHAT needs to move into the data module.