* * *

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

engkin

  • Hero Member
  • *****
  • Posts: 2101
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 »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus