Link to home
Start Free TrialLog in
Avatar of Mahsa60
Mahsa60Flag for Iran, Islamic Republic of

asked on

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  ?
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mahsa60

ASKER

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;
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