Jump to content
Henry Olive

Get Form Name

Recommended Posts

Good Day
 

I want to find out the Form Name 1 level behind of Active Form

 

In Form1 -  Form2.Show;

In Form2 -  Form3.ShowModal;

In Form3 I need the name of 1 level behind Form3, ( which is Form2 ) 

 

Thank You

Share this post


Link to post

There are different approaches:

  • Everytime a form takes focus it inserts itself at the top of Screen.CustomForms
  • ShowModal inserts the previously focused form at the top of Screen.SaveFocusedList

Share this post


Link to post

Thank you so much Uwe
If you have time,  could you please a little bit explain the 2 choices

and if possible could you show some code example
 

Share this post


Link to post

@Henry Olive A Delphi programmer will be able to come up with the code give the information above. There is documentation and VCL source. If you don't have a Delphi programmer on your team you have bigger problems. 

Share this post


Link to post

Don't set Form2 and Form3 autocreated but create them yourself.

You can use the "Owner" of the forms to get the name.

 

In Form 1 you do:

uses Unit2;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  Form2: TForm2;
begin
  Form2 := TForm2.Create(Self);
  Form2.Show;
end;

In Form2 you do:

uses Unit3;

procedure TForm2.BitBtn1Click(Sender: TObject);
var
  Form3: TForm3;
begin
  Form3 := TForm3.Create(Self);
  Form3.ShowModal;
end;

In form 3 you can do: (try to find a way to do this recursively..)

procedure TForm3.BitBtn1Click(Sender: TObject);
var FormName: string;
begin
  if Assigned(Owner) and (Owner is TForm) then
  Begin
    FormName := TForm(Owner).Name;
    if Assigned(TForm(Owner).Owner) and (TForm(Owner).Owner is TForm) then
    Begin
      FormName := TForm(Owner).Owner.Name;
    End else
      FormName := 'No Owner';
  End else
    FormName := 'No Owner';

  ShowMessage('The form is: ' + FormName);
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×