[fpc-devel] Get system ANSI code page

Denis Kozlov dezlov at gmail.com
Sat Jan 5 00:10:08 CET 2019


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



More information about the fpc-devel mailing list