?
Solved

Find Form Name

Posted on 2006-05-24
3
Medium Priority
?
989 Views
Last Modified: 2010-04-05
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  ?
0
Comment
Question by:Mahsa60
3 Comments
 
LVL 21

Accepted Solution

by:
ziolko earned 280 total points
ID: 16758556
if AOtherForm will be form's name any call of: AOtherForm.anything_here  will be wrong

use Self instead AOtherForm.

ziolko.
0
 

Author Comment

by:Mahsa60
ID: 16758884
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
 
LVL 10

Expert Comment

by:Jacco
ID: 16759248
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question