Hi, I just want your ideas on my approach. I wrote an application which uses several forms, and one datamodule. Most of the forms have to access different datasets in the datamodule.
I did several trial and errors, and finally settled on following approach.
1) in each TForm definition module, I add a TDataSet variable under public section.
2) And assign TDataSet object in the datamodule to the variable within "program" unit, before Application.Run, like following.
unit fselectproject_5;
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrlsl
type
TfProjectChoice = class(TForm)
bbrnLogin: TBitBtn;
bbtnCancelLogin: TBitBtn;
private
procedure RefreshProjectList;
public
uid: string;
DataSet: TDataSet; // <== this is TDataSet variable.
end;
var
fProjectChoice: TfProjectChoice;
....
//---------------
program aq01editor;
{$mode delphi}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, fselectproject_5, daq_fb_5, ... ;
{$R *.res}
begin
RequireDerivedFormResource:=True;
Application.Initialize;
Application.CreateForm(TAQFB4, AQFB4);
Application.CreateForm(TfProjectChoice, fProjectChoice);
Application.CreateForm(TfQEdit, fQEdit);
Application.CreateForm(TfoNewQDef, foNewQDef);
fProjectChoice.DataSet := AQFB4.dsProjects; // <== Assign the dataset here.
Application.Run;
end.
In this way, I can use the forms and datamodule almost independently. Up to now this works fine, without any problem. But not sure there could be any problem in this approach.
Want your advice.