Sign in Join

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

Mailing lists / lazarus / 2015-02

-FcUTF8,-dEnableUTF8 create problem

29 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

FreeMan

osx fpc & lazarus svn QT x64
my project's Compiler options has
-FcUTF8
-dEnableUTF8

this is my code: this code work normal without ut8 params

const
   WIN_EXE: String = 'MZ';
   LINUX_EXE: String = #127 + 'ELF';
var
   wFileStr: TFileStream;
   ar: array[0..4] of byte;
   ExecType: char;
  wProgram := ParamStrUTF8(0);
  wFileStr := TFileStream.Create(wProgram, fmOpenRead);
  try
    wFileStr.Read(ar, 4); *--> problem is here ar array all Item is 0,
test width string, its return nil*
  Finally
    wFileStr.Free;
  end;
  if CompareMem(@(ar), Pchar(WIN_EXE), 2) then ExecType := 'W'
  else if CompareMem(@(ar), Pchar(LINUX_EXE), 4) then ExecType := 'L'
       else Exit;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150219/9b12db80/attachment.html>

Reply by email

Juha Manninen
to FreeMan
FreeMan wrote
osx fpc & lazarus svn QT x64 my project's Compiler options has -FcUTF8 -dEnableUTF8

Do these 2 flags make a difference? I don't think they do because the problem is not about string encoding.
Was you code working earlier? What has changed since then?

Juha

Reply by email

FreeMan
to Juha Manninen

I wrote before message

this is my code: this code work normal without ut8 params

no, I not change my code, If I remove utf8 params, code working normal.

Juha Manninen wrote 9 lines
> osx fpc & lazarus svn QT x64 > >my project's Compiler options has > >-FcUTF8 > >-dEnableUTF8 Do these 2 flags make a difference? I don't think they do because the problem is not about string encoding. Was you code working earlier? What has changed since then? Juha

Reply by email

Mattias Gaertner
to FreeMan: osx fpc & lazarus svn QT x64 my project's Compiler options has -FcUTF8 -dEnableUTF8 this…
osx fpc & lazarus svn QT x64 my project's Compiler options has -FcUTF8

This changes the $codepage.

-dEnableUTF8

This has no effect on UTF8 Linux.

this is my code: this code work normal without ut8 params

Is this an LCL application?

const WIN_EXE: String = 'MZ'; LINUX_EXE: String = #127 + 'ELF';

What is string? AnsiString?

Show quoted text 15 lines
var wFileStr: TFileStream; ar: array[0..4] of byte; ExecType: char; wProgram := ParamStrUTF8(0); wFileStr := TFileStream.Create(wProgram, fmOpenRead); try wFileStr.Read(ar, 4); *--> problem is here ar array all Item is 0, test width string, its return nil* Finally wFileStr.Free; end; if CompareMem(@(ar), Pchar(WIN_EXE), 2) then ExecType := 'W' else if CompareMem(@(ar), Pchar(LINUX_EXE), 4) then ExecType := 'L' else Exit;

Mattias

Reply by email

FreeMan
to Mattias Gaertner
Mattias Gaertner wrote
> this is my code: this code work normal without ut8 params Is this an LCL application?

I'm not clearly understand lcl application mean. its GUI application, not just console.

Show quoted text 5 lines
> const > WIN_EXE: String = 'MZ'; > LINUX_EXE: String = #127 + 'ELF'; What is string? AnsiString?

I was founded in the internet, I benefit this code http://lists.lazarus.freepascal.org/pipermail/lazarus/2013-November/084198.html follow function AnyProgramVersion(const sProgram: string;...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150219/a01bf6b7/attachment.html>

Reply by email

luiz americo pereira camara
to FreeMan: osx fpc & lazarus svn QT x64 my project's Compiler options has -FcUTF8 -dEnableUTF8 this…

2015-02-19 5:30 GMT-03:00 FreeMan :

Show quoted text 16 lines
osx fpc & lazarus svn QT x64 my project's Compiler options has -FcUTF8 -dEnableUTF8 this is my code: this code work normal without ut8 params const WIN_EXE: String = 'MZ'; LINUX_EXE: String = #127 + 'ELF'; var wFileStr: TFileStream; ar: array[0..4] of byte; ExecType: char; wProgram := ParamStrUTF8(0);

What type is wParam?

Can you check the return value of the below procedure when passing wParam with and without -FcUTF8?

function StrToHex(const S: RawByteString): String;
var
  i: Integer;
begin
  Result := '';
  if S = '' then
    Exit;
  for i := 1 to Length(S) do
  begin
    Result := Result + IntToHex(Byte(S[i]), 0);
  end;
