hi Guys/Gals

OK my question, it seems complicated why I want to do it this way but I have my reasons ^_^

I have 3 Forms, FormBlue and FormRed and FormFunctions

Now, the code in FormFunctions e.g.

uses Blue, red

FormBlue.label1.color := clBlue;
FormBlue.edtBox.text := 'Bla';

OK so heres what I want, to change the form "FormBlue" name to a variable so I can use "FormRed" aswell without changing the structure of FormFunctions...


FormInUse : TForm;


formInUse := FormBlue; or formInUse := FormRed;

formInUse.label1.color := clBlue;
formInUse.edtBox.text := 'Bla';

how can this be done?

thnx! ^_^

Recommended Answers

All 6 Replies

You can loop a form's Controls property to see if the one you need is available:

procedure SetValues(AForm: TForm);
var i: Integer;
  if AForm = nil then

  // here you have to loop the form's Controls property and find the one you want to set.
  for i := Low(AForm.Controls) to High(AForm.Controls) do begin
    if AForm.Controls[i].Name = 'label1') then
      (AForm.Controls[i] as TLabel).Color := clBlue;

    if AForm.Controls[i].Name = 'edtBox') then
      (AForm.Controls[i] as TEdit).Text := 'Blah';

I could not try a real example at this time. Am sure this will get you started though.

(Sounds like you should have a look at how to use a TFrame, instead of using this.)

thnx for the reply..

I understand what it is you are doing...though I have more than 5k lines of code running in form Function...and to prevent myself from just duplicating the form just because form red now has to use the same function set...

I Dont know how effective this method might be?


It is caused by a strange way of building your code. Fixing that will always be akward, no matter what solution you choose. If they are so similar, a TFrame should have saved you a lot of trouble in the first place. It's hard to determine the best path from so little code.

^_^ no use crying over spilt milk,

I did not write this code. It's a new company I work for and this program was created about 6 years ago, I'm just trying to solve this dilemma. Adding "formRed" is giving me some trouble and no form has been written to work seperatly from others, the whole modular design was lost on them I suppose ^_^


*edit* the code I gave was just an example to simplify things a bit, the core concept remains the same. FormBlue used FormFunctions, and now I have to add FormRed which does exactly what Blue does and uses FormFunctions aswell. Form functions just changes variables on formBlue.

Great ;) Well, perhaps porting Blue (read copying) and functions to a new frame could still help. But that depends on your code, so it's just a guess... Good luck anyway.

ok this is still kinda unresolved, if anyone else has any other suggestions itll be appreciated!


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.