unit MyUnit;
uses
[...],
Vcl.Forms,
WEBLib.Forms;
interface
type
TApplicationHelper = class
procedure HandleHashChange(Sender: TObject; AHash: string; var Handled: boolean);
procedure HandleError(Sender: TObject; AError: TApplicationError; var Handled: boolean);
end;
procedure AssignHelper;
implementation
procedure TApplicationHandlerHelper.HandleHashChange(Sender: TObject; AHash: string; var Handled: boolean);
begin
// do stuff
end;
procedure TApplicationHandlerHelper.HandleError(Sender: TObject; AError: TApplicationError; var Handled: boolean);
begin
// do stuff
end;
procedure AssignHelper;
var
h: TApplicationHelper;
app: TApplication;
begin
h := TApplicationHelper.Create;
app := Application;
app.OnHashChange := h.HandleHashChange;
app.OnError := h.HandleError;
end;
end.
Projekt.dpr
program ProjBoknWeb;
{$R *.dres}
uses
Vcl.Forms,
WEBLib.Forms,
FormLogin in 'Forms\FormLogin.pas';
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.AutoFormRoute := True;
MyUnit.AssignHelper;
if not Application.Route then
Application.CreateForm(TFormLogin, fLogin);
Application.Run;
end.
unit Navigation;
interface
uses
WEBLib.Forms;
type
TNavigationManager = class
procedure HandleHashChange(Sender: TObject; AHash: string; var Handled: boolean);
end;
var
NavigationManager: TNavigationManager;
implementation
{ TNavigationManager }
procedure TNavigationManager.HandleHashChange(Sender: TObject; AHash: string; var Handled: boolean);
begin
// Handle hash change here
end;
initialization
NavigationManager := TNavigationManager.Create;
end.
First create a unit with a class for handling hash changes.
The key part here was creating initializating the variable in the initialization block.
With this, the variable is created just by including the unit file in the uses block (which I did not know). Now one can simply assign Application.OnHashChange := NavigationManager.HandleHashChange in the dpr file (or anywhere with the right uses).