Board index » delphi » What is first? DM or Unit creation?

What is first? DM or Unit creation?

If I have designed a data module and a form and unit and they both
reference each other what would be the order of creation?  Should I
create the dm first then maybe open the files after the form is created?

Thank you,
--
Craig
Programming by C

 

Re:What is first? DM or Unit creation?


Craig,

I usually open the DM first.  Occasionally I run into problems when I have
an event in the DM referencing a control or method in the Form.  An example
would be if you manually set something in the form like a TLabel.Caption
from an OnScroll event in the DM.  In this case I just add a line "if Form1
= nil then Exit;" to the beginning of the event so it does not trigger if
the form has not been created.

Same thing, but in reverse if you create the form first.

HTH,

Rick

Quote
Craig Clemans wrote in message ...
>If I have designed a data module and a form and unit and they both
>reference each other what would be the order of creation?  Should I
>create the dm first then maybe open the files after the form is created?

>Thank you,
>--
>Craig
>Programming by C

Re:What is first? DM or Unit creation?


Well, I'm trying to get someone else's original code to work. :)  I
cannot figure how they got it to work with reference's to the other form
when it has not been created.  Thanks for the info.

Quote

> I usually open the DM first.  Occasionally I run into problems when I have
> an event in the DM referencing a control or method in the Form.  An example
> would be if you manually set something in the form like a TLabel.Caption
> from an OnScroll event in the DM.  In this case I just add a line "if Form1
> = nil then Exit;" to the beginning of the event so it does not trigger if
> the form has not been created.

--
Craig
Programming by C

Re:What is first? DM or Unit creation?


Units are not objects and are not created.  They are just there.  If you put
code in the Initialization section of a unit it runs before anythig else.
To see or change the order of form and data module creation see the Forms
tab of the Project | Options dialog box or edit the project (.DPR) file.

--
Bill

(TeamB cannot answer questions received via email.)
(To contact me for any other reason remove nospam from my address)

Other Threads