Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2019-01

Get system ANSI code page

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Denis Kozlov

Hi,

I was looking for a cross-platform method for retrieving system ANSI code page. I have identified two methods, using direct API calls (1) and indirect using the WideStringManager (2). FPC's
SetPascalWideStringManager() routine provided a good reference.

Any ideas about which is best? Perhaps it is a useful generic routine to have in RTL?

function GetSystemCodePage1: TSystemCodePage;
begin
   {$IFDEF WINDOWS}
     Result := Windows.GetACP;
   {$ELSE WINDOWS}
     {$IFDEF UNIX}
       Result:= UnixCP.GetSystemCodepage;
     {$ELSE UNIX}
       Result := DefaultSystemCodePage;
     {$ENDIF UNIX}
   {$ENDIF WINDOWS}
end;
function GetSystemCodePage2: TSystemCodePage;
begin
   if Assigned(WideStringManager.GetStandardCodePageProc) then
     Result := WideStringManager.GetStandardCodePageProc(scpAnsi)
   else
     Result := DefaultSystemCodePage;
end;

Thanks,
Denis

Reply by email