潇
潇湘子
Unregistered / Unconfirmed
GUEST, unregistred user!
初玩控件开发,修改DBEDIT控件,问2个问题
1 自定义属性 EditDataField 不能像DATAFIELD那样从DATASOURCE中获取字段,为什么?
2 控件使用没有问题,但是如果把控件放到FRAME中去,每次在设计阶段,点 EditDataSource 就会报错,晕呀,好像fRAME中先放DBEDIT控件,再放此控件就不会出错
那位大侠指点指点,代码如下:
unit yddbedit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Mask, DBCtrls,db;
type
tyddbedit = class(TDBEdit)
private
// FDataLink: TFieldDataLink;
//?魁?﹍陪ボ?砞竚
FDataSource:TDataSource;
FDataField:String;
//跑秖
FEditDataField:STRING;
FEditDataSource:TDataSource;
//э糶ㄆン
procedure doExit;override;
procedure doenter;override;
//get and set datasource and datafield
// function GetDataField:string;
// function GetDataSource: TDataSource;
// procedure SetDataField(const Value:string);
// procedure SetDataSource(Value: TDataSource);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
// property EditDataField: string read GetDataField write SetDataField;
// property EditDataSource:TDataSource read GetDataSource write SetDataSource;
property EditDataField: string read FEditDataField write FEditDataField;
property EditDataSource:TDataSource read FEditDataSource write FEditDataSource;
end;
procedure Register;
implementation
{function tyddbedit.GetDataField: string;
begin
Result := FDataLink.FieldName;
end;
function tyddbedit.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure tyddbedit.SetDataField(const Value: string);
begin
FDataLink.FieldName := Value;
end;
procedure tyddbedit.SetDataSource(Value: TDataSource);
begin
FDataLink.DataSource := Value;
end;}
procedure tyddbedit.doExit;
begin
Inherited doexit;
if NOT (csDesigning in ComponentState) then
BEGIN
DataSource:=FDataSource;
DataField:=FDataField;
END;
end;
procedure tyddbedit.doEnter;
begin
inherited doenter;
if NOT (csDesigning in ComponentState) then
BEGIN
if (DataSource=EditDataSource) and (DataField=EditDataField) then
else
begin
FDataSource:=DataSource;
FDataField:=DataField;
end;
DataSource:=EditDataSource;
DataField:=EditDataField;
END;
end;
constructor tyddbedit.Create;
begin
inherited create(aowner);
FEditDataSource:=tdatasource.Create(nil);
// FDataLink := TFieldDataLink.Create;
// FDataLink.Control := self;
end;
destructor tyddbedit.Destroy;
begin
// FDataLink.Free;
FEditDataSource.Free;
inherited Destroy;
end;
procedure Register;
begin
RegisterComponents('Data Controls', [tyddbedit]);
end;
end.
1 自定义属性 EditDataField 不能像DATAFIELD那样从DATASOURCE中获取字段,为什么?
2 控件使用没有问题,但是如果把控件放到FRAME中去,每次在设计阶段,点 EditDataSource 就会报错,晕呀,好像fRAME中先放DBEDIT控件,再放此控件就不会出错
那位大侠指点指点,代码如下:
unit yddbedit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Mask, DBCtrls,db;
type
tyddbedit = class(TDBEdit)
private
// FDataLink: TFieldDataLink;
//?魁?﹍陪ボ?砞竚
FDataSource:TDataSource;
FDataField:String;
//跑秖
FEditDataField:STRING;
FEditDataSource:TDataSource;
//э糶ㄆン
procedure doExit;override;
procedure doenter;override;
//get and set datasource and datafield
// function GetDataField:string;
// function GetDataSource: TDataSource;
// procedure SetDataField(const Value:string);
// procedure SetDataSource(Value: TDataSource);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
// property EditDataField: string read GetDataField write SetDataField;
// property EditDataSource:TDataSource read GetDataSource write SetDataSource;
property EditDataField: string read FEditDataField write FEditDataField;
property EditDataSource:TDataSource read FEditDataSource write FEditDataSource;
end;
procedure Register;
implementation
{function tyddbedit.GetDataField: string;
begin
Result := FDataLink.FieldName;
end;
function tyddbedit.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure tyddbedit.SetDataField(const Value: string);
begin
FDataLink.FieldName := Value;
end;
procedure tyddbedit.SetDataSource(Value: TDataSource);
begin
FDataLink.DataSource := Value;
end;}
procedure tyddbedit.doExit;
begin
Inherited doexit;
if NOT (csDesigning in ComponentState) then
BEGIN
DataSource:=FDataSource;
DataField:=FDataField;
END;
end;
procedure tyddbedit.doEnter;
begin
inherited doenter;
if NOT (csDesigning in ComponentState) then
BEGIN
if (DataSource=EditDataSource) and (DataField=EditDataField) then
else
begin
FDataSource:=DataSource;
FDataField:=DataField;
end;
DataSource:=EditDataSource;
DataField:=EditDataField;
END;
end;
constructor tyddbedit.Create;
begin
inherited create(aowner);
FEditDataSource:=tdatasource.Create(nil);
// FDataLink := TFieldDataLink.Create;
// FDataLink.Control := self;
end;
destructor tyddbedit.Destroy;
begin
// FDataLink.Free;
FEditDataSource.Free;
inherited Destroy;
end;
procedure Register;
begin
RegisterComponents('Data Controls', [tyddbedit]);
end;
end.