我创建了一个自定义组件:这是一个实体编辑器:一对带有搜索选项的键和描述文本编辑,现在我想扩展它来提供一个带有所选实体数据的数据集。它将该内部数据(TFDQuery)作为属性发布。
type
TKpDBEntityEdit = class(TdxPanel)
private
...
procedure SetEntityData(const Value: TFDQuery);
protected
...
FEntityData: TKpQuery;
FEntityDatasource: TDatasource;
public
...
constructor Create(AOwner: TComponent); override;
published
...
property EntityData: TFDQuery read FEntityData write SetEntityData;
property EntityDatasource: TDatasource read FEntityDatasource;
end;
implementation
...
constructor TKpDBEntityEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
...
FEntityData := TFDQuery.Create(Self);
FEntityData.Name := Self.Name + 'qEntity';
FEntityData.SetSubComponent(True);
FEntityDatasource := TDatasource.Create(Self);
FEntityDatasource.DataSet := FEntityData;
FEntityDatasource.Name := Self.Name + 'dsEntity';
...
end;
procedure TKpDBEntityEdit.SetEntityData(const Value: TFDQuery);
begin
FEntityData.Assign(Value);
end;
这是我编写的能够在设计时调用ShowFieldsEditor并填充持久字段的ComprehentEditor:
unit EntityEdit.Editor;
interface
uses
Windows, SysUtils, Classes, DesignIntf, DesignEditors;
type
TkpEntityEditEditor = class(TComponentEditor)
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
procedure Register;
implementation
uses
Dialogs,
DSDesign,
MyDbEntityEdit;
procedure TkpEntityEditEditor.ExecuteVerb(Index: Integer);
begin
case Index of
0: ShowFieldsEditor(Designer, TKpDBEntityEdit(Component).EntityData, TDSDesigner);
end;
end;
function TkpEntityEditEditor.GetVerb(Index: Integer): string;
begin
case Index of
0: Result := 'Entity Fields Editor...';
end;
end;
function TkpEntityEditEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
procedure Register;
begin
RegisterComponentEditor(TKpDbEntityEdit, TkpEntityEditEditor);
end;
end.
我的问题是它的持久字段没有存储在DFM中,即使在我的内部FDQuery上调用SetSubcomponent(True)之后也没有。
这是一个DFM,用于在表单上添加一个带有4个永久字段(不保存)的编辑器。
object KpDBEntityEdit1: TKpDBEntityEdit2 [17]
Left = 179
Top = 138
Width = 548
Height = 21
Frame.Borders = []
Color = 15790320
TabOrder = 2
EntityName = 'TCountry'
ShowKey = True
ShowDescription = True
KeyWidth = 75
end
奇怪的是,表单确实声明了这4个持久化字段,尽管这些声明并不对应于DFM中的任何对象。
type
TfrmColour = class(TKpView)
...
KpDBEntityEdit1: TKpDBEntityEdit2;
KpDBEntityEdit1code: TWideStringField;
KpDBEntityEdit1description: TWideStringField;
KpDBEntityEdit1coating: TWideStringField;
KpDBEntityEdit1outdated: TBooleanField;
我错过了什么?.为什么我在内部数据集上成功创建的持久字段没有存储在DFM中?.
谢谢
1条答案
按热度按时间vsnjm48y1#
为什么我在内部数据集上成功创建的持久字段没有存储在DFM中?
因为 TDataSet 的 Fields 是通过在写入其属性后调用datasets GetChildren 方法来写入的,但该方法不会为子组件调用。只有子组件的已发布属性才作为所属组件的一部分编写。