end;

Luiz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150219/9cea9720/attachment.html>

Reply by email

luiz americo pereira camara
to luiz americo pereira camara

May you also check the DefaultSystemCodePage value

and StringCodePage(wParam) before and after assigning wParam

Luiz

2015-02-19 8:02 GMT-03:00 luiz americo pereira camara :

Show quoted text 42 lines
2015-02-19 5:30 GMT-03:00 FreeMan : > osx fpc & lazarus svn QT x64 > my project's Compiler options has > -FcUTF8 > -dEnableUTF8 > > this is my code: this code work normal without ut8 params > > const > WIN_EXE: String = 'MZ'; > LINUX_EXE: String = #127 + 'ELF'; > var > wFileStr: TFileStream; > ar: array[0..4] of byte; > ExecType: char; > wProgram := ParamStrUTF8(0); > What type is wParam? Can you check the return value of the below procedure when passing wParam with and without -FcUTF8? function StrToHex(const S: RawByteString): String; var i: Integer; begin Result := ''; if S = '' then Exit; for i := 1 to Length(S) do begin Result := Result + IntToHex(Byte(S[i]), 0); end; end; Luiz

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150219/c9d27bbc/attachment.html>

Reply by email

FreeMan
to luiz americo pereira camara: 2015-02-19 5:30 GMT-03:00 FreeMan : What type is wParam? Can you check the return value…

showmessage(StrToHex('1234567890'));
results:
Compiler Options --> Other is empty
31323334353637383930

Compiler Options --> Other "-FcUTF8"

31323334353637383930

Compiler Options --> Other "-FcUTF8 , -dEnableUTF8"

31323334353637383930

luiz americo pereira camara wrote 18 lines
Can you check the return value of the below procedure when passing wParam with and without -FcUTF8? function StrToHex(const S: RawByteString): String; var i: Integer; begin Result := ''; if S = '' then Exit; for i := 1 to Length(S) do begin Result := Result + IntToHex(Byte(S[i]), 0); end; end; Luiz

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150219/7dfd4119/attachment.html>

Reply by email

Mattias Gaertner
to FreeMan: I'm not clearly understand lcl application mean. its GUI application, not just console. I…
Show quoted text 7 lines
On 19.02.2015 11:44, Mattias Gaertner wrote: >> this is my code: this code work normal without ut8 params > Is this an LCL application? I'm not clearly understand lcl application mean. its GUI application, not just console.

I assumed so. I just wanted to make sure.

Show quoted text 7 lines
>> const >> WIN_EXE: String = 'MZ'; >> LINUX_EXE: String = #127 + 'ELF'; > What is string? AnsiString? I was founded in the internet, I benefit this code http://lists.lazarus.freepascal.org/pipermail/lazarus/2013-November/084198.html follow function AnyProgramVersion(const sProgram: string;...

The unit seems to only support Windows and Linux. What do you expect under OS X?

Mattias

Reply by email

FreeMan
to luiz americo pereira camara: May you also check the DefaultSystemCodePage value and StringCodePage(wParam) before and…

how to test & result is:
zzz := 'DefaultSystemCodePage = ' + Inttostr(DefaultSystemCodePage) + LineEnding +
'DefaultUnicodeCodePage = ' + Inttostr(DefaultUnicodeCodePage) + LineEnding +
'DefaultFileSystemCodePage = ' + Inttostr(DefaultFileSystemCodePage) + LineEnding +
'DefaultRTLFileSystemCodePage = ' +
Inttostr(DefaultRTLFileSystemCodePage) + LineEnding + 'UTF8CompareLocale =' + Inttostr(UTF8CompareLocale); ShowMessage(zzz);

with or without -FcUTF8,-dEnableUTF8

DefaultSystemCodePage = 65001
DefaultUnicodeCodePage = 0
DefaultFileSystemCodePage = 65001
DefaultRTLFileSystemCodePage = 65001

UTF8CompareLocale =0

luiz americo pereira camara wrote
May you also check the DefaultSystemCodePage value

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150219/796ed0aa/attachment.html>

Reply by email

luiz americo pereira camara
to FreeMan: showmessage(StrToHex('1234567890')); results: Compiler Options --> Other is empty…

2015-02-19 8:19 GMT-03:00 FreeMan :

Show quoted text 13 lines
showmessage(StrToHex('1234567890')); results: Compiler Options --> Other is empty 31323334353637383930 Compiler Options --> Other "-FcUTF8" 31323334353637383930 Compiler Options --> Other "-FcUTF8 , -dEnableUTF8" 31323334353637383930
Thanks. This means problem is not in ParamStrUTF8(0);

