delphi创建组件模板 [英] delphi Creating Component template
本文介绍了delphi创建组件模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Delphi应用程序。我创建了如下所示的表单:
I am working with Delphi application.I created one form shown as below:
我想通过代码使用该控件制作组件。但是不能通过 component->创建组件模板->来完成。
I wanted to make component out of this controls through code. But not through component-->create component Template-->so on.
我如何制作组件模板 >通过 delphi代码变形。
提前感谢。
How do i make component template out of form contols through delphi code.?? Thanx in advance.
推荐答案
或者,如果您希望将该组控件作为一个组件安装,则可以安装将这样的单元放入某个程序包:
Or if you want to have that group of controls as one single component you can install unit like this into some package:
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创建组件模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文