[SOLVED] Laz 2.0.10/fpc 3.2.0 and TBufDataset lazarus / 16-Databases ---------------------------------------------------------------------- OH1KH · 2021-03-02 09:46 HI ! Can someone again kindly advice me of reading (and understanding) the changes file. Thank you. I see that Lazarus 2.0.12 is out, but it seems the fpc part has not changed (file names and zip sizes are same) I will test that later when I have time so I assume the error still exist. Now the problem is with  TBufDataset. Code that perfectly works with laz2.0.8/fpc 3.0.4 does not work any more causing access violation error. 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 db := TBufDataset.Create(nil);        try          db.FieldDefs.Clear;        with db.FieldDefs do          begin            Add('loc', ftString, 4);            Add('cfm',ftBoolean)          end;          db.CreateDataset;          db.IndexDefs.Add('loc','loc',[ixPrimary]);           db.Open;        wkd := 0;          while not dmData.Q1.Eof do          begin          db.Append;            db.Fields[0].AsString  := dmData.Q1.Fields[0].AsString;            db.Fields[1].AsBoolean := False;            db.Post;            inc(wkd);            dmData.Q1.Next          end;       When execution comes  first time to line dp.post Access violation error is created. I tried to find what would be the difference reading changes documents but I could not find (understand) any reason. ---------------------------------------------------------------------- LacaK · 2021-03-02 09:58 if you omit line 10 : db.IndexDefs.Add('loc','loc',[ixPrimary]); then there is still AV ? ---------------------------------------------------------------------- dseligo · 2021-03-02 10:35 Quote from: LacaK on March 02, 2021, 10:58:00 amif you omit line 10 : db.IndexDefs.Add('loc','loc',[ixPrimary]); then there is still AV ? I also had this problem with IndexDefs.Add (and I just commented it out). After "Open" I added: 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 IndexFieldNames:='myfield1;myfield2'; I don't know if that helps. ---------------------------------------------------------------------- OH1KH · 2021-03-02 11:18 Thanks for quick reply! Yes! Commenting out line  db.IndexDefs.Add('loc','loc',[ixPrimary]); helps. This part of code is not originally written by me so I have to clear out what IndexDefs.Add there stands for and could/needs this to be replaced with IndexFieldNames:='myfield1;myfield2'; Program seems to work without IndexFieldNames and with it. With quick look result is similar. Funny that this it again one problem that arises when you update laz/fpc without touching the source you are going to compile. And in this case I could not find anything from update changes file that I am able to connect to this problem. ---------------------------------------------------------------------- PascalDragon · 2021-03-02 12:42 Quote from: OH1KH on March 02, 2021, 12:18:58 pmYes! Commenting out line  db.IndexDefs.Add('loc','loc',[ixPrimary]); helps. You should use TCustomBufDataset.AddIndex instead. IndexDef should be considered as readonly. ---------------------------------------------------------------------- cdbc · 2021-03-02 13:18 Code: [Select]Hi Try this: [code=pascal] Procedure TBufDataset.CopyFromDataset(DataSet : TDataSet; CopyData : Boolean); Var   I  : Integer;   F,F1,F2 : TField;   L1,L2  : TList;   N : String; begin   Clear(True);   // NOT from fielddefs. The data may not be available in buffers !!   for I:= 0 to Dataset.FieldCount-1 do begin     F:= Dataset.Fields[I];     // ææ special case for ftAutoInc fields 16.02.2020 /bc     if F.DataType = ftAutoInc then TFieldDef.Create(FieldDefs,F.FieldN ame,ftInteger,F.Size,F.Required,F.FieldNo)     else TFieldDef.Create(FieldDefs,F.FieldName,F.DataType,F.Size,F.Re quired,F.FieldNo);   end;   CreateTable;   if CopyData then begin     Open;     L1:= TList.Create;     try       L2:= TList.Create;       try         for I:= 0 to FieldDefs.Count-1 do begin           N:= FieldDefs[I].Name;           F1:= FieldByName(N);           F2:= DataSet.FieldByName(N);           L1.Add(F1);           L2.Add(F2);         end;         Dataset.DisableControls;         try           Dataset.Open;           while not Dataset.EOF do begin             Append;             for I:= 0 to L1.Count-1 do begin               F1:= TField(L1[i]);               F2:= TField(L2[I]);               case F1.DataType of                 ftString   : F1.AsString:= F2.AsString;                 ftBoolean  : F1.AsBoolean:= F2.AsBoolean;                 ftFloat    : F1.AsFloat:= F2.AsFloat;                 ftLargeInt : F1.AsInteger:= F2.AsInteger;                 ftSmallInt : F1.AsInteger:= F2.AsInteger;                 ftInteger  : F1.AsInteger:= F2.AsInteger;                 ftDate     : F1.AsDateTime:= F2.AsDateTime;                 ftTime     : F1.AsDateTime:= F2.AsDateTime;                 ftDateTime : F1.AsDateTime:= F2.AsDateTime;               end;             end;             try Post; except Cancel; Raise; end;             Dataset.Next;           end;         finally Dataset.EnableControls; end;       finally L2.Free; end;     finally L1.Free; end;   end; end; Implement this in TBufDatset and maybe locate, I dono. Indexes i dono  As you can see it's 'stolen' from TMemDataset. Regards Benny ---------------------------------------------------------------------- OH1KH · 2021-03-02 13:42 Change code like this makes it work: 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    db := TBufDataset.Create(nil);         try          db.FieldDefs.Clear;        //with db.FieldDefs do          //begin            db.FieldDefs.Add('loc', ftString, 4);            db.IndexDefs.Add('loc','loc',[ixPrimary]);            db.FieldDefs.Add('cfm',ftBoolean);          //end;          db.CreateDataset;          //db.IndexDefs.Add('loc','loc',[ixPrimary]);          db.Open;        wkd := 0;          while not dmData.Q1.Eof do          begin          db.Append;            db.Fields[0].AsUTF8String  := dmData.Q1.Fields[0].AsString;            db.Fields[1].AsBoolean := False;            db.Post;            inc(wkd);            dmData.Q1.Next          end;                 IndexDefs should be done before CreateDataset, then no error happen in db.post any more.