I have two more tips to try to see where the problem is:

What is the type of wProgram?

Compile with the option -al (without debug info to get smaller files) and look to the generated asm file (has .s extension and lives the same dir the units are store)

look at the generated code for

wFileStr := TFileStream.Create(wProgram, fmOpenRead);

and

wFileStr.Read(ar, 4);

BTW: the compiler are being recompiled with those options "-FcUTF8 , -dEnableUTF8" or only LCL?

Luiz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150219/5ed71bb3/attachment.html>

Reply by email

FreeMan
to Mattias Gaertner

Thank you Mattias
I found a few minutes ago this link,
http://wiki.lazarus.freepascal.org/Show_Application_Title,_Version,_and_Company and test finished in osx a few second ago. All works fine for me. I'm not test on linux and win, maybe later I can test in crosscompile. This is impotent for me.
But this topic still countinue about
wFileStr.Read(ar, 4);
maybe has a bug here. Different then my problem.

Mattias Gaertner wrote 12 lines
> >I need get application version infos, and others, > >........ > > VR : TVersionResource; > > FV : TFileVersionInfo; > >..... > > VR.FixedInfo.FileVersion[0]; > > FV.VersionStrings.Values['CompanyName']; > >FV.VersionStrings.Values['InternalName']; > >etc. Extend the unit with the TMachOResourceReader. Mattias

Reply by email

Mattias Gaertner
to FreeMan
Show quoted text 9 lines
Thank you Mattias I found a few minutes ago this link, http://wiki.lazarus.freepascal.org/Show_Application_Title,_Version,_and_Company and test finished in osx a few second ago. All works fine for me. I'm not test on linux and win, maybe later I can test in crosscompile. This is impotent for me. But this topic still countinue about wFileStr.Read(ar, 4); maybe has a bug here. Different then my problem.

What is wrong with "wFileStr.Read(ar, 4);"?
It only reads bytes. No strings involved. Has nothing to do with UTF8.

Mattias

Reply by email

FreeMan
to luiz americo pereira camara: 2015-02-19 8:19 GMT-03:00 FreeMan : Thanks. This means problem is not in ParamStrUTF8(0);…
luiz americo pereira camara wrote
Thanks. This means problem is not in ParamStrUTF8(0);

I was checked Its hasn't problem.

I have two more tips to try to see where the problem is: What is the type of wProgram?
wProgram: String;
Show quoted text 5 lines
Compile with the option -al (without debug info to get smaller files) and look to the generated asm file (has .s extension and lives the same dir the units are store)

where to add this parameter?

maybe I have a another bug
Project option -> Compiler options -> Other
Button "All options ..." open All options form but not show anything. Just filter bar and checkbox

Show quoted text 12 lines
look at the generated code for wFileStr := TFileStream.Create(wProgram, fmOpenRead); and wFileStr.Read(ar, 4); BTW: the compiler are being recompiled with those options "-FcUTF8 , -dEnableUTF8" or only LCL? Luiz

Reply by email

FreeMan
to Mattias Gaertner: On Thu, 19 Feb 2015 14:28:19 +0200 What is wrong with "wFileStr.Read(ar, 4);"? It only…

Yes you right, code is normal, but result is not same. if I add this utf8 parameters, result is all Items is zero, this mean nothing there, but when I remove utf8 parameter, ar has a value. I'm talk about this.

Mattias Gaertner wrote
What is wrong with "wFileStr.Read(ar, 4);"? It only reads bytes. No strings involved. Has nothing to do with UTF8. Mattias

Reply by email

luiz americo pereira camara
to FreeMan: I was checked Its hasn't problem. wProgram: String; where to add this parameter? maybe I…

2015-02-19 9:41 GMT-03:00 FreeMan :

Show quoted text 6 lines
maybe I have a another bug Project option -> Compiler options -> Other Button "All options ..." open All options form but not show anything. Just filter bar and checkbox

Same here. Probably related to compiler version (v3.x). When i open a project that uses fpc 2.6.4 the options are show

Luiz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150219/fc9cdc97/attachment.html>

Reply by email

FreeMan
to luiz americo pereira camara: 2015-02-19 8:19 GMT-03:00 FreeMan : Thanks. This means problem is not in ParamStrUTF8(0);…

Sorry I been late.

var wProgram :string;

params:

-dUseCThreads

-FcUTF8

-dEnableUTF8

-al

