Ok, had to play around for a while to make a reduced version of the program not to post a huge listing. And in the proces I discovered how to get it to work....
I gave the frame its own constructor to be able to pass the ID of the record to be displayed to the frame.....and from the constructor I call the function to fill the fields in the frame. Apparently that is too soon...
If I add a button to the frame and load data upon pressing the button it does get all data from the database.
But ok, some source to show what I did (wrong):
=======
unit frame;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, sqldb, FileUtil, Forms, Controls, StdCtrls;
type
{ TMyFrame }
TMyFrame = class(TFrame)
cbFrameLoad: TButton;
cbFrameData: TComboBox;
SQLQuery: TSQLQuery;
procedure cbFrameLoadClick(Sender: TObject);
private
procedure FillData ;
public
constructor Create(AOwner : TComponent) ; override ;
end;
implementation
{$R *.lfm}
{ TMyFrame }
procedure TMyFrame.FillData ;
begin
SQLQuery.SQL.Text := 'SELECT * FROM Countries' ;
SQLQuery.Open ;
while not SQLQuery.EOF do
begin
cbFrameData.Items.Add(SQLQuery.FieldByName('Country_Name').AsString) ;
SQLQuery.Next ;
end;
SQLQuery.Close ;
end;
constructor TMyFrame.Create(AOwner : TComponent) ;
begin
inherited Create(AOwner) ;
// this doesn't work
FillData ;
end;
procedure TMyFrame.cbFrameLoadClick(Sender: TObject);
begin
// this DOES work
FillData ;
end;
end.
==========
unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, sqldb, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, frame;
type
{ TForm1 }
TForm1 = class(TForm)
MyFrame1: TMyFrame;
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
end.
=========
unit data;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, db, sqldb, sqlite3conn, FileUtil;
type
{ TMyDataModule }
TMyDataModule = class(TDataModule)
DataSource: TDataSource;
SQLite3Connection: TSQLite3Connection;
SQLTransaction: TSQLTransaction;
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
MyDataModule: TMyDataModule;
implementation
{$R *.lfm}
{ TMyDataModule }
procedure TMyDataModule.DataModuleCreate(Sender: TObject);
begin
SQLite3Connection.DatabaseName := ExtractFilePath(ParamStr(0)) + 'data\cupping_data.sl3' ;
SQLite3Connection.Connected := True ;
end;
procedure TMyDataModule.DataModuleDestroy(Sender: TObject);
begin
SQLite3Connection.Connected := False ;
end;
end.