Fix access violation when using ASCIIencoding, by turning it from a SingleTon into a new instance each time we call GetEncodingByName. Probably introduces a memory leak. The encoding object is freed when using in a TStringStream context which is freed after usage. See exportgrid unit.

This commit is contained in:
Ansgar Becker
2012-11-17 08:48:21 +00:00
parent 5958d7102b
commit b6a18114f4
2 changed files with 6 additions and 6 deletions

View File

@ -327,7 +327,6 @@ type
var
AppSettings: TAppSettings;
MutexHandle: THandle = 0;
ASCIIEncoding: TEncoding;
implementation
@ -2449,7 +2448,7 @@ begin
Result := '';
if Encoding = TEncoding.Default then
Result := 'Windows-'+IntToStr(GetACP)
else if Encoding = ASCIIEncoding then
else if Encoding.CodePage = 437 then
Result := 'ascii'
else if Encoding = TEncoding.Unicode then
Result := 'utf-16le'

View File

@ -1580,7 +1580,6 @@ begin
FTreeRefreshInProgress := False;
FileEncodings := Explode(',', 'Auto detect (may fail),ANSI,ASCII,Unicode,Unicode Big Endian,UTF-8,UTF-7');
ASCIIEncoding := TEncoding.GetEncoding(437);
end;
@ -10118,11 +10117,13 @@ end;
function TMainForm.GetEncodingByName(Name: String): TEncoding;
var
Enc: TEncoding;
begin
Result := nil;
case FileEncodings.IndexOf(Name) of
1: Result := TEncoding.Default;
2: Result := ASCIIEncoding;
2: Result := TEncoding.GetEncoding(437);
3: Result := TEncoding.Unicode;
4: Result := TEncoding.BigEndianUnicode;
5: Result := TEncoding.UTF8;
@ -10136,7 +10137,7 @@ var
idx: Integer;
begin
if Encoding = TEncoding.Default then idx := 1
else if Encoding = ASCIIEncoding then idx := 2
else if Encoding.CodePage = 437 then idx := 2
else if Encoding = TEncoding.Unicode then idx := 3
else if Encoding = TEncoding.BigEndianUnicode then idx := 4
else if Encoding = TEncoding.UTF8 then idx := 5
@ -10201,7 +10202,7 @@ begin
54936: Result := 'gb18030';
65001: Result := 'utf8';
end;
end else if Encoding = ASCIIEncoding then
end else if Encoding.CodePage = 437 then
Result := 'ascii'
else if Encoding = TEncoding.Unicode then
Result := 'utf16le'