Z
zjmaskman
Unregistered / Unconfirmed
GUEST, unregistred user!
继承于TDataGrid的一个子类,增加了一个私有成员 FDataset:TDataset,希望保存Datasource属性中指向的数据集,从而捕捉数据集的AfterOpen事件。我这样写:
type
TDBGridChild = class(TDBGrid)
private
FDataset:TDataset;
protected
procedure DatasetAfterOpen(Dataset:TDataset);
public Constructor Create(AOwner:TComponent);override;
......
end;
implementation
......
Constructor TDBGridChild.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FDataset := TDataset.Create(AOwner);
FDataset := Datasource.DataSet;
//运行到此出错,原因是Datasource = nil,但我在Object Inspector中已对该组件的Datasource属性进行了赋值。难道Datasource属性并不是在构造函数中已构建完毕吗?
FDataset.AfterOpen := DatasetAfterOpen;
end;
type
TDBGridChild = class(TDBGrid)
private
FDataset:TDataset;
protected
procedure DatasetAfterOpen(Dataset:TDataset);
public Constructor Create(AOwner:TComponent);override;
......
end;
implementation
......
Constructor TDBGridChild.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FDataset := TDataset.Create(AOwner);
FDataset := Datasource.DataSet;
//运行到此出错,原因是Datasource = nil,但我在Object Inspector中已对该组件的Datasource属性进行了赋值。难道Datasource属性并不是在构造函数中已构建完毕吗?
FDataset.AfterOpen := DatasetAfterOpen;
end;