gpt4 book ai didi

delphi - delphi创建组件模板

转载 作者:行者123 更新时间:2023-12-03 18:23:19 25 4
gpt4 key购买 nike

我正在使用Delphi应用程序。我创建了一种如下所示的表单:



我想通过代码使控件脱离组件。但是不能通过component-> create component Template->等等。

我该如何通过delphi代码使组件模板脱离表单控制??
提前感谢。

最佳答案

或者,如果要将一组控件作为一个组件,可以将这样的单元安装到某些软件包中:

unit EditGroup;

interface

uses
SysUtils, Classes, Graphics, Controls, StdCtrls;

type
TEditGroup = class(TCustomControl)
private
FButton: TButton;
FFirstEdit: TEdit;
FFirstLabel: TLabel;
FSecondEdit: TEdit;
FSecondLabel: TLabel;
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Button: TButton read FButton;
property FirstEdit: TEdit read FFirstEdit;
property FirstLabel: TLabel read FFirstLabel;
property SecondEdit: TEdit read FSecondEdit;
property SecondLabel: TLabel read FSecondLabel;
end;

procedure Register;

implementation

{ TEditGroup }

constructor TEditGroup.Create(AOwner: TComponent);
begin
inherited;

Width := 213;
Height := 104;
Color := clWhite;

FFirstLabel := TLabel.Create(Self);
FFirstLabel.SetSubComponent(True);
FFirstLabel.Parent := Self;
FFirstLabel.Top := 11;
FFirstLabel.Left := 8;
FFirstLabel.Name := 'FirstLabel';

FFirstEdit := TEdit.Create(Self);
FFirstEdit.SetSubComponent(True);
FFirstEdit.Parent := Self;
FFirstEdit.Top := 8;
FFirstEdit.Left := 84;
FFirstEdit.Width := 121;
FFirstEdit.Name := 'FirstEdit';

FSecondLabel := TLabel.Create(Self);
FSecondLabel.SetSubComponent(True);
FSecondLabel.Parent := Self;
FSecondLabel.Top := 39;
FSecondLabel.Left := 8;
FSecondLabel.Name := 'SecondLabel';

FSecondEdit := TEdit.Create(Self);
FSecondEdit.SetSubComponent(True);
FSecondEdit.Parent := Self;
FSecondEdit.Top := 36;
FSecondEdit.Left := 84;
FSecondEdit.Width := 121;
FSecondEdit.Name := 'SecondEdit';

FButton := TButton.Create(Self);
FButton.SetSubComponent(True);
FButton.Parent := Self;
FButton.Top := 71;
FButton.Left := 69;
FButton.Width := 75;
FButton.Name := 'Button';
end;

destructor TEditGroup.Destroy;
begin
FButton.Free;
FFirstEdit.Free;
FFirstLabel.Free;
FSecondEdit.Free;
FSecondLabel.Free;
inherited;
end;

procedure TEditGroup.Paint;
begin
Canvas.Rectangle(ClientRect);
end;

procedure Register;
begin
RegisterComponents('Stack Overflow', [TEditGroup]);
end;

end.


这是设计时的样子:

关于delphi - delphi创建组件模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11243208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com