Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 使用CreateParam'强制子窗体;她是谁?_Delphi - Fatal编程技术网

Delphi 使用CreateParam'强制子窗体;她是谁?

Delphi 使用CreateParam'强制子窗体;她是谁?,delphi,Delphi,在我继承并迁移到XE5的一些遗留D7代码中,我发现了下面的代码 该评论指出,如果它是从非WinControl创建的,则会诱使windows将其视为子窗体。代码库中有一个地方调用Create,AOwner为nil。(打电话时有表格,所以不知道他们为什么这么做…) 关于程序员的目标有什么建议吗 private FParentWinControl: TWinControl; {Don't mess with! Used in CreateParams} procedure TFormX.Cre

在我继承并迁移到XE5的一些遗留D7代码中,我发现了下面的代码

该评论指出,如果它是从非WinControl创建的,则会诱使windows将其视为子窗体。代码库中有一个地方调用Create,AOwner为nil。(打电话时有表格,所以不知道他们为什么这么做…)

关于程序员的目标有什么建议吗

private
  FParentWinControl: TWinControl; {Don't mess with! Used in CreateParams}
  procedure TFormX.CreateParams(var params: TCreateParams); override;
public
  constructor TFormX.Create( AOwner: TComponent); reintroduce;
end;

constructor TFormX.Create( AOwner: TComponent);
begin
  if AOwner IS TWinControl then
    FParentWinControl := TWinControl(AOwner)
  else
    FParentWinControl := NIL;
  inherited Create(AOwner);
end; { Create }


procedure TFormX.CreateParams(var params: TCreateParams);
begin
  inherited CreateParams(params);
  if (NOT fCreateParamsHasBeenRun) then
    begin
      fCreateParamsHasBeenRun := TRUE;
      if Assigned(FParentWinControl) then
        Params.WndParent := FParentWinControl.Handle; {tricks windows into thinking it's a child form}
    end;
end;

此代码早于Delphi 8中添加到
TCustomForm
的属性,并且松散地模仿这些属性。假设
AOwner
是另一种形式,在现代Delphi版本中使用这些属性,例如:

constructor TFormX.Create( AOwner: TComponent);
begin
  inherited Create(AOwner);
  if AOwner Is TCustomForm then
    PopupParent := TCustomForm(AOwner);
end;

此外,使用
fcreateparamsbeenrun
是错误的<每次(重新)创建表单窗口时都会调用code>CreateParams(),因此每次都需要应用
WndParent
。如果需要保留
CreateParams()
逻辑(例如
AOwner
是非
TCustomForm
窗口控件),则需要删除
fcreateparamsbeenrun

此代码早于并松散地模仿Delphi8中添加到
TCustomForm
的属性。假设
AOwner
是另一种形式,在现代Delphi版本中使用这些属性,例如:

constructor TFormX.Create( AOwner: TComponent);
begin
  inherited Create(AOwner);
  if AOwner Is TCustomForm then
    PopupParent := TCustomForm(AOwner);
end;

此外,使用
fcreateparamsbeenrun
是错误的<每次(重新)创建表单窗口时都会调用code>CreateParams(),因此每次都需要应用
WndParent
。如果需要保留
CreateParams()
逻辑(例如如果
AOwner
是非
TCustomForm
窗口控件),则需要删除
fcreateparamsbeenrun
Params.WndParent
hWndParent
CreateWindowEx
,请参阅MSDN文档以获取完整解释。除非“TFormX”在样式中指定了
WS\u CHILD
(情况似乎并非如此),否则该窗口将被创建为所有者(AOOwner)所有,而不是子窗口。我不知道程序员是怎么想的。尽管如此,他很可能不知道自己在做什么。
Params.WndParent
hWndParent
CreateWindowEx
,请参阅MSDN文档以获取完整解释。除非“TFormX”在样式中指定了
WS\u CHILD
(情况似乎并非如此),否则该窗口将被创建为所有者(AOOwner)所有,而不是子窗口。我不知道程序员是怎么想的。不过,很有可能他不知道自己在做什么。雷米真是太棒了!也许有必要解释一下代码的作用(所有者表单的所有者表单“保持在顶部”),以及在原始代码的注释中使用“孩子”一词指的是z顺序中涉及的父母关系,而不是任何“遏制”关系(这正是让我在我自己的特别追逐中失败的原因!).谢谢你们两位。Deltics:是的,保持领先是用户想要做的。雷米,好位置!也许有必要解释一下代码的作用(所有者表单的所有者表单“保持在顶部”),以及在原始代码的注释中使用“孩子”一词指的是z顺序中涉及的父母关系,而不是任何“遏制”关系(这正是让我在我自己的特别追逐中失败的原因!).谢谢你们两位。Deltics:是的,保持领先是用户想要做的。