Recent

Author Topic: How to assign nil to all TEncoding.FStandardEncodings?  (Read 1690 times)

engkin

  • Hero Member
  • *****
  • Posts: 3112
How to assign nil to all TEncoding.FStandardEncodings?
« on: April 23, 2018, 08:36:09 pm »
Unit SysUtils has a singleton class TEncoding. When changing DefaultSystemCodePage, like in Lazarus under Windows, TEncoding.Default.EncodingName does not get updated.

In theory calling TEncoding.FreeEncodings should be enough except that it does not assign nil to TEncoding.FStandardEncodings:
Code: Pascal  [Select][+][-]
  1.   for E := Low(FStandardEncodings) to High(FStandardEncodings) do
  2.     FStandardEncodings[E].Free;

The only way I found to get over this issue is to create a descendant class like TMBCSEncoding to reach to the strict private constructor:
Code: Pascal  [Select][+][-]
  1.   TEncoding = class
  2.   strict private
  3. ...
  4.     class constructor Create;
  5. ...
  6. class constructor TEncoding.Create;
  7. var
  8.   E: TStandardEncoding;
  9. begin
  10.   for E := Low(FStandardEncodings) to High(FStandardEncodings) do
  11.     FStandardEncodings[E] := nil;
  12. end;

Is that a bug or intended design?

Edit:
Bug reported: 33681 and fixed!
« Last Edit: May 05, 2018, 01:32:16 am by engkin »

 

TinyPortal © 2005-2018