I'm a beginner to delphi and I'm stuck with a finalization error e2155. I'm using RAD 10 and try to run my programm on mobile devices. It works fine on my windows machine, but when i change to Android or IOS it gives me that finalization error.
The Code:
type
TRaumparameter = record
ID : string;
Länge: string;
Breite: string;
Höhe: string;
Fläche: string;
Raumvolumen: string;
Wände: string;
Decke: string;
Boden: string;
Baujahr: string;
Heizlast: string;
end;
var Aufstellraum: Traumparameter;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
{$R *.iPad.fmx IOS}
procedure TForm1.speichernClick(Sender: TObject);
var F: File of Traumparameter;
begin
Aufstellraum.Länge:=form2.Länge.Text;
Aufstellraum.Breite:=form2.Breite.Text;
Aufstellraum.Höhe:=form2.Höhe.Text;
Aufstellraum.Fläche:=form2.Fläche.Text;
Aufstellraum.Raumvolumen:=form2.ErgebnisRaumVol.Text;
Aufstellraum.Wände:=form2.Wände.Text;
Aufstellraum.Decke:=form2.Decke.Text;
Aufstellraum.Baujahr:=form2.Baujahr.Selected.Text;
Aufstellraum.Heizlast:=form2.Heizlast.Text;
try
AssignFile(F,'D:\test\1.txt');
ReWrite(F);
Write(F,Aufstellraum);
finally
CloseFile(F);
end;
end;
I already tried to limit the length of the strings with [] but then it tells me: ';' expected but '[' found. Hope I can get some answers because i spent quiet some time without any success. Thanks in advance!!
When you are trying to write a file of record containing String
types, it is not allowed by the compiler:
E2155 Type '%s' needs finalization - not allowed in file type (Delphi)
String is one of those data types which need finalization, and as such they cannot be stored in a File type
It is no point writing a record with a String
field using a binary file type anyway, since you will be writing the address instead of the text (string is a reference type).
When you are declaring strings with a dedicated length, they are called ShortString (value type). ShortString
is not supported by the mobile compilers though.
I suggest you use other techniques to store text. See how to convert a record to text with json
for example.