unit MYDBEdit;interfaceuses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Mask, DBCtrls,
FSQL,Forms,db;
type
TMYDBEdit = class(TDBEdit)
private
function GetMyDS_1:TDataSource;
procedure SetMyDS_1(value:TDataSource);
{ Private declarations }
protected
{ Protected declarations }
public
procedure DblClick; override;
{ Public declarations }
published
property MyDS_1:TDataSource read GetMyDS_1 write SetMyDS_1;
constructor Create(AOwner: TComponent); override;
{ Published declarations }
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('lcy', [TMYDBEdit]);
end;
constructor TMYDBEdit.Create(AOwner: TComponent);
begin
inherited;
end;
procedure TMYDBEdit.DblClick;
begin
IF Application.FindComponent('FSQL1')=nil THEN
BEGIN
Application.CreateForm(TMYForm1, FSQL1);
END;
FSQL1.DBGridEh1.DataSource:=MyDS_1;
FSQL1.Show;
end;function TMYDBEdit.GetMyDS_1:TDataSource;
begin
result:=MyDS_1;
end;procedure TMYDBEdit.SetMyDS_1(value:TDataSource);
begin
MyDS_1:=value;
end;
end.
只要我一把控件加到窗口中DELPHI就自动关闭了
要么就提示:Stack overflow-save your work and restart Delphi
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Mask, DBCtrls,
FSQL,Forms,db;
type
TMYDBEdit = class(TDBEdit)
private
function GetMyDS_1:TDataSource;
procedure SetMyDS_1(value:TDataSource);
{ Private declarations }
protected
{ Protected declarations }
public
procedure DblClick; override;
{ Public declarations }
published
property MyDS_1:TDataSource read GetMyDS_1 write SetMyDS_1;
constructor Create(AOwner: TComponent); override;
{ Published declarations }
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('lcy', [TMYDBEdit]);
end;
constructor TMYDBEdit.Create(AOwner: TComponent);
begin
inherited;
end;
procedure TMYDBEdit.DblClick;
begin
IF Application.FindComponent('FSQL1')=nil THEN
BEGIN
Application.CreateForm(TMYForm1, FSQL1);
END;
FSQL1.DBGridEh1.DataSource:=MyDS_1;
FSQL1.Show;
end;function TMYDBEdit.GetMyDS_1:TDataSource;
begin
result:=MyDS_1;
end;procedure TMYDBEdit.SetMyDS_1(value:TDataSource);
begin
MyDS_1:=value;
end;
end.
只要我一把控件加到窗口中DELPHI就自动关闭了
要么就提示:Stack overflow-save your work and restart Delphi
begin
result:=MyDS_1;
end;有問題
begin
IF Application.FindComponent('FSQL1')=nil THEN
BEGIN
Application.CreateForm(TMYForm1, FSQL1);
END;
FSQL1.DBGridEh1.DataSource:=MyDS_1;
FSQL1.Show;
end;
似乎也有问题,不过有些忘了,再想想
begin
result:=MyDS_1;
end;无限递归,使堆栈溢出了!在private下定义一个 TDataSource FMyDS_1;
改GetMyDS_1函数为:
function TMYDBEdit.GetMyDS_1:TDataSource;
begin
result:=FMyDS_1;
end;