这个自定义控件是TXQuery,它有一个Sqls属性,类型是TSqls,安装之后.新建一个普通工程,放置一个TXQuery控件,发现在控件的属性浏览器的属性SQLS中的文本框出现文本”(Unknown)”字样.单击”...”按钮,打开SqlsForm,然后编辑SQLS,而这个SqlsForm也能成功改动SQLS属性.但是运行时,发现放置的TXQuery的中的SQLS属性没有加载任何东西.停止运行之后,发现放置的TXQuery控件的SQLS的属性还存在.为什么会这样呢?
还有,关闭工程再打开.发现放置的TXQuery控件的SQLS属性全部不见了.
TXQuery = class(TADOQuery)
private
FSqls:TSQls;
published
property Sqls:TSqls read FSqls write FSqls;
end; TSQLS=class(TPersistent)
private
SqlLab:TStringList;
Sqls :TStringList;
function GetCount: Integer;
public
.....
published
end; TSqlsEditorProperty = class(TPropertyEditor)
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
end;procedure TSqlsEditorProperty.Edit;
var
SqlsEditor:TSqlsForm;
sqls:TSqls;
begin
inherited; SqlsEditor:=TSqlsForm.Create(nil);
SQLS:=TSqls(self.GetOrdValue);
sqlseditor.SQLS:=sqls;
SqlsEditor.ShowModal; sqlsEditor.Free;
end;function TSqlsEditorProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog] //指定这是一个对话框编辑器
end;procedure Register;
begin
//注册TSQLS编辑器
RegisterPropertyEditor(TypeInfo(TSQls), TXQuery,'Sqls',TSqlsEditorProperty);
RegisterComponents('ADO', [TXQuery]);
end;
还有,关闭工程再打开.发现放置的TXQuery控件的SQLS属性全部不见了.
TXQuery = class(TADOQuery)
private
FSqls:TSQls;
published
property Sqls:TSqls read FSqls write FSqls;
end; TSQLS=class(TPersistent)
private
SqlLab:TStringList;
Sqls :TStringList;
function GetCount: Integer;
public
.....
published
end; TSqlsEditorProperty = class(TPropertyEditor)
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
end;procedure TSqlsEditorProperty.Edit;
var
SqlsEditor:TSqlsForm;
sqls:TSqls;
begin
inherited; SqlsEditor:=TSqlsForm.Create(nil);
SQLS:=TSqls(self.GetOrdValue);
sqlseditor.SQLS:=sqls;
SqlsEditor.ShowModal; sqlsEditor.Free;
end;function TSqlsEditorProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog] //指定这是一个对话框编辑器
end;procedure Register;
begin
//注册TSQLS编辑器
RegisterPropertyEditor(TypeInfo(TSQls), TXQuery,'Sqls',TSqlsEditorProperty);
RegisterComponents('ADO', [TXQuery]);
end;
procedure TSqlsEditorProperty.Edit;
上面代码中的这个过程,当中的
SQLS:=TSqls(self.GetOrdValue);
sqlseditor.SQLS:=sqls;
SqlsEditor.ShowModal;
已经就是把TXQuery控件中的SQLS的指针交给SqlsForm了.所以,打开sqlsform再编辑,就会修改这个tsqls对象了.