Reference form objects from a module

  • Thread starter Thread starter Andy.I
  • Start date Start date
A

Andy.I

Hi

I have a module where I put all my functions and sub procedures. How do I
from the module best reference objects in other forms?

I have a form with a datagrid, and in the module I have a procedure to fill
this datagrid.
The datagrid is called dg, the form frmEventMain

Would this be correct:

frmEventMain.dg.Datasource = dt when I reference the datagrid in another
form?

/A.
 
Andy:

It's not clear to me if frmEventMain is an instance of a form or the
name of the class wherein the form is defined. Assuming it's an
instance of the form you could...

1) Call your proc passing frmEventMain as a parameter
2) Call your proc passing frmEventMain.dg as a parameter
3) Assuming frmEventMain is visible within your proc, you could access
frmEventMain.dg directly.

My preference would be #2 because it would make your proc more
generally useful.
 
Thanks

I'll give it a try
Lee said:
Andy:

It's not clear to me if frmEventMain is an instance of a form or the
name of the class wherein the form is defined. Assuming it's an
instance of the form you could...

1) Call your proc passing frmEventMain as a parameter
2) Call your proc passing frmEventMain.dg as a parameter
3) Assuming frmEventMain is visible within your proc, you could access
frmEventMain.dg directly.

My preference would be #2 because it would make your proc more
generally useful.
 
Andy.I said:
I have a module where I put all my functions and sub procedures. How do
I from the module best reference objects in other forms?

If a method requires a reference to a Form then pass it one as an
argument to the method.
Better still, if the method primarily affects the Form based on other
data that you supply, move the method into the Form class.
I have a form with a datagrid, and in the module I have a procedure to
fill this datagrid.

I would suggest that's the wrong way round.
I would attach this method to the Form and pass the data, however you
retrieve it, to the method.

HTH,
Phill W.
 
Back
Top