result:
# [634] wFileStr.Read(ar, 4);
leaq -24(%rbp),%r14
movq -16(%rbp),%r13
movl $4,%r12d
movq -16(%rbp),%rbx
testq %rbx,%rbx
jne Lj2643
movl $210,%edi
call fpc_handleerror
Lj2643:
movq (%rbx),%rbx
movq %rbx,%rdi
call fpc_check_object
movl %r12d,%edx
movq %r13,%rdi
movq %r14,%rsi
call *256(%rbx)
Lj2634:
call FPC_POPADDRSTACK
# [637] wFileStr.Free

params:

-dUseCThreads

-al
results:# [634] wFileStr.Read(ar, 4);
leaq -24(%rbp),%r14
movq -16(%rbp),%r13
movl $4,%r12d
movq -16(%rbp),%rbx
testq %rbx,%rbx
jne Lj2515
movl $210,%edi
call fpc_handleerror
Lj2515:
movq (%rbx),%rbx
movq %rbx,%rdi
call fpc_check_object
movl %r12d,%edx
movq %r13,%rdi
movq %r14,%rsi
call *256(%rbx)
Lj2506:
call FPC_POPADDRSTACK
# [637] wFileStr.Free;

luiz americo pereira camara wrote 21 lines
I have two more tips to try to see where the problem is: What is the type of wProgram? Compile with the option -al (without debug info to get smaller files) and look to the generated asm file (has .s extension and lives the same dir the units are store) look at the generated code for wFileStr := TFileStream.Create(wProgram, fmOpenRead); and wFileStr.Read(ar, 4); BTW: the compiler are being recompiled with those options "-FcUTF8 , -dEnableUTF8" or only LCL? Luiz

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150220/3a3ef4a7/attachment.html>

Reply by email

FreeMan
to luiz americo pereira camara

compiler options:

-dUseCThreads

-FcUTF8

-dEnableUTF8

this is test code:
var
   wProgram: String;
   z:longint;
   s:string;
begin
  Result   := False;
  wProgram :=ParamStrUTF8(0);
  wFileStr := TFileStream.Create(wProgram, fmOpenRead);
  z:= -1;
  z:=wFileStr.Handle;
  s:=wFileStr.FileName;

result:
wProgram --> ^char($000000010CA86358) '/opt/proje_laz/myproject.app' z --> 40
wFileStr.FileName --> '/opt/proje_laz/myproject.app' s --> ^char($000000010CA86358) '/opt/proje_laz/myproject.app'

I getted this result while debugging from Whach list, via copy value. wFileStr.FileName and s showing different value. "^charxxxx"

luiz americo pereira camara wrote 8 lines
OK. They are equal so problem is elsewhere One last shot. Can you check the values of wFileStr FileName and Handle properties? Luiz

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150222/7058f052/attachment.html>

Reply by email

luiz americo pereira camara
to FreeMan

2015-02-22 8:05 GMT-03:00 FreeMan :

Show quoted text 30 lines
compiler options: -dUseCThreads -FcUTF8 -dEnableUTF8 this is test code: var wProgram: String; z:longint; s:string; begin Result := False; wProgram :=ParamStrUTF8(0); wFileStr := TFileStream.Create(wProgram, fmOpenRead); z:= -1; z:=wFileStr.Handle; s:=wFileStr.FileName; result: wProgram --> ^char($000000010CA86358) '/opt/proje_laz/myproject.app' z --> 40 wFileStr.FileName --> '/opt/proje_laz/myproject.app' s --> ^char($000000010CA86358) '/opt/proje_laz/myproject.app' I getted this result while debugging from Whach list, via copy value. wFileStr.FileName and s showing different value. "^charxxxx"

OK.

Thanks.

Personally don't have more idea of what is wrong. Hopefully someone else can find the problem

Luiz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150222/7ed5ce61/attachment.html>

Reply by email

FreeMan
to luiz americo pereira camara

I wrote before, I'm not use this code block now. I remove that code block to function. still not remove it, save for your tests. please let me know, need test etc. when you tell me you finished or cansel work on it, I'll remove that from my code.
Thank you

luiz americo pereira camara wrote 8 lines
OK. Thanks. Personally don't have more idea of what is wrong. Hopefully someone else can find the problem Luiz

Reply by email

luiz americo pereira camara
to FreeMan

2015-02-22 11:46 GMT-03:00 FreeMan :

Show quoted text 5 lines
I wrote before, I'm not use this code block now. I remove that code block to function. still not remove it, save for your tests. please let me know, need test etc. when you tell me you finished or cansel work on it, I'll remove that from my code.

