[SOLVED] Struggling with multiple forms, DBGrids and SQLite lazarus / 16-Databases ---------------------------------------------------------------------- Gizmo · 2020-08-22 18:55 I need some help! I'm going insane. I have 3 x TSQLQuery 3 x TDataSource 1 x SQLite3Connection 1 x SQLTranscaction The 3 TDataSources are each 'connected' to the 3 respective SQLQueries. And each SQLQuery is connected to the SQLite3Connection. Then, I have 3 forms, and in each form, is a DBGrid. Each DBGrid of each form is linked to the corresponding DataSource. Of the 3, 2 work fine. They are made visible and shows columns and rows of data. However, the third one, which I thought I made in exactly the same way just will not show any data. The form is empty when made visible. And if I add a line like the following, I get "Project X raised exception class 'External : SEGSEGV in file x.pas at line X : frmDisplayGrid3.DBGrid3.Options := frmDisplayGrid3.DBGrid3.Options + [dgAutoSizeColumns]; : 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     frmDisplayGrid3.DBGrid3.Options := frmDisplayGrid3.DBGrid3.Options + [dgAutoSizeColumns];  I have spent literally hours trying to see where I might not have a uses clause added or something. And I just can't understand why it won't display the content. It seems as though the form can't hold the data or something? I have even tried quering the SQLite database by adding a breakpoint to the code just before I try to make the 3rd form visible. It definitely exists and it holds all the data I want to show in the 3rd form. But I just can't get it to show or be accepted into the form. I can't easily paste the code relating to it because it spans several units and forms but if needs be I'll try. I'm hoping for now someone might be able to identify what the issue is most likely to be given the above error description. i.e. empty form with the line above commented out, and with it in, I get "Project X raised exception class 'External : SEGSEGV" ---------------------------------------------------------------------- madref · 2020-08-23 11:40 Can you make a working example? ---------------------------------------------------------------------- egsuh · 2020-08-24 05:38 Aren't you creating the form after the following statement?   frmDisplayGrid3.DBGrid3.Options := frmDisplayGrid3.DBGrid3.Options + [dgAutoSizeColumns]; Check the creation of components, especially if you are using frames. ---------------------------------------------------------------------- fpcoder · 2020-08-24 08:19 I think this happened for me too. The reason was that something was being used that was not ready/opened/created yet. It was a config simple mistake, but hard on the sanity until found out. To start with, set DBGrid3.DataSource to "None" in the object inspector and see if it works now. 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 frmDisplayGrid3.DBGrid3.Options := frmDisplayGrid3.DBGrid3.Options + [dgAutoSizeColumns]; ---------------------------------------------------------------------- wp · 2020-08-24 09:12 Quote from: Gizmo on August 22, 2020, 08:55:28 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     frmDisplayGrid3.DBGrid3.Options := frmDisplayGrid3.DBGrid3.Options + [dgAutoSizeColumns]; Does this code belong to a method of class TfrmDisplayGrid3? Then remove the "frmDisplayGrid3" from this and any other methods of TfrmDisplayGrid3. Because having the instance name in the class code means that the code will work only when the instance is named exactly like that. If you do not auto-create the form there is a high chance that this code will fail because there is no "frmDisplayGrid3". ---------------------------------------------------------------------- Gizmo · 2020-08-24 10:41 Thanks guys for the suggestions. Re the form creation aspect. The LPR project file creates all the forms at startup as far I am aware with the following lines : 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 ...Application.CreateForm(TMainForm, MainForm);Application.CreateForm(TfrmDisplayGrid1, frmDisplayGrid1);Application.CreateForm(TfrmDisplayGrid3, frmDisplayGrid3);Application.CreateForm(TfrmAbout, frmAbout);Application.CreateForm(TfrmSQLiteDBases, frmSQLiteDBases); ...Application.Run;  So all the forms should be created by the time they are called. On the class point raised by WP...I did try changing the line from 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     frmDisplayGrid3.DBGrid3.Options := frmDisplayGrid3.DBGrid3.Options + [dgAutoSizeColumns];  to 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     DBGrid3.Options := DBGrid3.Options + [dgAutoSizeColumns];  but then when compiling it said the identifier could not be found and was unknown. Re the DataSource for DBGrid3 to none suggestion...for that particular component (the DBGrid3) the datasource is already blank (none). It is the SQLQueries that have the datasources attached to them. The other two DBGrids that work get populated via the SQLQueries but the same technique for this one just wont work. So I have resorted to deleting it, and trying again with a new form and a new DBGrid. Added all the usual uses to link it together. I noticed this time that in the object inspector for the new DBGrid, in the "Datasource" drop down, all three of the datasource options are now listed, whereas they were not before for this 3rd grid (yet for the other two, they are listed). So I figured the problem must have been some kind of invisibility of the datasources by the form. (It's worth noting that the two that do work do not actually have either datasource selected; they are listed as none. But they are available). So I selected DataSource3 just to see if that would work, assuming that would now resolve it given they were inaccessible before, but sadly on execution exactly the same problem occured. And if I try using frmDisplayGrid3.DBGrid3.DataSource.DataSet.Open; that line errors during running suggesting the dataset can't be opened or is invalid. So somewhere I think the DataSource is not getting linked or is inaccessible, but I keep looking at the other two and comparing it against the setting for DataSource3 and all the settings are exactly the same, just changed by name or by SQLQuery link. This is driving me utterly insane. I can't understand how I can have a main form, with 2 additional forms all containing a DBGrid, and have corresponding TSQLQueries and Datasources, all created at application launch in the same way, and yet this third form and its embedded DBGrid seems somehow inaccessible. I just cannot see what I have done wrong. ---------------------------------------------------------------------- egsuh · 2020-08-24 12:10 Your explanations are a little bit confusing. Quotefor that particular component (the DBGrid3) the datasource is already blank (none). It is the SQLQueries that have the datasources attached to them. Datasource property is necessary for DB controls, e.g. DBGrid in this case. It must be set as  DBGrid3.datasource = datasource3, and datasource3.DataSet = SQLQuery3. 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  frmDisplayGrid3.DBGrid3.Options := frmDisplayGrid3.DBGrid3.Options + [dgAutoSizeColumns]; If you have defined this statement within OnCreate event handler of TfrmDisplayGrid3, this should raise exception because frmDisplayGrid3 is not instantiated yet. Or you are running the above sentece within the TMainForm, it will also raise SEGSEGV 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 DBGrid3.Options := DBGrid3.Options + [dgAutoSizeColumns]; "Identifier not found here" means DBGrid3 may be defined in other unit, and the unit is not included in the uses clause.  You have four forms, so please explain which form contains which components. ---------------------------------------------------------------------- wp · 2020-08-24 12:16 Without seeing your code it is not possible to solve this. Make a copy of the project folder. Then remove everything from the copied project which is not needed to reproduce the error. Test whether the modified project still compiles and shows the error. Then pack the .pas, .lfm, .lpi, lpr and sqlite3 files into a common zip which you can upload here. If you do not want to show the project in public upload it to some cloud server and send me the link by PM. I'll try to have a look and see what's wrong. But please: Give detailed instructions what to click to trigger the error - I am not willing to learn how to use a foreign program. ---------------------------------------------------------------------- wp · 2020-08-24 14:27 After seeing the code sent by a PM, I saw that the {$R *.lfm} was missing from the unit containing frmDisplayGrid3. As a consequence the DBGrid on this form was nil at runtime. Didn't know about the importance of these few characters... ---------------------------------------------------------------------- Gizmo · 2020-08-24 15:28 WP is the man, the legend, and my hero of the hour!! As he reports, I sent him the project and he quickly identified the missing line below "implementation". I too had never appreciated the importance of this line! So I now have 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  frmDisplayGrid3: TfrmDisplayGrid3; implementation {$R *.lfm}  // this was added by WP initialization                        and it works!! All the hours spent struggling with that....I'm an idiot. Thank you so much WP. I really do appreciate your generous contribution of time and effort.