字典数据表设计,table字段设置排序
读取字典元数据方法
procedure SetDataSet(dataset: TDataSet; const table: string); var d: TADOQuery; i: Integer; begin if dataset = nil then Exit; if not dataset.Active then Exit; if table = '' then Exit; d := TADOQuery.Create(nil); try with d do begin Connection := uFunction.GetConnection; Close; SQL.Clear; SQL.Text := 'select table, ename, cname, width, visible from dictionary '+ 'where table = :a'; Parameters.ParamByName('a').Value := table; Open; end; if d.IsEmpty then Exit; d.First; while not d.Eof do begin for I := 0 to dataset.FieldCount - 1 do begin if dataset.Fields[i].FieldName = d.FindField('ename').AsString then begin dataset.Fields[i].DisplayLabel := d.FindField('cname').AsString; dataset.Fields[i].DisplayWidth := d.FindField('width').AsInteger; dataset.Fields[i].Visible := d.FindField('visible').AsBoolean; Break; end; end; d.Next; end; finally d.Free; end; end;
调用示例
procedure TformEmployee.HYVisualPluginCreate(Sender: TObject); begin with ADOQuery1 do begin Connection := uFunction.GetConnection; Close; SQL.Clear; SQL.Text := 'select * from employee'; Open; end; uFunction.SetDataSet(ADOQuery1, 'employee'); end;
效果图片