请问如何对adotable添加字段啊
是在程序里加,刚学,不知道怎么加
好人们,请多多指教啊...

解决方案 »

  1.   

    procedure TForm1.AuthorGetText(Sender: TField; var Text: String;
      DisplayText: Boolean);
    begin
      if Sender = nil then Exit;
      if Sender.DataSet.FieldByName('Status').Value = 'OP' then
        Text := '審核'
      else Text := '未審核';
    end;//注意,在增加字段的時候,需要將數據至為不活動
    procedure TForm1.Button1Click(Sender: TObject);
    var
      fAutroth: TStringField;
    begin
      fAutroth := TStringField.Create(ADOTable1);
      fAutroth.FieldKind := fkCalculated;
      fAutroth.DisplayLabel := '審核';
      fAutroth.FieldName := 'Author';
      fAutroth.DataSet := ADOTable1;
      fAutroth.OnGetText := AuthorGetText;
      ADOTable1.Fields.Add(fAutroth);
    end;
    不過在增加字段時,需要加到全局變量中才行,因為增加了之
    後還需要釋放才行,要不然會有錯誤