Inactive DataSource property of DBxxxx components from Object Inspector lazarus / 31-LCL ---------------------------------------------------------------------- Bono · 2025-08-31 15:50 Hello from Japan. To dear all developer. I apologize for my poor English. I discovered inactive DataSource / DataField / ListSource / KeyField / ListField properties of DBxxxx components by set via the Object Inspector. My use case involves placing db component to common unit (Form unit). The compiler doesn't seem to recognize references to `[UnitName].[TDataSet]`. As a temporary workaround, I'm setting the DataSource in code. thanks. ---------------------------------------------------------------------- jamie · 2025-08-31 16:29 Only what you place on the TFORM1 using the object inspector will the system see the DataSource connected to the other components.  Normally these are at the top of TFORM1 inside the class. If you are manually placing these items elsewhere, you need to connect them at run-time.  If this isn't the problem, then please post a simple short example of a failure via a Project.zip using the publish project in the "Project" menu. Jamie ---------------------------------------------------------------------- Bono · 2025-08-31 17:17 Hi, thanks jamie. Since it's a bit tricky to keep this project simple, I'll just paste the GitHub page URL here. https://github.com/BonoJovi/KakeiBon.git As you suggest, placing DB components like TDataSource on the top form might be preferable. However, due to the large number of components, I placed them on a separate form. Even if placed on the top form, accessing that top form's DB components from subsequent forms would still involve referencing an external form. Therefore, I believe the same issue would persist regardless. ---------------------------------------------------------------------- jamie · 2025-08-31 17:30 Ok, that is a large project for me to look at. Have you tried using a Data Module instead of a form?  With that you can place many objects on there to be used all over the place, and it seems the Object Inspector also allows you to link them. Jamie ---------------------------------------------------------------------- CharlyTango · 2025-08-31 18:17 Data modules are designed precisely for this purpose. Data modules can be thought of as TForms without visuals or as carrier elements for invisible components. Especially in database applications, things can quickly become confusing if you have too many components on a TForm. My structure: I have a data module that contains ONLY the database connection (e.g. SQL connection, transaction, monitoring). I have also made this data module a singleton object so that it is always accessible throughout the programme. I use data-sensitive controls on TForm and if there are only 2 or 3 queries and dataset components, I place them on the form. If there are more, the TForm gets its own data module. Then everything becomes quite clear. When the data module or TForm is opened, the connection is assigned to the queries. I also use data modules to structure other components, e.g. image lists. ---------------------------------------------------------------------- Bono · 2025-08-31 21:35 Hi, Jamie Sorry, not yet push the new state project to GitHub. Now create a small sample project. But my small sample project is SYSSEGV. Debugging now, wait a moment please. ---------------------------------------------------------------------- jamie · 2025-08-31 21:41 Put it here, the simple project. use the PROJECT: PUBLISH PROJECT. That will make a small zip file of only the needed items, then you can attach it here. ---------------------------------------------------------------------- Bono · 2025-08-31 21:49 Hi, CharlyTango. Thanks post. You think so me too. Too much information—like the number of components on a form—not only reduces development efficiency but also becomes a breeding ground for bugs. I think it's best to narrow down the information visible at once as much as possible. No matter how excellent Lazarus's structuring is, if the human-made parts aren't structured, its effectiveness is halved. Besides, Lazarus + Free Pascal is still under development, and I don't think it's reached the point where structuring is automated without developers having to worry much about it. And let's not forget, the IDE and components themselves still have plenty of bugs.I saw it mentioned somewhere recently: Lazarus developers say that since its history is considerably shorter compared to Delphi, it's inevitable that some bugs remain. ---------------------------------------------------------------------- Bono · 2025-08-31 21:54 Ok, Jamie  Once I've fixed the bugs in the sample program I'm currently working on, I'll zip it up and attach it here. ---------------------------------------------------------------------- Bono · 2025-09-01 00:29 Hi, Jamie Sorry to keep you waiting. I've finished a small sample project and will upload it now. Please check the section marked “Check Here Please !!” in UManageUser.pas (inside the FormShow event handler). ---------------------------------------------------------------------- egsuh · 2025-09-01 04:50 I haven't looked into your example, but `[UnitName].[TDataSet]` is not correct form. 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 unit DataModule; type     TDataModule1 = class(TDataModule)         dataset: TBufDataset;            datasource1: TDataSource;         DBGrid1 : TDBGrid;          .....     end;  var    DataModule1: TDataModule;  implementation end; And in other units, 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 unit Mainform;uses    DataModule;    ............... begin      DataModule1.DataSet := ....;    // should reference a variable, not type themselves.  end; ---------------------------------------------------------------------- Bono · 2025-09-01 06:29 Hi, egsuh. Oh. I misspell... I see. Depending on the scale of the code, the way you suggested splitting up the objects seems like it could be effective. Below is an example of my current code. I'm not sure if this is the best approach, but since the form calls span multiple layers, I wanted to separate the TDBGrid, TDBNavigator, input fields, and DB components to make them more generic. While there are other ways to separate DB components in object design, I think this approach is fine for now. Common module. 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 unit UCommonDB type    TFrmCommonDB = class (TForm)        Connection1: TSQLite3Connection;        DataSource1: TDataSource;        Transaction1: TSQLTransaction;        Query1: TSQLQuery;                  Connection2: TSQLite3Connection;        DataSource2: TDataSource;        Transaction2: TSQLTransaction;        Query2: TSQLQuery;                    Connection3: TSQLite3Connection;        DataSource3: TDataSource;        Transaction3: TSQLTransaction;      Query3: TSQLQuery;                           ・                        ・                          ・    end;  Other main form. 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 unit UMainForm; ・・・・・ type    TMainForm = class(TForm)        DBGrid1: TDBGrid;         ・・・・    end; var・・・・ implementationuses    UCommDB; constructor TMainForm..Create;begin    CommDB := TFrmCommonDB.Create;end; procedure TMainForm.FormShow(Sender: TObject);begin    with CommDB do begin        with Query1 do begin          SQL.Text := 'SELECT * FROM TBL_USERS';            Open;        end;        DBGrid1.DataSource := DataSource1;  // ←Here    end;end;  And other sub form. 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 unit SubForm; ・・・・・ type    TSubForm = class(TForm)        DBGrid2: TDBGrid;         ・・・・    end; var・・・・ implementationuses    MainForm; procedure TSubForm.FormShow(Sender: TObject);begin    with MainForm do begin        with CommDB do begin            with Query2 do begin                SQL.Text := 'SELECT * FROM TBL_SHOP';              Open;            end;            DBGrid2.DataSource := DataSource2;  // ←Here        end;    end;end; ---------------------------------------------------------------------- CharlyTango · 2025-09-01 06:52 It Seems to me that you didn't understood a concept. You only need ONE set of SQLite-Connection/Transaction for the complete application. There is no need to repeat that for each and every SQLQuery. Just Assign the connection and you ar on the go. The connection is opened once and is open until the application ends. I attached a sample project which shows that. The main datamodule is dmmain.pas What could be interesting for you is the form fcustomer. Just one single SQL Statement and it works. Lazarus maybe has some bugs, but as an old delphi (since Delphi2) veteran i can say that it is more stable than you might think. Maybe there is an advantage to collect all SQL statements in one if there is a possibility to change them often. I prefer to put things together in a form which belong together. You put your datamodule at the first place of the autocreate-forms list. remove it and create it yourself at a defined position in your starting routine (shown in example code) Certainly you can put each and every data field in a seperate Label or nidependent edit control. That results in quite a huge typing amount which does not seem to me that it is necessary. The only exception for me ist that you urgently need the possibilities of controlong the process. Otherwise I'd use database enabled controls. You also can have more control over the process reading writing etc data controlling the used events. but that could be another thread. In such an application ---------------------------------------------------------------------- Bono · 2025-09-01 07:33 Hi, CharlyTango Admittedly, I can't deny my lack of understanding. While I used Delphi in its early days, circumstances led me away from programming for nearly 30 years. I only recently resumed programming with Lazarus last year. However, thanks to your excellent sample project, I've gained a better understanding of how to use the DB component. Thank you. With this knowledge, I think I can improve the database architecture of the household budget app I'm currently developing. ---------------------------------------------------------------------- egsuh · 2025-09-04 03:31 Does your code cause compiler error or runtime error, or simply show no data? ---------------------------------------------------------------------- Bono · 2025-09-04 06:37 Hi, egsuh It's working here. By the way, what OS are you using? If you're on Windows, it might be the SQLite3 DLL; if you're on Linux, SQLite3 might not be installed. ---------------------------------------------------------------------- Bono · 2025-09-04 06:40 If you need it, let me know and I'll re-upload Sample.zip. ---------------------------------------------------------------------- egsuh · 2025-09-04 07:00 @Bono I'm fine. I just cannot find the problem in your codes. I have no problem in running my DB-projcts^^