每次我使用 raise Exception.create('...');
时,它都会显示与 Delphi 不同的以下框:
[my message]
Press OK to ignore and risk data corruption.
Press Cancel to kill the program.
我只想更改此默认消息并仅保留我的部分。
有人知道我该怎么做吗?
最佳答案
为了配置我自己的异常消息,我执行了以下操作:
在应用程序主窗体的私有(private)声明中:
procedure onExcept(sender: TObject; e: Exception);
在主窗体的OnCreate事件中:
procedure TfrmMain.formCreate(sender: TObject);
begin
application.onException := @onExcept;
end;
procedure TfrmMain.onExcept(sender: TObject; e: Exception);
begin
//...
end;
请务必注意,如果您使用 Lazarus,则需要 @ 运算符。如果我没有放置它,编译器会将 onExcept
视为函数调用。 Delphi 在内部添加了它,因此您不必担心它。
如果您想更改此行为,请使用 {$mode Delphi}
而不是 {$mode ObjFPC}
指令。
关于exception - 更改 Lazarus 中的异常消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16908111/