For my sake, feel free to remove from your code. I really don't have a clue what went wrong.
Anyway, if someone wants to take a look, the code can be easily reconstructed from the info in this thread.

Luiz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150222/06bc1ac9/attachment-0001.html>

Reply by email

FreeMan
to luiz americo pereira camara

Okey Luiz,
Thank you so much for your help.

luiz americo pereira camara wrote 6 lines
For my sake, feel free to remove from your code. I really don't have a clue what went wrong. Anyway, if someone wants to take a look, the code can be easily reconstructed from the info in this thread. Luiz

Reply by email

Mattias Gaertner
to luiz americo pereira camara: 2015-02-22 11:46 GMT-03:00 FreeMan : For my sake, feel free to remove from your code. I…
Show quoted text 12 lines
2015-02-22 11:46 GMT-03:00 FreeMan : > I wrote before, I'm not use this code block now. I remove that code block > to function. still not remove it, save for your tests. please let me know, > need test etc. when you tell me you finished or cansel work on it, I'll > remove that from my code. > For my sake, feel free to remove from your code. I really don't have a clue what went wrong. Anyway, if someone wants to take a look, the code can be easily reconstructed from the info in this thread.

Post a complete example and someone can find out.

Mattias

Reply by email

FreeMan
to Mattias Gaertner
Mattias Gaertner wrote
Post a complete example and someone can find out. Mattias

code block is not mine, I was find in this link.
http://lists.lazarus.freepascal.org/pipermail/lazarus/2013-November/084198.html

function AnyProgramVersion(const sProgram: string; Out vv: PTVersion) :Boolean;
const
   WIN_EXE: String = 'MZ';
   LINUX_EXE: String = #127 + 'ELF';
var
   wFileStr: TFileStream;
   RS : TResources;
   E : TWinPEImageResourceReader=nil;
   EL : TElfResourceReader=nil;
   VR : TVersionResource;
   I : Integer;
   {$IFDEF WINCE}
   wProgram: WideString;
   {$ELSE}
   wProgram: String;
   {$ENDIF}
   ar: array[0..4] of byte;
   ExecType: char;
begin
   Result := False;
   vv := New(PTVersion);
   with vv^ do begin
     Major:= -1;
     Minor := 0;
     Release := 0;
     Build := 0;
   end;
   if sProgram = EmptyStr then
     wProgram := ParamStr(0)
   else
     wProgram := sProgram;
   if not FileExists(wProgram) then begin
     // program name without path, assume directory of executing program
     if Pos(DirectorySeparator, wProgram) = 0 then begin
       wProgram := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))) + sProgram;
       if not FileExists(wProgram) then
         Exit;
     end else
       // no path delimiter, get out
       Exit;
   end else
     wProgram := sProgram;
   wFileStr := TFileStream.Create(sProgram, fmOpenRead);
   try
     // check what kind of executable an get resources accordingly
     wFileStr.Read(ar, 4);
   Finally
     wFileStr.Free;
   end;
   if CompareMem(@(ar), Pchar(WIN_EXE), 2) then
     ExecType := 'W'
   else
   if CompareMem(@(ar), Pchar(LINUX_EXE), 4) then
     ExecType := 'L'
   else
     Exit;
   RS:=TResources.Create;
   try
     try
       if ExecType = 'W' then begin
         E := TWinPEImageResourceReader.Create;
         Rs.LoadFromFile(wProgram, E);
       end else begin
         EL := TElfResourceReader.Create;
         Rs.LoadFromFile(wProgram, EL);
       end;
     finally
       if Assigned(E) then
         E.Free;
       if Assigned(EL) then
         EL.Free;
     end;
     VR:=Nil;
     I:=0;
     While (VR=Nil) and (I < RS.Count) do begin
       if RS.Items[i] is TVersionResource then
         VR := TVersionResource(RS.Items[i]);
       Inc(I);
     end;
     if VR  Nil then begin
       with vv^ do begin
         Major:= VR.FixedInfo.FileVersion[0];
         Minor := VR.FixedInfo.FileVersion[1];
         Release := VR.FixedInfo.FileVersion[2];
         Build := VR.FixedInfo.FileVersion[3];
       end;
       Result := True
     End ;
   Finally
     RS.FRee;
   end;
end;
{$IFDE

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150224/6f496125/attachment.html>

Reply by email

Mattias Gaertner
to FreeMan
On 22.02.2015 20:37, Mattias Gaertner wrote: > Post a complete example and someone can find out. > code block is not mine, I was find in this link.

Several people tried to find out what is wrong with your code snippet and failed.
Please post a complete example - one that compiles.

Mattias

Reply by email