0
votes

Base from the anwser How to eliminate variables... i get and accepted it works great when i have all this components and make the actions like a button1.click from the main form...

But i use to make the actions from units... so

When i click a button i great a procedure DoMaths(Sender: TObject);

procedure Tform1.DoMaths(Sender: TObject);
  begin
    if TButton1(Sender).hint := 'Make the standard Package' then
      do_Maths_standard_package;
  end;

the do_Maths_standard_package is in unit ComplexMaths.

is the procedure do_Maths_standard_package form unit ComplexMaths it calls some components form Form1... like Form1.label1 etc...

So when i call the RegisterClass(TLabel) and erase the Tlabel from the type it gives an error that it cant find the Label1...

Please can someone help me so not to do the hole program from the start...

Thank you..

2
This is one of the reasons I said not to do what you wanted in your previous question (read my answer and the comments I posted to other answers).Ken White
Ken i read your anwser but it not suit to my program bcs must do to many changes instead the anwser of mcottle that i accepted is goob but has the above problem that i ask the programmers to help me if there is an anwser... Thank youazrael11
What I was saying was that if you delete the names to remove them (like you did in your previous question), then you can't use them by name (you removed it). That's one reason I said you should not remove them in the first place. :-) If you do it wrong from the start, and then it doesn't work later... It doesn't matter to me that you didn't accept my answer to the other question; what matters is that you were going the wrong way to start with, and I suggested you not do so.Ken White
I see now what you mean Sorry i dont understand before bcs my english is not to good ... So there is no easy way to do this ... hmmm that make me concern the hole structure of my programm... thanks a lot Ken..azrael11
This is what happens when you fight the system. Don't fight the system.David Heffernan

2 Answers

0
votes

You might be able to reference your components like this:

TLabel(Form1.FindComponent('Label1')).Caption := '...';
TCheckBox(Form1.FindComponent('CheckBox12')).Checked := False;

But it's really a pain...

0
votes

I think you have two options.

1) you can assign each component a unique numeric ID. And save it into .Tag property. Just like u use to generate and bind IDs in .HelpContext properties.

Then to get the control by number you would enumerate Form.Controls and get the one with proper Tag value.

The problem would be to have two separate ID lists, in PAS files and DFM files, in sync. Mistyping would be hard to notice. Especially since you have no constants in DFM but only "magic numbers".

2) Set .Name property and use iMan Biglari's recipe - FindComponent by name. The question is if you can have .Name but not variable. Since no one answers - just try and see. To my experience - with Delphi 5, hopefully D7 is mostly the same - you can just delete the variable.

  • If you made wrong declaration of variable, then Delphi editor would notice and ask to correct it.
  • If you have variable without DFM object, Delphi would notice it and ask to remove it.
  • But if there is DFM object without corresponding variable, then Delphi editor is oblivious. Maybe it thinks that the object is inherited or whatever. But if you did not declare it at all it does not mind.

However, since you deleted Names, it looks like it is not possible to you for some reason.


In both cases you would have to cache value if some procedure makes a lot of accesses to some control. And maybe even across the procedures. In effect yu would manually restore those variables at least for most used controls.