This confusing error appeared in my program, and it took me precious time to discover what was happening.
Finally, I discovered the failure.
There are two facets to this error. First, why doesn't the error return an explanation or a clue about where the problem is?
And second, what causes the error?
The cause of the error is probably a missing function of the pas2js compiler.
In the code next, showing an example of the error, I have a public property of type TSetup, a class. The field of this property is FSetup: TSetup. And the property declaration is consciously a write-only property. The intention is that other classes can modify this value but don't read it. Internally inside the same class, his values can be read through the FSetup field.
private
FSetup :TSetup;
public
{ This is a write-only property }
property Setup :TSetup {read FSetup} write FSetup;
end;
Is easy. And is functionality well know in Delphi.
And, of course, internally in the class, I can assign the value to the property through the property name, Setup, or directly to the Field, FSetup.
procedure TForm5.WebButton1Click(Sender: TObject);
begin
Setup.AuthToken := 'Hola!';
end;
Or really, no!!!!!!
I get this insidious error if I use the property name Setup.
Error during compilation
[Fatal Error] Error during compilation.
Without any clue about what is happening!!
Next is the complete code for testing the problem.
in the event handler of the TWebButton, if you say "Setup.AuthToken := 'Hola!';" you are not going to be able to compile, but if you say "FSetup.AuthToken := 'Hola!';" you are not going to have any problem.
unit Unit5;
interface
uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls;
type
TSetup = class
private
FAuthToken :string;
public
property AuthToken :string read FAuthToken write FAuthtoken;
end;
TForm5 = class(TWebForm)
WebButton1: TWebButton;
procedure WebButton1Click(Sender: TObject);
procedure WebFormCreate(Sender: TObject);
private
FSetup :TSetup;
public
{ This is a write-only property }
property Setup :TSetup {read FSetup} write FSetup;
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
procedure TForm5.WebFormCreate(Sender: TObject);
begin
FSetup := TSetup.Create;
end;
procedure TForm5.WebButton1Click(Sender: TObject);
begin
Setup.AuthToken := 'Hola!';
end;
end.