用户坚持为应用程序中的每个“重要事件”提供一个弹出框。在备忘录或列表框中添加一行是 Not Acceptable 。
我不能使用标准模式框,因为 PC 经常无人看管,我的应用程序将等待用户单击“确定”,然后再继续。
我可以动态地创建一个带有备忘录组件和一个确定按钮的表单并传递一些文本以显示在备忘录中吗?
我试过了,当点击确定时我遇到了访问冲突。
问题:
谷歌并没有那么有用,因为表单应该自我毁灭,而示例却让其创建者破坏它。
主要形式:
theDialogForm := TDialogFormForm.Create(Nil);
theDialogForm.ShowTheForm('Database error '+#13+#10+''+#13+#10+
E.ClassName+#13+#10+
E.Message);
和对话框形式...
unit fDialogForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TDialogFormForm = class(TForm)
Memo1: TMemo;
OkButton: TButton;
procedure OkButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure ShowTheForm(const theMessage : String);
end;
implementation
{$R *.dfm}
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
procedure TDialogFormForm.FormCreate(Sender: TObject);
begin
Visible := False;
end;
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
procedure TDialogFormForm.OkButtonClick(Sender: TObject);
begin
// Close();
Free();
end;
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
procedure TDialogFormForm.ShowTheForm(const theMessage : String);
begin
Memo1.Text := theMessage;
Show();
end;
end.
调用栈
main thread ($630):
005164e3 +013 StoreRoom.exe Vcl.Controls TControl.WMLButtonUp
00515b30 +2d4 StoreRoom.exe Vcl.Controls TControl.WndProc
0051a47b +5b3 StoreRoom.exe Vcl.Controls TWinControl.WndProc
00537bf0 +06c StoreRoom.exe Vcl.StdCtrls TButtonControl.WndProc
00519ad0 +02c StoreRoom.exe Vcl.Controls TWinControl.MainWndProc
0048dea4 +014 StoreRoom.exe System.Classes StdWndProc
76677885 +00a USER32.dll DispatchMessageW
005b7c63 +0f3 StoreRoom.exe Vcl.Forms TApplication.ProcessMessage
005b7ca6 +00a StoreRoom.exe Vcl.Forms TApplication.HandleMessage
005b7fd9 +0c9 StoreRoom.exe Vcl.Forms TApplication.Run
00823616 +17a StoreRoom.exe StoreRoom 56 +24 initialization
75c43398 +010 kernel32.dll BaseThreadInitThunk
最佳答案
要关闭表单,您可以
Close
关闭它并将操作设置为 caFree
在 OnClose 事件中 Release
, 这是 Free 的一种特殊风格,尤其是对于表单。 调用
Free
的问题, 是立即释放表单,而您仍在处理关闭按钮上的单击事件。在该过程中,表单和按钮被释放,导致访问冲突。 Release
在内部向表单发送一条消息,使其在处理点击后关闭。
关于delphi - 如何创建无模式对话框并在用户单击确定时将其关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12475252/