MemTables Memdataset check fieldsdefintion before open lazarus / 16-Databases ---------------------------------------------------------------------- eldonfsr · 2024-11-14 14:17 Hello well i using memdataset for create a memory tables and handle information but never has this fact.. 1.- How i can update fieldsdefinition and don't lose information , if i update on design time when i run the program rise on error      how i can validate current table changes before open and transfer information the other way big problem 2.- I need to keep old fielddefinitions and with that information handle and  migrate to new table structure... Any Idea are welcome ---------------------------------------------------------------------- eldonfsr · 2024-11-14 17:39 After reading i think get solve this problem,  what i did is open file creating dataset and assign the file name and open it, this way fields are created with file structure, after that compare fieldcount and fielddef.count see if both are same .. 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 on create form  TmpBuff:= TBufDataset.Create(nil);  TmpDs:= TDataSource.Create(nil);  TmpDs.DataSet := TmpBuff; //---------------- ----------------------  if(FileExists(GetCurrentDir+'\mmacros.db')) then begin    TmpBuff.FileName:=GetCurrentDir+'\mmacros.db';    TmpBuff.Open;    if(TmpBuff.FieldCount<>MDBtns.FieldDefs.Count) then begin      MigrateTable(TmpBuff, MDBtns);    end;    TmpBuff.close;  end;  TmpBuff.Clear;  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 Procedure TForMMain.MigrateTable(OldTbl:TBufDataSet; NewTbl:TBufDataSet);Var Fldname:String;    cf:Integer;begin if( NewTbl.Active = false) then begin    NewTbl.Open; end; oldtbl.First; while not oldtbl.EOF do begin   newtbl.Append;   for cf:=0 to oldtbl.FieldCount-1 do begin      fldname:= oldtbl.FieldDefs[cf].DisplayName;      newtbl.FieldByName(fldname).Value:= oldtbl.FieldByName(fldname).Value;   end;   newtbl.Post;   oldtbl.Next; end; NewTbl.SaveToFile(oldtbl.FileName);end;         Could be another way to do that but now for me is working.. ---------------------------------------------------------------------- Richard Marriott · 2024-12-16 06:08 As far as I know, none of the TDataset descendants that ship with Lazarus allow a change to Field Definitions or Indexes after the table is Created and records added. The only solution is the one that you have described, where a new table is defined and the old table is copied across. ---------------------------------------------------------------------- egsuh · 2024-12-16 06:18 If you want to save table structure and data, and need to change the structrure sometimes, I recomment you to use SQLite etc.