Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Referencing objects on an ActiveForm from another unit

Posted on 2001-08-27
6
Medium Priority
?
391 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 800 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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