一个控件开发的问题 ( 积分: 100 )

  • 主题发起人 主题发起人 潇湘子
  • 开始时间 开始时间

潇湘子

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.
 
初玩控件开发,修改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.
 
报什么错
 
Access violation at address 400373e3 in module rl70.bpl. Read of address 00000005
 
你自定的控件是不是不会自动引用单元,如果你放了DBEdit就行了,可能是这样吧?
 
我也不知道呀,这方面不是很清楚,晕呀
 
后退
顶部