[fpc-devel] Unicode resourcestrings

Anton Kavalenka anton.k at tut.by
Mon Mar 3 12:49:45 CET 2008


Florian Klaempfl wrote:
> Martin Schreiber schrieb:
>   =

>> On Sunday 02 March 2008 18.48:01 Dani=EBl Mantione wrote:
>>     =

>>> Op Sun, 2 Mar 2008, schreef Florian Klaempfl:
>>>       =

>>>>> What did I wrong?
>>>>>           =

>>>> I'am not sure how this could be made working just a remark: -Fcutf8
>>>> influences _only_ the interpretation of string constants when converti=
ng
>>>> them to unicode.
>>>>         =

>>> Right. Try to compile the (utf-8 encoded) file without specifying a code
>>> page, this should result in the constants ending up in the resourcestri=
ng
>>> without processing.
>>>
>>>       =

>> And now the widestring constants are broken, see attachment...
>>     =

>
> Did you utf-8 decode the string constants?
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>
>   =

Inside our projects there are lots of WIdeStrings handling.

For Delphi/Kylix we use the following dirty hack (somewhat reworked =

routine from Borland RTL):
This one is Widows implementation,
There is also linux implementation

function LoadResStringW(const pRec: PResStringRec): WideString;
var
  hInst:cardinal;
  Buffer: array [0..1023] of char;
begin
  if pRec =3D nil then Exit;

  if pRec^.Identifier < 64*1024 then
  begin
    hInst:=3DFindResourceHInstance(pRec^.Module^);
    // try wide
    if LoadStringW(hInst,pRec^.Identifier, @Buffer, SizeOf(Buffer))>0 then
      Result:=3DPWideChar(@Buffer)
    else // try narrow
    if LoadString(hInst,pRec^.Identifier, @Buffer, SizeOf(Buffer))>0 then
      Result:=3DPChar(@Buffer)
    else
      Result:=3D'-lost-';
  end
  else
    Result :=3D PWideChar(pRec^.Identifier);
end;

To get the wide string from resource string by its identifier, we go the =

following:

resourcestring
  sWideStringID=3D'Some string';

var
    mw:WideString;

mw:=3DLoadresStringW(@sWideStringID)

Under FPC there is special implementation, but dirty hack does not work =

all the time, since there is hard to determine - where was the resource =

string
was implicitly decoded to current codepage. PRestringRec is boralnd =

specific, under FPC it is PAnsiString;

function LoadResStringW(const pRec: PResStringRec): WideString;inline;
begin
  if pRec=3Dnil then
  Result:=3D''
  else
  begin
    {$ifdef LINUX}
    Result:=3DPAnsiString(pRec)^;
    {$else}
    {$ifdef WindowsUnicodeSupport}
    Result:=3DUTF8Decode(PAnsiString(pRec)^);
    {$else}
    Result:=3DPAnsiString(pRec)^;
    {$endif}
    {$endif}
  end;
end;
{$ENDIF} // end platform-compiler dependent string loader


Please help -
How to implement that dirty hack.


Best regards,
Anton Kavalenka
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freepascal.org/lists/fpc-devel/attachments/20080303/5d770=
b89/attachment.html


More information about the fpc-devel mailing list