Solved

Referencing objects on an ActiveForm from another unit

Posted on 2001-08-27
6
384 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:djmcrae
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:djmcrae
ID: 6428760
The ActiveXForm is being compiled as an OCX! (forgot to mention)
0
 

Expert Comment

by:alshaikh
ID: 6430787
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,
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 200 total points
ID: 6431720
I don't think it's possible. Besides, I think it's bad programming to link units that way.

Pass the Query object (or the specific property) to the function in the 2nd unit, so that function can change the property that belongs to the query object on the main form.

example:

unit Unit2;

...

procedure ChangeQuery(sql: TStrings);
begin
  sql.Text := 'select * from table1';
end;


Call this function from the main unit like this:

uses Unit2;

ChangeQuery(Query1.SQL);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:djmcrae
ID: 6432828
 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.
0
 

Author Comment

by:djmcrae
ID: 6432971
 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.
0
 
LVL 17

Expert Comment

by:geobul
ID: 9288587
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question