[Pas2js] how to access variables between various procedures
Mgr. Janusz Chmiel
janusz.chmiel at volny.cz
Tue Sep 15 09:38:58 CEST 2020
Here is The code. I have tried to replace windowalert command by display
info as text since GOogle chrome rendering engine has some internal issues
and when I press OK on window alert some editable boxes refuse to receieve
characters. I will try to add table on future which will contain correctly
answered pairs of The words. But now, I must solve variable issue. Thank you
for yours patience to my pleas. I can learn very much about object Pascal
thanks to yours advices.
program project1;
{$mode objfpc}
uses
browserapp, JS, Classes, SysUtils, Web, webwidget, htmlwidgets;
type
TMyApplication
=class(TBrowserApplication)
procedure doRun; override;
end;
{ TQuestion }
TQuestion
=
class
l: TLabelWidget;
ti:TTextInputWidget;
a: integer;
Question, Answer: String;
constructor Create( _ba: TBrowserApplication; _wp: TWebPage; _Question,
_Answer: String);
procedure tiInput( _Sender : TObject; _Event : TJSEvent);
end;
{ TQuestion }
constructor TQuestion.Create( _ba: TBrowserApplication; _wp: TWebPage;
_Question, _Answer: String); begin
Question:= _Question;
Answer:=_Answer;
ti:=TTextInputWidget.Create(_ba);
l:=TLabelwidget.Create(_ba);
l.Text:=_Question;
l.LabelFor:= ti;
l .Parent:= _wp;
ti.Parent:= _wp;
ti.OnInput := @tiInput;
//ti.OnChange:= @tiInput;
l .Refresh;
ti.Refresh;
end;
procedure TQuestion.tiInput( _Sender: TObject; _Event: TJSEvent);
begin
if ti.value = Answer
then
a:=a+1;
end;
procedure TMyApplication.doRun;
var
wp: TWebPage;
tex: TTextWidget;
tex2: TTextWidget;
begin
wp:=TWebPage.Create(Self);
wp.Parent:=TViewPort.Create(Nil);
tex:=TTextWidget.Create(Self);
tex.Parent:=wp;
tex.Text:='Doplňte druhého do známé dvojice. Jakmile doplníte správné jméno,
aplikace Vás pochválí. V opačném případě aplikace nevypíše nic.';
tex.Refresh;
tex2:=TTextWidget.Create(Self);
tex2.Parent:=wp;
tex2.Text:='You have answered'+a +'Good answer/s from 36 possible answers';
tex2.Refresh;
TQuestion.Create(Self, wp,'Hamlet a', 'Ofélie');
TQuestion.Create(Self, wp,'Břetislav a', 'Jitka');
TQuestion.Create( Self, wp,'Radůz a','Mahulena');
TQuestion.Create( Self, wp,'Laurin a','Klement');
TQuestion.Create( Self, wp,'Kain a','Ábel');
TQuestion.Create( Self, wp,'Romeo a','Julie');
TQuestion.Create( Self, wp,'Othello a','Desdemona');
TQuestion.Create( Self, wp,'Přemysl a','Libuše');
TQuestion.Create( Self, wp,'Kleopatra a','Antonius');
TQuestion.Create( Self, wp,'Faust a','Markéta');
TQuestion.Create( Self, wp,'Tristan a','Izolda');
TQuestion.Create( Self, wp,'Adam a','Eva');
TQuestion.Create( Self, wp,'Cyrano a','Roxana');
TQuestion.Create( Self, wp,'David a','Goliáš');
TQuestion.Create( Self, wp,'Oldřich a','Božena');
TQuestion.Create( Self, wp,'Ruslan a','Ludmila');
TQuestion.Create( Self, wp,'Kolben a','Daněk');
TQuestion.Create( Self, wp,'Čert a','Káča');
TQuestion.Create( Self, wp,'Romulus a','Remus');
TQuestion.Create( Self, wp,'Hanzelka a','Zikmund');
TQuestion.Create( Self, wp,'Suchý a','Šlitr');
TQuestion.Create( Self, wp,'Šimek a','Grossman');
TQuestion.Create( Self, wp,'Laurel a','Hardy');
TQuestion.Create( Self, wp,'Voskovec a','Werich');
TQuestion.Create( Self, wp,'Křemílek a','Vochomůrka');
TQuestion.Create( Self, wp,'Maková panenka a','motýl Emanuel');
TQuestion.Create( Self, wp,'Bob a','Bobek');
TQuestion.Create( Self, wp,'Bolek a','Lolek');
TQuestion.Create( Self, wp,'Čuk a','Gek');
TQuestion.Create( Self, wp,'Jeníček a','Mařenka');
TQuestion.Create( Self, wp,'Spejbl a','Hurvínek');
TQuestion.Create( Self, wp,'Sultán a','Tyrl');
TQuestion.Create( Self, wp,'Orfeus a','Eurydika');
TQuestion.Create( Self, wp,'Ctirad a','Šárka');
TQuestion.Create( Self, wp,'Samson a','Dalila');
TQuestion.Create( Self, wp,'Cyril a','Metoděj');
wp.Refresh;
end;
var
Application : TMyApplication;
begin
Application:=TMyApplication.Create(nil);
Application.Initialize;
Application.Run;
end.
More information about the Pas2js
mailing list