Delphi Access Violation in TLanguages ​​Utility

For some reason, trying to create the TLanguages ​​object provided by the SysUtils header using Singleton or calling the constructor directly causes problems in the wild when some users report this error (X changes):

Access violation at address X. Write of address X (at address X)

... when the following seemingly innocent line of code is executed:

TLanguages.Create;

To clarify, this is not context related. I can put this line anywhere I like (as the only line of code in an empty program, for example), but the problem remains.

The weird part is that this class is part of the standard Delphi headers, which should not fail (right?).

constructor TLanguages.Create;
type
  TCallbackThunk = packed record
    POPEDX: Byte;
    MOVEAX: Byte;
    SelfPtr: Pointer;
    PUSHEAX: Byte;
    PUSHEDX: Byte;
    JMP: Byte;
    JmpOffset: Integer;
  end;
var
  Callback: TCallbackThunk;
begin
  inherited Create;
  Callback.POPEDX := $5A;
  Callback.MOVEAX := $B8;
  Callback.SelfPtr := Self;
  Callback.PUSHEAX := $50;
  Callback.PUSHEDX := $52;
  Callback.JMP     := $E9;
  Callback.JmpOffset := Integer(@TLanguages.LocalesCallback) - Integer(@Callback.JMP) - 5;
  EnumSystemLocales(TFNLocaleEnumProc(@Callback), LCID_SUPPORTED);
end;

- EnumSystemLocales, , -, , TLanguages.LocalesCallback EnumSystemLocales .

Intel x86, :

pop  edx
mov  eax Self
push eax
push edx
jmp  JmpOffset

- , , , , ?

+5
1

, Delphi, DEP, . , RTL , DEP.

: http://codecentral.embarcadero.com/Item/23411

CodeCentral Delphi 5, , Delphi 7. SysUtils.Languages. , , TLanguages.Create , .

+4

All Articles