[Pas2js] how to access variables between various procedures
Michael Van Canneyt
michael at freepascal.org
Tue Sep 15 11:52:44 CEST 2020
On Tue, 15 Sep 2020, Mgr. Janusz Chmiel wrote:
> I have even tried to type The following line.
> tex2.Text:='You have answered'+TQuestion.a +'Good answer/s from 36 possible
> answers';
> But I have got The following error.
> project1.lpr(65,42) Error: Instance member "a" inaccessible here
> So really, some magic block variable access from other procedures.
No, you do not seem to understand how classes work.
The variable a is part of a TQuestion class. You create several instances of
the TQuestion class. TQuestion.A does not exist because a is part of an
instance.
So, You need to save the instances you create in an array.
var
MyQuestion : Array[1..36] of TQuestion;
For I:=1 to 36 do
MyQuestion[i]:=TQuestion.Create(blah);
Then you can do for example
if MyQuestion[13].A=1 then
and so on.
Michael.
More information about the Pas2js
mailing list