[fpc-pascal] Code page for the Windows event viewer

Abuy abbuyy at zoho.com
Wed Sep 15 15:08:50 CEST 2021


Instead of cyrillic characters there some garbage in Windows event 
viewer. Have tried AnsiString with Windows-1251 code page (type 
StringCP1251 = type AnsiString(1251)) but this does not work. What works 
is RawByteString variable with the following conversion to Windows-1251. 
Here is code:

{$MODE objfpc} {$ifdef mswindows}{$apptype console}{$endif}
{$R C:\lazarus\fpc\3.2.0\source\packages\fcl-base\src\win\fclel.res}
program Project1;

uses
   EventLog,
   sysutils;
type
   StringCP1251 = type AnsiString(1251);
var
   logger:teventlog;
   //msg:StringCP1251;
   msg:rawbytestring;
begin
msg:='Іівівйц й вфівфъ2цву йцуцйівів';
SetCodePage(msg, 1251, True);

Write('DefaultSystemCodePage is ');
Writeln(system.DefaultSystemCodePage);

logger:=teventlog.create(nil);
logger.Identification:='My gressdqwwe';
logger.RegisterMessageFile('');
logger.logtype:=ltsystem;
logger.active:=true;

Write('Code page is ');
WriteLn(StringCodePage(msg));

logger.Info(msg);
logger.Destroy;

WriteLn('End');
end.

OS: English Windows XP.


More information about the fpc-pascal mailing list