BufferDataset error Save and Load from file lazarus / 16-Databases ---------------------------------------------------------------------- eldonfsr · 2024-09-24 01:10 I don't know why now bufferdataset give me error save and load from file ---------------------------------------------------------------------- paweld · 2024-09-24 05:04 What version of lazarus / fpc? In Lazarus trunk / fpc 3.2-fixes version the project works fine - when closing the form it saves to file, when opening it loads from file if file exists ---------------------------------------------------------------------- eldonfsr · 2024-09-24 12:32 windows lazarus 3.2.2 this error show when save..and close buffer data ---------------------------------------------------------------------- rvk · 2024-09-24 12:59 Works fine for me too. BUT... you shouldn't free mdbtns in your CloseForm !!!!!!!! The mdbtns is created and controlled (owned) by your form. NEVER free components that you don't create yourself (with nil as owner parameter). This is probably the reason for your error (because TForm is trying to clear and free the component while you already did so). ---------------------------------------------------------------------- eldonfsr · 2024-09-24 13:45 Yes i remove MDBtns.close and MDBtns.free, but  still send me a error on close and another this you can see values show me on dbgrid is not what values i put on fields.. 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 ic:Integer;begin   if( not FileExists(GetCurrentDir+'\BTNSMACROS.db')) then begin     if( MDBtns.Active=false) then begin //      MDBtns.FileName:=GetCurrentDir+'\BTNSMACROS.db';//       MDBtns.LoadFromFile(GetCurrentDir+'\BTNSMACROS.db');       MDBtns.Open;       ic:=0;     if MDBtns.EOF then begin       MDBtns.Append;       MDBtns.FieldByName('PageNo').AsInteger:= 0;     MDBtns.FieldByName('BtnName').AsString:= 'BtnHomeSp1';       MDBtns.FieldByName('Caption').AsString:= 'Home';       MDBtns.FieldByName('Macro').AsString:= 'MS0';       MDBtns.post;     MDBtns.Append;       MDBtns.FieldByName('PageNo').AsInteger:= 0;     MDBtns.FieldByName('BtnName').AsString:= 'BtnMovUnoSp1';       MDBtns.FieldByName('Caption').AsString:= 'Move 1';       MDBtns.FieldByName('Macro').AsString:= 'MS30';       MDBtns.post;     MDBtns.Append;       MDBtns.FieldByName('PageNo').AsInteger:= 0;     MDBtns.FieldByName('BtnName').AsString:= 'BtnMtoDosSp1';       MDBtns.FieldByName('Caption').AsString:= 'Move 2';       MDBtns.FieldByName('Macro').AsString:= 'MS35';       MDBtns.post;     MDBtns.Append;       MDBtns.FieldByName('PageNo').AsInteger:= 0;     MDBtns.FieldByName('BtnName').AsString:= 'BtnMvtCycleSp1';       MDBtns.FieldByName('Caption').AsString:= 'Move Cycle';       MDBtns.FieldByName('Macro').AsString:= 'MS40';       MDBtns.post;     MDBtns.Append;       MDBtns.FieldByName('PageNo').AsInteger:= 0;     MDBtns.FieldByName('BtnName').AsString:= 'BtnMvtLoopSp1';       MDBtns.FieldByName('Caption').AsString:= 'Loop Cycle';       MDBtns.FieldByName('Macro').AsString:= 'MS50';       MDBtns.post;     MDBtns.Append;       MDBtns.FieldByName('PageNo').AsInteger:= 0;     MDBtns.FieldByName('BtnName').AsString:= 'BtnTechPosi1Sp1';       MDBtns.FieldByName('Caption').AsString:= 'Teach Posi 1';       MDBtns.FieldByName('Macro').AsString:= 'MS90';       MDBtns.post;     MDBtns.Append;       MDBtns.FieldByName('PageNo').AsInteger:= 0;     MDBtns.FieldByName('BtnName').AsString:= 'BtnTechPosi2Sp1';       MDBtns.FieldByName('Caption').AsString:= 'Teach Posi 2';       MDBtns.FieldByName('Macro').AsString:= 'MS95';       MDBtns.post;     MDBtns.Append;       MDBtns.FieldByName('PageNo').AsInteger:= 0;     MDBtns.FieldByName('BtnName').AsString:= 'BtnSpeedAccSp1';       MDBtns.FieldByName('Caption').AsString:= 'Speed Acc';       MDBtns.FieldByName('Macro').AsString:= 'MS100';       MDBtns.post;     MDBtns.Append;       MDBtns.FieldByName('PageNo').AsInteger:= 0;     MDBtns.FieldByName('BtnName').AsString:= 'BtnFindSurfSp1';       MDBtns.FieldByName('Caption').AsString:= 'Find Surface';       MDBtns.FieldByName('Macro').AsString:= 'MS60';       MDBtns.post;     end;    end else begin       MDBtns.FileName:=GetCurrentDir+'\BTNSMACROS.db';       mdbtns.LoadFromFile(GetCurrentDir+'\BTNSMACROS.db');       MDBtns.Open;    end;     end else begin     mdbtns.LoadFromFile(GetCurrentDir+'\BTNSMACROS.db' );     MDBtns.Open;   end; ---------------------------------------------------------------------- eldonfsr · 2024-09-24 13:48 I download and install lazarus 3.4 still the same problem .... ---------------------------------------------------------------------- rvk · 2024-09-24 13:50 Quote from: eldonfsr on September 24, 2024, 03:45:19 pmYes i remove MDBtns.close and MDBtns.free, but  still send me a error on closeDoesn't happen here Quote from: eldonfsr on September 24, 2024, 03:45:19 pm and another this you can see values show me on dbgrid is not what values i put on fields.. You might want to begin with deleting the existing db file because that code doesn't execute if the file exists. (And you probably have some fields from before) This code doesn't correspond with the earlier code so you have changed things around. So we can't tell what's going on. BTW. I wouldn't do MDBtns.FieldByName('PageNo').AsString := '4' since PageNo is defined as SmallInt. You might want to use AsInteger instead. (FPC will convert this but it's better to be sure) ---------------------------------------------------------------------- eldonfsr · 2024-09-24 17:39 I create a new project and send me same error when close app is only bufferdata and dbgrid on form.. and also the information is now as was insert on fields... some problems lazarus 3.4 64 on windows 10 ---------------------------------------------------------------------- BrunoK · 2024-09-24 17:51 Quote from: eldonfsr on September 24, 2024, 07:39:55 pmI create a new project and send me same error when close app is only bufferdata and dbgrid on form.. and also the information is now as was insert on fields... some problems lazarus 3.4 64 on windows 10 All I can add is that I tried the last program (Win 10, FPC 3.2.2, laz +- trunk) and there are quite a few errors showing as described by eldonfsr. I couldn't find what might be wrong to the point of getting all these errors in his code. ---------------------------------------------------------------------- eldonfsr · 2024-09-24 18:52 I made the same sample on other computer and same results datas not as was input values and when close app same error... lazarus 3.4 windows 10... and i made same test typhon and not problem.... ---------------------------------------------------------------------- TRon · 2024-09-24 18:57 Wasn't there an issue with tbufdataset and persistent fields ? e.g. you had to use createdataset explicitly ? I might remember it wrong though... ---------------------------------------------------------------------- eldonfsr · 2024-09-24 19:58 Exactly is what i did... ---------------------------------------------------------------------- TRon · 2024-09-24 22:25 Apologies as it took me some time to locate the corresponding thread. see here, reported at issue  40450 (and seems to have been fixed by wp). My mind isn't exactly clear atm so pardon me for not being able to advise how you need to fix that in your current code. Perhaps someone else is around is able to help you out. ---------------------------------------------------------------------- eldonfsr · 2024-09-24 22:34 Wow i understand what you sad... i made changes and look working let me continue with make better understanding this thinks... ---------------------------------------------------------------------- rvk · 2024-09-25 00:45 Quote from: TRon on September 25, 2024, 12:25:41 amsee here, reported at issue  40450 (and seems to have been fixed by wp). Which should be fixed in version 3.4, shouldn't it? Quote from: eldonfsr on September 24, 2024, 08:52:05 pmI made the same sample on other computer and same results datas not as was input values and when close app same error... lazarus 3.4 windows 10... and i made same test typhon and not problem.... So that version should be ok. (I'm on the fixes_3_2 version and it worked fine for me so it should have worked in 3.4 too) ---------------------------------------------------------------------- egsuh · 2024-09-25 03:49 I think the problems come from TFields,    MDBtnsBtnName    MDBtnsCaption    MDBtnsPageNo    MDBtnsMacro and so on. When I removed them, all works fine, except saving the file.  ------------- I have dropped all the TFields, and added them again and the program works fine, including saving the database. ---------------------------------------------------------------------- rvk · 2024-09-25 08:20 Quote from: egsuh on September 25, 2024, 05:49:12 amI have dropped all the TFields, and added them again and the program works fine, including saving the database. Can you compare the lfm (the part with the fields) with the original one? I wonder why it would work after that. (And what version of Lazarus?) ---------------------------------------------------------------------- TRon · 2024-09-25 08:20 Quote from: rvk on September 25, 2024, 02:45:27 amWhich should be fixed in version 3.4, shouldn't it? Are you sure that Lazarus 3.4 came with a new(er) version of FPC ?  I am not sure it made fixes though (and I haven't seen fixes/trunk mentioned by TS). ---------------------------------------------------------------------- rvk · 2024-09-25 08:24 Quote from: TRon on September 25, 2024, 10:20:09 amQuote from: rvk on September 25, 2024, 02:45:27 amWhich should be fixed in version 3.4, shouldn't it? Are you sure that Lazarus 3.4 came with a new(er) version of FPC ?  I am not sure it made fixes though (and I haven't seen fixes/trunk mentioned by TS). Woops, yes, I meant FPC fixes (the TBufDataset is in FPC, not in Laz). Last week I tried a new trunk (Laz+FPC) and that failed so I set my script back at fixes versions. Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i set fpc_version="fixes_3_2"set laz_version="fixes_3_2a" That version gave me no problems. Aren't those (fixes_3_2 and fixes_3_2a) not incorperated in the Lazarus 3.4 install (for both FPC and Lazarus) ??? Quote from: mattias on May 29, 2024, 09:38:42 amThe Lazarus team is glad to announce the release of Lazarus 3.4. This is a bugfix release and was built with FPC 3.2.2. Aaaaargh. So maybe they are not and FPC still has that problem with the standard install. ---------------------------------------------------------------------- egsuh · 2024-09-25 08:44 QuoteCan you compare the lfm (the part with the fields) with the original one? I wonder why it would work after that. (And what version of Lazarus?) I don't see any difference between the two files, except that I've set the size of field MCode to 20, which is a ftMemo field (in the original file, it was 0). At first I had the same errors reported, and I set the size of MCode to 20, and the same errors. Then I deleted and repopulated all the TFields. Then OK. Lazarus version is 3.4. ---------------------------------------------------------------------- rvk · 2024-09-25 09:30 Just tried standard 3.4 (my own compile went correctly but I'm not sure the revert to 3.2.2 went ok). Standard Laz 3.4 with FPC 3.2.2 is indeed a mess with TBufDataset. Just removing the MCode (and decoupling the TDBMemo) fixes the startup problems (without a DB present). The error for exiting probably has to do with that mentioned issue. BTW. After starting the application with an existing correct db, the exit works fine. ---------------------------------------------------------------------- TRon · 2024-09-25 12:11 Quote from: rvk on September 25, 2024, 10:24:07 amWoops, yes, I meant FPC fixes (the TBufDataset is in FPC, not in Laz). Thank you for the confirmation (my head is such a mess atm that I wasn't sure either). QuoteAren't those (fixes_3_2 and fixes_3_2a) not incorperated in the Lazarus 3.4 install (for both FPC and Lazarus) ??? Unfortunately, no. That is why it is such a PITA that the release-cycle of FPC is (so) much slower (when compared to Lazarus). QuoteAaaaargh. So maybe they are not and FPC still has that problem with the standard install. For sure. Therefor the only person able to shed a light is eldonfsr (until then I/we have to assume that (s)he is using a standard (non trunk/fixes) installation, no matter the version) fwiw: It seems to be such a mess (either code-wise or in my head, not sure  ) that I do not know how to (correctly) work around the issue in TS' code. ---------------------------------------------------------------------- rvk · 2024-09-25 12:44 Quote from: TRon on September 25, 2024, 02:11:15 pmfwiw: It seems to be such a mess (either code-wise or in my head, not sure  ) that I do not know how to (correctly) work around the issue in TS' code. Yes, my advise would be to just get rid of the persistent fields (via the object inspector). They aren't even used so just remove them. (only use FieldByName, NOT persistent defined fields. But leave the FieldDefs in the TBufDataset (they are used for creation). Move everything from FormShow to FormCreate (you don't want to be too late with creating the database). Last... change the first MDBtns.Open to MDBtns.CreateDataset in Active=false part (just above the Append). After that... everything should work fine (even in Lazarus 3.4). ---------------------------------------------------------------------- TRon · 2024-09-26 05:28 Quote from: rvk on September 25, 2024, 02:44:55 pmAfter that... everything should work fine (even in Lazarus 3.4). (Again) apologies for the delay. Thank you very much for those detailed instructions rvk  That seems to work as intended.... with one small side-note: I needed to remove the existing db (from the original archive of TS) in order to prevent a streaming error on startup (which makes perfect sense). In hind-side the suggested workaround makes perfect sense but this must be a PITA for those unfamiliar with bufdataset (which includes me as I hardly use this class/component) ---------------------------------------------------------------------- rvk · 2024-09-26 09:26 Quote from: TRon on September 26, 2024, 07:28:47 amIn hind-side the suggested workaround makes perfect sense but this must be a PITA for those unfamiliar with bufdataset (which includes me as I hardly use this class/component) I do find it logical that you would need to do a CreateDataset (or likewise command). But I also normally don't used predefine FieldDefs in the object inspector. I much more prefer adding the FieldDefs in code and then a CreateDataset is more intuitive to create the dataset after defining the fields. And then there is no problem. Luckily the problem with persistent fields is solved in the next version. But I don't like using persistent fields anyway (as I do everything via code and FieldByName). ---------------------------------------------------------------------- TRon · 2024-09-26 09:36 Amen to/for setting things up manually rvk. Even though I started out designing databases with the visual designer (Delphi back then), once you have several forms/modules stuffed to the brim with database components then things become unmaintainable and is it much easier to manage manually (especially when you have the GUI and functional code separated). Hopefully TS is (now) able to workaround the issue as well (thanks to your excellent instructions) but even better would be a new release of the compiler Again, thank you very much for the guidance rvk.