<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#cccccc" text="#000000">
Florian Klaempfl wrote:
<blockquote cite="mid:47CAF289.5070702@freepascal.org" type="cite">
<pre wrap="">Martin Schreiber schrieb:
</pre>
<blockquote type="cite">
<pre wrap="">On Sunday 02 March 2008 18.48:01 Daniël Mantione wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Op Sun, 2 Mar 2008, schreef Florian Klaempfl:
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">What did I wrong?
</pre>
</blockquote>
<pre wrap="">I'am not sure how this could be made working just a remark: -Fcutf8
influences _only_ the interpretation of string constants when converting
them to unicode.
</pre>
</blockquote>
<pre wrap="">Right. Try to compile the (utf-8 encoded) file without specifying a code
page, this should result in the constants ending up in the resourcestring
without processing.
</pre>
</blockquote>
<pre wrap="">And now the widestring constants are broken, see attachment...
</pre>
</blockquote>
<pre wrap=""><!---->
Did you utf-8 decode the string constants?
_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/mailman/listinfo/fpc-devel">http://lists.freepascal.org/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
<font size="-1"><font face="Helvetica, Arial, sans-serif">Inside our
projects there are lots of WIdeStrings handling.<br>
<br>
For Delphi/Kylix we use the following dirty hack (somewhat reworked
routine from Borland RTL):<br>
This one is Widows implementation,<br>
There is also linux implementation<br>
<br>
function LoadResStringW(const pRec: PResStringRec): WideString;<br>
var<br>
hInst:cardinal;<br>
Buffer: array [0..1023] of char;<br>
begin<br>
if pRec = nil then Exit;<br>
<br>
if pRec^.Identifier < 64*1024 then<br>
begin<br>
hInst:=FindResourceHInstance(pRec^.Module^);<br>
// try wide<br>
if LoadStringW(hInst,pRec^.Identifier, @Buffer,
SizeOf(Buffer))>0 then<br>
Result:=PWideChar(@Buffer)<br>
else // try narrow<br>
if LoadString(hInst,pRec^.Identifier, @Buffer, SizeOf(Buffer))>0
then<br>
Result:=PChar(@Buffer)<br>
else<br>
Result:='-lost-';<br>
end<br>
else<br>
Result := PWideChar(pRec^.Identifier);<br>
end;<br>
<br>
To get the wide string from resource string by its identifier, we go
the following:<br>
<br>
resourcestring<br>
sWideStringID='Some string';<br>
<br>
var <br>
mw:WideString;<br>
<br>
mw:=LoadresStringW(@sWideStringID)<br>
<br>
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 <br>
was implicitly decoded to current codepage. PRestringRec is boralnd
specific, under FPC it is PAnsiString;<br>
<br>
function LoadResStringW(const pRec: PResStringRec): WideString;inline;<br>
begin<br>
if pRec=nil then<br>
Result:=''<br>
else<br>
begin<br>
{$ifdef LINUX}<br>
Result:=PAnsiString(pRec)^;<br>
{$else}<br>
{$ifdef WindowsUnicodeSupport}<br>
Result:=UTF8Decode(PAnsiString(pRec)^);<br>
{$else}<br>
Result:=PAnsiString(pRec)^;<br>
{$endif}<br>
{$endif}<br>
end;<br>
end;<br>
{$ENDIF} // end platform-compiler dependent string loader<br>
<br>
<br>
Please help -<br>
How to implement that dirty hack.<br>
<br>
<br>
Best regards,<br>
Anton Kavalenka<br>
</font></font>
</body>
</html>