Link to home
Start Free TrialLog in
Avatar of djmcrae
djmcrae

asked on

Referencing objects on an ActiveForm from another unit

Easy to do with a normal TForm and unit - ie in the second unit have a "uses uMain" where uMain defines for example "var MyMainForm:TMyMainForm" and within the second unit we can have MyMainForm.memo1.lines.text:='xx'

I'm trying to do this with an ActiveX Form:
I have a TMyAForm=class(TActiveForm, IMyAForm) and a datamodule unit - everythin has been working a treat so far, opening database connection etc - but now I require one of the query components in the datamodule to alter a property of an object on the main form.

Any help would be greatly appreciated.
Avatar of djmcrae
djmcrae

ASKER

The ActiveXForm is being compiled as an OCX! (forgot to mention)
From my own experiments, I don't think it is possible to use more than one form in an ActiveFrom project. In our own projects, we try to put all components and functionality we need in just one ActiveForm and use the Visible property to show/hide these components at run time.

I noticed however, that it is possible to have more than one form, provided that the second form is created at run time dynamically. We have not explored this in details yet.

Regards,
ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of djmcrae

ASKER

 It may not be possible - I will try for just a bit longer though (~1 week). I have a huge application - the main form is 7,500 lines of code (it also has 8 other units, although these are much smaller). I want to shift the dozen odd database components to a datamodule (this worked OK) and move a fair bit of database code from the main to this. This has been proceeding along well, until one of the TADOQuery's onOpen code was moved over.
  This onOpen refreshed the strings in a TComboBox on the main form - grief - cannot get to the objects on the main form. I could just have the onOpen populate a TStringList which the opening code in main could the reference after issueing the opening command - yuk!!
  Another work around may be to make the whole main ActiveForm a normal TForm, then have the activeForm create an instance of this (outlined at http://pw2.netcom.com/~cherrman/cvtforms.htm) - better choice than my first, and much better than...
  Have a global var in the main pointing to the object on the form, ie var objPersonnel:TDBComboBox; then in the ActiveForm's onCreate, assign objPersonnel:=cbPersonnel ir the combobox on the form, the dataModule then uses objPersonnel. I just tried this and, dammit, it works. I do not like it one bit!! Global variables for reference by other units, it cannot be good!!
  Hitting the books at the moment on the COM world - we may be able to use an interface - my knowledge here could do with some honing!!
  BTW, alshaikh, creating a second form is not a problem - this application has about 8 including an about form, & not including the many messageboxes - it's handled no differently from normal.
Avatar of djmcrae

ASKER

 It may not be possible - I will try for just a bit longer though (~1 week). I have a huge application - the main form is 7,500 lines of code (it also has 8 other units, although these are much smaller). I want to shift the dozen odd database components to a datamodule (this worked OK) and move a fair bit of database code from the main to this. This has been proceeding along well, until one of the TADOQuery's onOpen code was moved over.
  This onOpen refreshed the strings in a TComboBox on the main form - grief - cannot get to the objects on the main form. I could just have the onOpen populate a TStringList which the opening code in main could the reference after issueing the opening command - yuk!!
  Another work around may be to make the whole main ActiveForm a normal TForm, then have the activeForm create an instance of this (outlined at http://pw2.netcom.com/~cherrman/cvtforms.htm) - better choice than my first, and much better than...
  Have a global var in the main pointing to the object on the form, ie var objPersonnel:TDBComboBox; then in the ActiveForm's onCreate, assign objPersonnel:=cbPersonnel ir the combobox on the form, the dataModule then uses objPersonnel. I just tried this and, dammit, it works. I do not like it one bit!! Global variables for reference by other units, it cannot be good!!
  Hitting the books at the moment on the COM world - we may be able to use an interface - my knowledge here could do with some honing!!
  BTW, alshaikh, creating a second form is not a problem - this application has about 8 including an about form, & not including the many messageboxes - it's handled no differently from normal.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept Epsylon's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer