【问题标题】:Delphi - How to close a form from WITHIN a TFrame on that form?Delphi - 如何从该表单上的 TFrame 中关闭表单?
【发布时间】:2013-09-28 13:43:20
【问题描述】:

在 Delphi 2010 中,我正在创建一个表单,然后创建一个 TFrame,将 TFrame.Parent 分配给该表单,然后以模式方式显示该表单。工作正常...框架有一个 DBNavigator、一个字段 DBFields 等。当用户点击发布/保存时,我想自动关闭表单。我尝试了一些方法,例如 Close、Action = caFree、(DBNav.parent.parent) as TForm.Free 等,但似乎没有任何效果。我如何 - 从 TFrame 中关闭表单?

创建这个东西的代码是......

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

谢谢,

GS

【问题讨论】:

  • 对 TForm 的子类使用 Release 而不是 Free
  • 这里没有必要,@Marcus。 Release 用于从表单或其控件之一的消息处理程序中销毁表单时。从这里显示的代码来看,表单不可能在调用 Free 时处理任何消息,所以一切都很好。

标签: forms delphi tframe


【解决方案1】:

从框架类中的方法,您可以通过调用GetParentForm 来访问宿主窗体。因此,以下内容将满足您的需求:

GetParentForm(Self).Close;

【讨论】:

  • 做到了。谢谢。
  • +1 不知道这个功能。我自己为不同的项目实施了几次。谢谢!
  • 这符合 OP 的要求,但如果我正在对 OP 的代码进行代码审查,我会说“这太糟糕了”。使框架具有OnRequestClose 属性/事件(实际上是一个回调),并让所有者表单决定是否关闭,以及在关闭之前要执行什么逻辑,甚至是否挂钩回调。
猜你喜欢
  • 2010-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-26
相关资源
最近更新 更多