大家好!
  如何在程序运行的时候动态添加字段呢!包含Calculate字段!
thanks

解决方案 »

  1.   

    自己搞定:
    procedure Tfrmdbhelpt.FormShow(Sender: TObject);
    const SqlFmt='select %s from %s%s%s order by %s';
    var
      QryTmp: TADOQuery;
      i: integer;
      sSQL: string;
      FS: TStringField;
      j: integer;
    begin
      inherited;
      sSQL:=Format(SqlFmt,[strCol,strDBName,' where ',strWhere,strOrder]);
      QryTmp:=TADOQuery.Create(nil);
      QryTmp.Connection:=DllAdoCn;
      QryTmp.Close;
      QryTmp.SQL.Clear;
      QryTmp.SQL.Add(sSQL);
      QryTmp.Open;  Qryhelp.Connection:=DlladoCn;
      Qryhelp.Close;
      Qryhelp.SQL.Clear;
      Qryhelp.SQL.Add(sSQL);
      for j:=0 to QryTmp.FieldCount-1 do
      begin
        FS:=TStringField.Create(Qryhelp);
        FS.FieldName:=Trim(QryTmp.Fields[j].DisplayLabel);
        FS.Index:=QryTmp.FieldCount;
        FS.DataSet:=Qryhelp;
      end;
      Qryhelp.FieldDefs.Update;
      Qryhelp.Open;
      SearchField.Items.Clear;
      with Qryhelp do begin
        for i:=1 to Qryhelp.FieldCount-1 do
        SearchField.items.add(Fields[i].DisplayLabel);
      end;
      searchField.ItemIndex:=0;
    end;