没有什么可以替代测试。如何在代码中创建表单,设置您感兴趣的属性并在调用 resize 事件时进行记录。
如果您原谅代码的丑陋,这里有一个粗略的概念证明,它测试了 BorderStyle 和 Position 的所有组合,而无需为每个组合显式编码。您可以添加更多属性并尽可能多地使用它。像 CodeSite 这样的工具也会使日志记录更清晰、更容易。
创建一个包含 2 个表单的应用程序。确保第二个不是自动创建的。
在第二个表单中,添加一个属性并向表单的 Resize 事件添加一些日志记录代码:
private
FOnResizeFired: TNotifyEvent;
public
property OnResizeFired: TNotifyEvent read FOnResizeFired write FOnResizeFired;
end;
...
procedure TForm2.FormResize(Sender: TObject);
begin
if Assigned(FOnResizeFired) then
FOnResizeFired(self);
end;
在主窗体中,将 TypInfo 添加到 uses 子句并在窗体上放置一个按钮和一个备忘录。
添加一个简单的过程:
procedure TForm1.ResizeDetected(Sender: TObject);
begin
Memo1.Lines.Add(' *** Resize detected');
end;
现在将以下内容添加到 ButtonClick 事件中:
procedure TForm1.Button1Click(Sender: TObject);
var
lBorderStyle: TFormBorderStyle;
lBorderStyleName: string;
lPosition: TPosition;
lPositionName: string;
lForm: TForm2;
begin
Memo1.Clear;
for lBorderStyle in [low(TFormBorderStyle) .. high(TFormBorderStyle)] do
begin
for lPosition in [low(TPosition) .. high(TPosition)] do
begin
lBorderStyleName := GetEnumName(TypeInfo(TFormBorderStyle), Integer(lBorderStyle));
lPositionName := GetEnumName(TypeInfo(TPosition), Integer(lPosition));
Memo1.Lines.Add(Format('Border: %s Position: %s', [lBorderStyleName, lPositionName]));
Memo1.Lines.Add(' Creating form');
lForm := TForm2.Create(self);
try
Memo1.Lines.Add(' Form Created');
lForm.OnResizeFired := ResizeDetected;
Memo1.Lines.Add(' Setting border style');
lForm.BorderStyle := lBorderStyle;
Memo1.Lines.Add(' Setting Position');
lForm.Position := lPosition;
Memo1.Lines.Add(' Showing form');
lForm.Show;
Memo1.Lines.Add(' Form Shown');
lForm.Close;
Memo1.Lines.Add(' Form Closed');
finally
FreeAndNil(lForm);
Memo1.Lines.Add(' Form Freed');
end;
end;
end;
end;
您会注意到在显示表单之前设置某些属性时会触发 resize,并且我看到在某些组合中,当显示表单时 resize 似乎会触发两次。有趣的。