Forum > Beginners
[Solved] Calling objects from other units
heebiejeebies:
Hi all,
I've added a new unit to my app that functions as a help screen. As my main unit is one huge tabsheet with about 70 tabs, the help screen needs to read which tab is active, and then bring up its own corresponding help tab.
Just as a made-up example, supposing the user is on the 'vegetables' tab in the main screen, when the user opens the help screen from the menubar, it needs to be on the vegetables help screen.
Definitely not the most efficient way of doing it, but this is what I've come up with for the moment.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.ShowQuestionsPromptClick(Sender: TObject);begin if HelperScreen.visible = false then begin if MainScreen.ActivePage = Vegetables then HelperScreen.HelperScreenPages.ActivePage := VegetablesHelp;// and so on for all the other tabs on the main screen. HelperScreen.visible :=true; end else if HelperScreen.visible = true then HelperScreen.visible :=false;end;
The HelperScreen, unit 2, shows and hides with no problems. I have also been able to successfully change the properties of a label object on the HelperScreen, from the main screen, unit 1 - which is proof of concept. But when I try and change the ActivePage of the tabsheet on the HelperScreen, it complains that there is no identifier VegetablesHelp. Which there is. %)
Any thoughts? Thanks
Paolo:
It seems that such variable is ot seen, did you have declared it in the interface or implementation section ?
heebiejeebies:
--- Quote from: jamie on June 07, 2021, 01:41:07 pm ---Put a method in unit 2 that accepts your ttabsheet control as a parameter. Since tab sheet is a common control you should be able to gain access to the control that way..
Unit 2
Procedure ShowHelp(theTabCOntrol:TTabControl,.....);
You will need also the use the Unit in the users list for that control type, too..
etc..
I think you get the idea..
--- End quote ---
Thanks Jamie! I get the basic idea of what you're saying but I'm going to have to brush up on creating procedures over the weekend when I have time. Unfortunately I am not a natural programmer by temperament so I usually implement everything in the simplest way possible, which is perhaps not the 'correct' way. In other words I normally avoid creating procedures and just code everything manually in the relevant event. :-[ The only part I didn't get at all was ' You will need also the use the Unit in the users list for that control type, too..'
I have listed Unit 2 in the 'uses' section of unit 1, but not sure what you mean by the 'users list for that control type' ... ?
heebiejeebies:
--- Quote from: Paolo on June 07, 2021, 01:47:34 pm ---It seems that such variable is ot seen, did you have declared it in the interface or implementation section ?
--- End quote ---
Thanks for your reply, not quite sure what you mean though ... %)
Paolo:
It is just a possibility: move the declared VegetableHelps from implementation section of unit2 to the interface section of unit2.
Navigation
[0] Message Index
[#] Next page