MJ-79
MJ-79

Reputation: 133

Deactivate Huge Strings in Delphi 2010

I'm new in Delphi and I was migrating a very old Delphi project to Embarcadero RAD Studio 2010. I found a problem using strings. Here is the code:

ProgramaResultadosType = record
    Version: string;
    TituloPrincipal   : string;
    BloquesResultados : VectorBloquesResultadosType;
end;

FileOfProgramaResultadosType  = file of ProgramaResultadosType;

And the error...

"E2155 Type '%s' needs finalization - not allowed in file type"

I know it's a well-known error for many delphi developers when you don't specify the string size.

Basically I would like to deactivate Huge strings directive like older versions of RAD Studio, but I can't find out in the 2010 version.

Upvotes: 5

Views: 538

Answers (1)

Arnaud Bouchez
Arnaud Bouchez

Reputation: 43033

Just use instead:

ProgramaResultadosType = record
    Version: shortstring;
    TituloPrincipal   : shortstring;
    BloquesResultados : VectorBloquesResultadosType;
end;

But be aware that:

  • Almost every call to a RTL function will first make an invisible conversion to the new string type: you should better use another explicit string variable just after having read the shortstring content;
  • In newer version of Delphi (starting with Delphi 2009), string is an Unicode string: so you may lose some data when writing into a shortstring (which is an Ansi string) from an UnicodeString;
  • Perhaps adding ProgramaResultadosType = packed record could be necessary if your application is very very old (default alignment changed around Delphi 4, AFAIR).

So you may have to:

  • Read the existing content using structures like the above;
  • Write using a new paradigm, Unicode ready (e.g. an embedded DB like Midas, SQLite3 or any other).

Worth reading when converting an existing application to newer Unicode version of Delphi:

Upvotes: 10

Related Questions