unit CpFuncs;
interface
uses windows, classes;
type
_cpinfoex =
record
MaxCharSize: UINT;
{ max length (bytes) of a char }
DefaultChar:
array[0..MAX_DEFAULTCHAR - 1]
of Byte;
{ default character }
LeadByte:
array[0..MAX_LEADBYTES - 1]
of Byte;
{ lead byte ranges }
UnicodeDefaultChar : WCHAR;
CodePage : UINT;
CodePageName :
array[0..MAX_PATH]
of char;
end;
TCPInfoEx = _cpinfoex;
{$EXTERNALSYM CPINFOEX}
CPINFOEX = _cpinfoex;
{$EXTERNALSYM GetCPInfoEx}
procedure GetCodePageList(AList : TStrings);
function GetCPInfoEx(CodePage: UINT; dwFlags : DWORD;
var lpCPInfoEx: TCPInfoEx): BOOL;
stdcall;
function GetCPInfoEx;
external kernel32
name '
GetCPInfoExA';
implementation
uses Sysutils;
var CodePageList : TStringList;
function CpEnumProc(CodePage : PChar) : Cardinal ;
stdcall;
var
CpInfoEx : TCPInfoEx;
Cp : cardinal;
begin
Cp := StrToIntDef(CodePage,0);
if IsValidCodePage(Cp)
then
begin
GetCPInfoEx(Cp, 0, CpInfoEx);
CodePageList.AddObject(Format('
%s', [CpInfoEx.CodePageName]), TObject(Cp));
end;
Result := 1;
end;
procedure GetCodePageList(AList : TStrings);
begin
CodePageList.Clear;
AList.Clear;
EnumSystemCodePages(@CpEnumProc, CP_SUPPORTED);
AList.Assign(CodePageList);
end;
initialization
CodePageList := TStringList.Create;
finalization
CodePageList.Free;
end.