TDataset(from DataModule) event from main form unsuccess (SQLite) lazarus / 16-Databases ---------------------------------------------------------------------- totya · 2018-03-06 20:26 Hi! 1. Create new application 2. Create new DataModule 3. Drop one Sqlite3Dataset to DataModule 4. Drop one DataSource to DataModule 5. DataSource.dataset:= Sqlite3Dataset 6. Drop on DBGrid to form1 7. DBGrid.DataSource:=DataModule.DataSource Now, I want to access the DataModule/Dataset/AfterOpen event from the Form1, so: 8. Click on the DBGrid events Datasource Dataset AfterOpen event 9. Fill this event empty: // After run, I get exception: Invalid value for property. What's wrong? Thank you. Lazarus 1.6.4 (64 bit) ---------------------------------------------------------------------- taazz · 2018-03-06 20:57 I'm guessing the creation order. Form1 can not find and link with the controls in datamodule if the datamodule is not created before the form1 and datamodule can not find and link with the event in form1 during creation before the form1 is created. That is a paradox and can not be resolved automatically you need assign the event manually after creation. ---------------------------------------------------------------------- totya · 2018-03-06 21:14 Hi! Thank you taazz! IIRC under Delphi it's working in similar situation, but possible my memory is wrong. So, how can I assign manually this event after creation? Thanks! ---------------------------------------------------------------------- taazz · 2018-03-06 21:27 you make sure that the datamodule is created before form1 and you write a OnCreate event in form with the code below. 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  DataModule1.Sqlite3Dataset1.AfterOpen = @Sqlite3Dataset1AfterOpen;end; ---------------------------------------------------------------------- totya · 2018-03-06 21:36 Thank you! Form creation order is changed as you suggest. But then this code: 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 Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, DBGrids, db; type   { TForm1 }   TForm1 = class(TForm)    DBGrid1: TDBGrid;    procedure FormCreate(Sender: TObject);  private    procedure Sqlite3Dataset1AfterOpen(DataSet: TDataSet);  end; var  Form1: TForm1; implementation uses Unit2; {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  DataModule1.Sqlite3Dataset1.AfterOpen = @Sqlite3Dataset1AfterOpen;end; procedure TForm1.Sqlite3Dataset1AfterOpen(DataSet: TDataSet);begin end;  end.  ...cause compiler error: illegal expression ---------------------------------------------------------------------- taazz · 2018-03-07 05:46 Quote from: totya on March 06, 2018, 10:36:29 pm...cause compiler error: illegal expression No problems here find attached your example corrected, it compiles properly. ---------------------------------------------------------------------- totya · 2018-03-07 17:13 Thanks, compile OK, but I got exception when project started. Edit: But yes, I see my one error ":=" needed OMG. But your sample halted for me when I run it, see attached picture. Lazarus 1.6.4 x64 ---------------------------------------------------------------------- taazz · 2018-03-08 04:52 Quote from: totya on March 07, 2018, 06:13:04 pmThanks, compile OK, but I got exception when project started. Edit: But yes, I see my one error ":=" needed OMG. But your sample halted for me when I run it, see attached picture. Lazarus 1.6.4 x64 clear the after post event in the datamodule. ---------------------------------------------------------------------- totya · 2018-03-08 17:46 Thank you taazz!