Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - How to close a form from WITHIN a TFrame on that form?

In Delphi 2010, I am creating a form, and then creating a TFrame, assigning TFrame.Parent to the form, and then showing the form MODALLY. Works fine... The frame has a DBNavigator, a field DBFields,etc. When the user clicks on Post/Save, I want to automatically close the Form. I have tried a few things, such as Close, Action = caFree, (DBNav.parent.parent) as TForm.Free, etc and nothing seems to work. How do I - from within a TFrame, close the Form?

Code to create this thing is...

 // Create the Window
    ThisWin := TEmptyFrameWin.Create(nil);

  // Create the Frame for the Window
  ThisFrame := TFrameUsage.Create(Application);

  ThisFrame.Parent := ThisWin;

  // Load the data
  ThisFrame.tUsage.Open;
  ThisFrame.tUsage.FindKey([StrToInt(ID)]);
  ThisFrame.LoadDateFields;

  ThisWin.Caption := 'Change Appointment Information';
  // Only show the POST button    
  ThisFrame.UsageNav.VisibleButtons := [sbPost];

  try
    ThisWin.ShowModal;
  finally
    ThisWin.Free;
  end;

Thanks,

GS

like image 569
user1009073 Avatar asked Feb 15 '23 04:02

user1009073


1 Answers

From a method within the frame class, you can reach the host form by calling GetParentForm. So, the following would meet your needs:

GetParentForm(Self).Close;
like image 95
David Heffernan Avatar answered Feb 17 '23 18:02

David Heffernan