(SOLVED) DBF add fields into existing table lazarus / 16-Databases ---------------------------------------------------------------------- xinyiman · 2019-02-13 10:37 Hi I want to add a column to my existing table in a dbf file. What am I doing wrong? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var   MyDBF: TDBF;   dbDefs: TDbfFieldDefs;begin   MyDBF:=TDBF.Create(nil);  MyDBF.FilePath:=Self.PAthDBF;  MyDBF.TableName:=Self.TableNameDBF;   if MyDBF.FindField('ELAB') = nil then  begin       // create new field list       MyDBF.Exclusive:= True;       dbDefs := TDbfFieldDefs.Create(nil);       try         dbDefs.Assign(MyDBF.DbfFieldDefs);         dbDefs.Add('ELAB',ftString,1);         MyDBF.RestructureTable(dbDefs, true);       finally         dbDefs.Free;       end;  end;  MyDBF.Open;  MyDBF.Close; ---------------------------------------------------------------------- Handoko · 2019-02-13 11:22 I have code to add dbf column. I copy/paste and modify a bit to suit your case: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function FieldIndex(aDBF: TDBF; const strField: string): Integer;var  i: Integer;begin  Result := -1;  for i := 0 to (aDBF.DbfFieldDefs.Count-1) do    if (aDBF.DbfFieldDefs.Items[i].FieldName = strField) then    begin      Result := i;      Exit;    end;end; //... var  MyDBF  : TDBF;  dbDefs : TDbfFieldDefs;  dbDef  : TDbfFieldDef;  isNew  : Boolean; begin   MyDBF           := TDBF.Create(nil);  MyDBF.FilePath  := 'the_path_to_the_location';  MyDBF.TableName := 'the_file_name';  MyDBF.Open;   dbDefs := TDbfFieldDefs.Create(nil);  dbDefs.Assign(MyDBF.DbfFieldDefs);   isNew := False;  if FieldIndex('ELAB') < 0 then  begin    isNew           := True;    dbDef           := dbDefs.AddFieldDef;    dbDef.FieldName := 'ELAB';  dbDef.Type      := ftString;    dbDef.Size      := 1;    dbDef.Required  := False;  end;   MyDBF.Close;  if isNew then MyDBF.RestructureTable(dbDefs, True);  dbDefs.Free;  MyDBF.Free end; ---------------------------------------------------------------------- xinyiman · 2019-02-14 07:40 I replace dbDef.Type      := ftString; with dbDef.FieldType := ftString; But run correctly. Thank you very much.