TDbf: "Operation cannot be performed on an inactive dataset" lazarus / 16-Databases ---------------------------------------------------------------------- maurobio · 2021-12-17 20:01 Dear ALL, I am having a hell of a time while attempting to do something which looks quite simple with a bunch of TDbf's datasets. I have a master list of a few plants collected somewhere (the COLLECTION file), with fields which point to a list of plant genera (the GENERA file) and to a list of species names (the SPECIES file). What I do want is simply to display the genus and the species name in a read only edit field, for each record in the master file. For this purpose, I added a few lines in the AfterScroll event of the master file However, the compiler keeps complaining that this "Operation cannot be performed on an inactive dataset", even if I am opening all data tables in the OnCreate event of the main form. My sample code is attached, and I believe that the problem will be more easily understood by perusing that code. Could someone out there help me to understand what am I missing? Thanks in advance! With best wishes, ---------------------------------------------------------------------- Sieben · 2021-12-17 20:23 This is because Dbf1AfterScroll() fires immediately after Dbf1.Open - when Dbf2/3 are not yet active. You have to disconnect the event in the IDE and connect it in FormCreate() only after all tables have been opened. 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 TForm1.FormCreate(Sender: TObject);begin  Dbf1.Open;  Dbf2.Open;  Dbf3.Open;  Dbf1.AfterScroll := @Dbf1AfterScroll;end;  Or you can alter the opening sequence so that Dbf1 opens last, or you can test for the Active status of Dbf2 and Dbf3 in the event... Apart from that, did you have a look at the MasterSource/MasterField concept? ---------------------------------------------------------------------- maurobio · 2021-12-17 20:32 Hi, @Sieben! Thanks a lot for your fast and helpful reply! I would never guess to call the AfterScroll event in the way you pointed out. Yes, I have had a look at the master/detail concept (of which there is some discussion in the TDbf tutorial page: https://wiki.lazarus.freepascal.org/Lazarus_Tdbf_Tutorial). It can surely be useful to the sort of data I am working with. With warmest regards, ---------------------------------------------------------------------- Sieben · 2021-12-17 21:01 Just to be clear - it's not calling the event, it's connecting it. And as I said there are other solutions as well once you know why it's happening. ---------------------------------------------------------------------- maurobio · 2021-12-17 21:08 @Hi, Sieben, Sure, sorry for the misplaced verb - it should be "connect" instead of "call". But we all got the point!  With best wishes,