我如何做表单控件?(50分)

  • 主题发起人 yanghaijun
  • 开始时间
Y

yanghaijun

Unregistered / Unconfirmed
GUEST, unregistred user!
就这么个简单的表单(进入DELPHI时的空白表单),我如何将它变成一个控
件,在需要时只要 Form1.ShowModal 即可。
同时,请问如何在运行时注册此表单,更重要的是如何删除此表单的
注册,我对控件的问题总是有点儿糊涂。
=== 最好有简单的源码 ===

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

implementation

{$R *.DFM}

end.
 
Form不应该做成控件, 控件是能够放到一个容器上的(如Form, panel...)类.
对于你的问题我有点没搞清除, 我猜想你是要动态创建一个Form, 烦你检索一下已答
问题,用“动态创建”做关键字。
 
一般把对话框做成构件,一般的窗体也可以,但作用不大

uses
// 略

type
TFormComponent = Class(TComponent)
public
procedure Execute;
end;

procedure Register; //略

implementation {可能拼错了}

procedure TFormComponent.Execute;
begin
if not assigned(form1) then
form1.ShowModal;
end;

end.
 
我的本意是做要像使用诸如FontDialog等形式的在设计时可放入表单中,只须进行
Execute等方法的控件。
 
按照下面的步骤:
1. 设计好你的对话框表单, 比如TSampleDialogForm
2. 设计你的构件类,比如TSampleDialog,TSampleDialog可以这样实现.

unit ....;

interface

uses
..., ..., ..., SampleDialogf{TSampleDialogForm的单元文件};

type

TSampleDialog = Class(TComponent)
private
FCaption: String;
public
function Execute: Boolean;
published
{比如可以让用户通过Caption属性修改对话框的标题}
property Caption: String Read FCaption write FCaption;
end;

implementation

function TSampleDialog.Execute: Boolean;
begin
if not Assigned(SampleDialogform) then
SampleDialogform := TSampleDialogform.Create(Application);
SampleDialogform.Caption := FCaption;
result := SampleDialogform.ShowModal = mrOK;
end;

end.

详细情况还可以看帮助:"Help"/"Contents"/"Creating Custom Components'/
'Making a dialog box a component'
 
多人接受答案了。
 

Similar threads

回复
0
查看
658
不得闲
回复
0
查看
864
不得闲
D
回复
0
查看
826
DelphiTeacher的专栏
D
D
回复
0
查看
798
DelphiTeacher的专栏
D
顶部