Find Form Name

Hi
I'm using Delphi 7 .
I wanna build a template form that other forms inherit from it .
i wanna do some work with Form Name in template form (i need name of form) that inherited forms do it for itself .
for example i wanna Disabled all component in form and i need from name to do that :
    for i := 0 to AOtherForm.ComponentCount-1 do
         begin
            if (AOtherForm.Components[i] is TDBEdit) then
              TEdit(AOtherForm.Components[i]).Enabled := True;
            if (AOtherForm.Components[i] is TDBComboBox) then
              TComboBox(AOtherForm.Components[i]).Enabled := True;
         end;
//AOtherForm is a variable that contains form name.

how can i get the name of a form to fill AOtherForm  ?
Mahsa60Asked:
Who is Participating?
 
ziolkoCommented:
if AOtherForm will be form's name any call of: AOtherForm.anything_here  will be wrong

use Self instead AOtherForm.

ziolko.
0
 
Mahsa60Author Commented:
This is my procedure and it works when i call it from another forms(i send status and name of the form that i'm coding in it), but i don't want to call it from the other forms, i wanna put it into the my template form and then inherited forms can use it without writing any codes .
tell me if i am wrong

tanxfull
Mahsa

i'm working like this but i wanna change it and put all codes into the template form .
//this procedure is in my MAIN form
procedure Enable_Items(AOtherForm : TForm;status :boolean);
var i:integer;
begin
  if status then
    begin
        for i := 0 to AOtherForm.ComponentCount-1 do
          begin
            if (AOtherForm.Components[i] is TDBEdit) then
              TEdit(AOtherForm.Components[i]).Enabled := True;
            if (AOtherForm.Components[i] is TDBComboBox) then
              TComboBox(AOtherForm.Components[i]).Enabled := True;
          end;
    end;
end;

//this code is in Registry form
procedure TF_Registry.BitBtn1Click(Sender: TObject);
begin
  Enable_Items(F_Registry,True);
end;
0
 
JaccoCommented:
If you make it a method of the Form it looks like this:

interface

type
  TMyForm = class(TForm)
  ...
    procedure Enable_Items(status :boolean);
  end;

implementation

procedure TMyForm.Enable_Items(status :boolean);
var i:integer;
begin
  if status then
    begin
        for i := 0 to ComponentCount-1 do
          begin
            if (Components[i] is TDBEdit) then
              TEdit(Components[i]).Enabled := True;
            if (Components[i] is TDBComboBox) then
              TComboBox(Components[i]).Enabled := True;
          end;
    end;
end;

If you have this working you can use FormInheritance to inherit other forms from this form.

To do this in Delphi choose "File / New / Other ..." select the tab with the projects name on it an select your base form.

The new form will be a descendant of you created enhanced form. You can create as much descendants as you like. They will all have the new method Enable_Items

Regards Jacco
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.