[Pas2js] Variable in .LPR: How to make global through entire application?
warleyalex
warleyalex at yahoo.com.br
Thu Nov 8 13:07:32 CET 2018
I want to declare a variable in the .LPR file so that it can be used by all
the units in the project.
If I declare a variable in the .LPR file , it's scope doesn't seem to extend
to any of the .pas files comprising the project. I don't want to have to put
this global vairable in the main form and have every single .pas file in the
project have to use the main .pas file.
e.g. I want do access the variable "Application" from the .LPR at the unit
Unit1.pas;
I can access such variable using ASM section:
asm
console.log(pas['program'].Application);
end;
Is there another way around, some keyword in pas I am missing in addition to
declaring it?
-------------------------------
program project1;
{$mode objfpc}
uses
Classes, SysUtils, JS, Web, JComponents,
uForm1, uForm2, uForm3, uForm4;
type
{ TApplication }
TApplication = class(TCustomApplication)
private
{ private declarations }
protected
procedure ApplicationStarting; override;
end;
{ TApplication }
procedure TApplication.ApplicationStarting;
begin
inherited ApplicationStarting;
{ Register Auto Create Forms }
CreateForm('Form1', TForm1);
CreateForm('Form2', TForm2);
CreateForm('Form3', TForm3);
end;
var
Application: TCustomApplication;
begin
try
Application := TApplication.Create;
Application.RunApp;
except
on e: Exception do
console.log(e.Message);
end;
end.
--------------------------------
--
Sent from: http://pas2js.38893.n8.nabble.com/
More information about the Pas2js
mailing list