unit ValueListPE; interface uses Windows, SysUtils,designEditors,DesignIntf,classes,db,TypInfo,Dbeditplus; Type TValueListProPerty = class(TStringProPerty) private procedure GetValueList(List: TStrings); //自定义过程,得到字段列表 function GetPropertyValue(Instance: TPersistent; const PropName: string): TPersistent; protected { Protected declarations } public procedure GetValues(Proc: TGetStrProc); override; function GetAttributes: TPropertyAttributes; override; { Public declarations } published { Published declarations } end; procedure Register; implementation procedure Register; begin RegisterPropertyEditor(TypeInfo(string), TDBEditPlus, 'ListField', TValueListProPerty);//注册属性为"ListField"的编辑器 RegisterPropertyEditor(TypeInfo(string), TDBEditPlus, 'KeyField', TValueListProPerty);//注册属性为"KeyField"的编辑器 end; { TValueListProPerty } function TValueListProPerty.GetAttributes: TPropertyAttributes; begin Result := [paValueList, paSortList, paMultiSelect];//属性类型 end; function TValueListProPerty.GetPropertyValue(Instance: TPersistent; const PropName: string): TPersistent; var PropInfo: PPropInfo; begin Result := nil; PropInfo := TypInfo.GetPropInfo(Instance.ClassInfo, PropName); if (PropInfo <> nil) and (PropInfo^.PropType^.Kind = tkClass) then Result := TObject(GetOrdProp(Instance, PropInfo)) as TPersistent; end; procedure TValueListProPerty.GetValueList(List: TStrings); var DataSource: TDataSource; begin //查询Datasource为"ListSource"的对像 DataSource := GetPropertyValue(GetComponent(0), 'ListSource') as TDataSource; if (DataSource <> nil) and (DataSource.DataSet <> nil) then DataSource.DataSet.GetFieldNames(List); end; //字段列表赋值 procedure TValueListProPerty.GetValues(Proc: TGetStrProc); var I: Integer; Values: TStringList; begin Values := TStringList.Create; try GetValueList(Values); for I := 0 to Values.Count - 1 do Proc(Values[I]); if values.count=0 then Proc(' '); finally Values.Free; end; end;
组件属性编辑器-数据字段列表功能
最新推荐文章于 2020-02-17 16:45:24 发布