program Project1;
uses
Vcl.Forms,
Unit1
in '
Unit1.pas'
{Form1},
Unit2
in '
Unit2.pas'
{DataModule1: TDataModule};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
// Datenmodule vor dem Hauptformular erzeugen
Application.CreateForm(TDataModule1, DataModule1);
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
//**************************************************************************************
unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, Data.DB;
type
TForm1 =
class(TForm)
procedure FormActivate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
private
{ Private-Deklarationen }
procedure FormularUpdate(DataSet: TDataSet);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Unit2;
procedure TForm1.FormActivate(Sender: TObject);
begin
DataModule1.FormularUpdateEvent := FormularUpdate;
end;
procedure TForm1.FormDeactivate(Sender: TObject);
begin
DataModule1.FormularUpdateEvent :=
nil;
end;
procedure TForm1.FormularUpdate(DataSet: TDataSet);
begin
// Hier das Formular updaten
end;
end.
//**************************************************************************************
unit Unit2;
interface
uses
System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, Data.DB,
FireDAC.Comp.DataSet, FireDAC.Comp.Client;
type
TFormularUpdateEvent =
procedure(DataSet: TDataSet)
of object;
TDataModule1 =
class(TDataModule)
FDQuery1: TFDQuery;
procedure FDQuery1AfterScroll(DataSet: TDataSet);
procedure DataModuleCreate(Sender: TObject);
private
{ Private-Deklarationen }
FFormularUpdateEvent: TFormularUpdateEvent;
public
{ Public-Deklarationen }
property FormularUpdateEvent: TFormularUpdateEvent
read FFormularUpdateEvent
write FFormularUpdateEvent;
end;
var
DataModule1: TDataModule1;
implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}
procedure TDataModule1.DataModuleCreate(Sender: TObject);
begin
FormularUpdateEvent :=
nil;
end;
procedure TDataModule1.FDQuery1AfterScroll(DataSet: TDataSet);
begin
// Erledige hier alles, das mit dem direkten Zugriff auf
// Komponenten im Datenmodul zusammen hängt
// ...
// Formular aktualisieren:
if Assigned(FormularUpdateEvent)
then FormularUpdateEvent(DataSet);
end;
end.