Sign in Join

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

Mailing lists / lazarus / 2012-04

TProcess, UTF8, Windows

86 messages · 14 people · –

Reply by email Subscribe to this list Your subscription

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

Marcos Douglas

Hi,

I'm using the example in FreePascal wiki to execute external programs: http://wiki.freepascal.org/Executing_External_Programs#Reading_large_output

I adapted this code to work in LCL, using a simple TMemo. All "write" and "writeln" was replaced with
Memo1.Lines.Append(ConsoleToUTF8(<text or variable>)).

Everything works fine... but since I changed this line:
OurProcess.Options := [poUsePipes];
to
OurProcess.Options := [poUsePipes, poNoConsole];

...the conversion ConsoleToUTF8 do not work.

Any tips?

Marcos Douglas

Reply by email

Mattias Gaertner
to Marcos Douglas
Show quoted text 8 lines
Hi, I'm using the example in FreePascal wiki to execute external programs: http://wiki.freepascal.org/Executing_External_Programs#Reading_large_output I adapted this code to work in LCL, using a simple TMemo. All "write" and "writeln" was replaced with Memo1.Lines.Append(ConsoleToUTF8(<text or variable>)).

What is the source of <text or variable>?
The output of the other process?

Show quoted text 8 lines
Everything works fine... but since I changed this line: OurProcess.Options := [poUsePipes]; to OurProcess.Options := [poUsePipes, poNoConsole]; ...the conversion ConsoleToUTF8 do not work. Any tips?
Maybe the other process's output is not in console codepage.
Try

Memo1.Lines.Append(<text or variable>)
or
Memo1.Lines.Append(SysToUTF8(<text or variable>)).

Mattias

Reply by email

Marcos Douglas
to Mattias Gaertner
Mattias Gaertner wrote 14 lines
On Thu, 12 Apr 2012 12:34:59 -0300 Marcos Douglas wrote: > Hi, > > I'm using the example in FreePascal wiki to execute external programs: > http://wiki.freepascal.org/Executing_External_Programs#Reading_large_output > > I adapted this code to work in LCL, using a simple TMemo. > All "write" and "writeln" was replaced with > Memo1.Lines.Append(ConsoleToUTF8(<text or variable>)). What is the source of <text or variable>? The output of the other process?

I mean Write('.') or WriteLn(OutputLines[NumBytes]) etc. See the original code in the wiki.

Show quoted text 15 lines
> Everything works fine... but since I changed this line: > OurProcess.Options := [poUsePipes]; > to > OurProcess.Options := [poUsePipes, poNoConsole]; > > ...the conversion ConsoleToUTF8 do not work. > > Any tips? Maybe the other process's output is not in console codepage. Try Memo1.Lines.Append(<text or variable>) or Memo1.Lines.Append(SysToUTF8(<text or variable>)).

I will try... but I see other problem now. The example read all buffer before print on screen (in my case, a TMemo).
I want to print on time. I will change the code for this before try UTF8 conversion.

Do you have an example for I need?

Marcos Douglas

Reply by email

Jürgen Hestermann
to Mattias Gaertner: On Thu, 12 Apr 2012 12:34:59 -0300 What is the source of <text or variable>? The output…
Show quoted text 6 lines
Maybe the other process's output is not in console codepage. Try Memo1.Lines.Append(<text or variable>) or Memo1.Lines.Append(SysToUTF8(<text or variable>)).

I am always astonished that we have come so far already! Today programmers have to guess about coding of strings, they cannot find out in documentation or by identifier name. Only trial and error (the latter mostly when the program is in production use) can be used. That's what I call C style and is not what Niklaus Wirth had in mind.

IMO it must be possible to predict the encoding of strings when writing the code (without running the program).

Reply by email

Lukasz Sokol
to Jürgen Hestermann
J?rgen Hestermann wrote 16 lines
Mattias Gaertner schrieb: > Maybe the other process's output is not in console codepage. > Try > Memo1.Lines.Append(<text or variable>) > or > Memo1.Lines.Append(SysToUTF8(<text or variable>)). > I am always astonished that we have come so far already! Today programmers have to guess about coding of strings, they cannot find out in documentation or by identifier name. Only trial and error (the latter mostly when the program is in production use) can be used. That's what I call C style and is not what Niklaus Wirth had in mind. IMO it must be possible to predict the encoding of strings when writing the code (without running the program).

No one prohibits you to use an identifier name to reflect encoding ;)

Also : how do you think you'd guess encoding of a text file on disk before reading it ? Some people don't like to have the decision taken by the compiler for themselves...

Other area where this may be important: web applications. Database fields may (each) have different encoding (and we would be able to know it), internals of the app would work on their own encoding (and we would know it) the web frontend may run on different encoding every time (and we would be able to know it ) (imagine somebody forces a certain encoding on their web browser and tells the web app developer to support THAT)

I for one /like/ that The New Pascal has become highly customizable even if some things have to be more explicit than in Ye Olden Days...

It's still way more 'high level' than plain c that some people dub 'assembler on drugs'....

;)
L.

Reply by email

Marcos Douglas
to Jürgen Hestermann: I am always astonished that we have come so far already! Today programmers have to guess…
J?rgen Hestermann wrote 19 lines
Mattias Gaertner schrieb: > Maybe the other process's output is not in console codepage. > Try > Memo1.Lines.Append(<text or variable>) > or > Memo1.Lines.Append(SysToUTF8(<text or variable>)). > I am always astonished that we have come so far already! Today programmers have to guess about coding of strings, they cannot find out in documentation or by identifier name. Only trial and error (the latter mostly when the program is in production use) can be used. That's what I call C style and is not what Niklaus Wirth had in mind. IMO it must be possible to predict the encoding of strings when writing the code (without running the program).

I think this is being made in the FPC trunk.
Let's wait.

Marcos Douglas

Reply by email

Marcos Douglas
to Marcos Douglas: On Thu, Apr 12, 2012 at 5:20 PM, Mattias Gaertner I mean Write('.') or…
Marcos Douglas wrote 44 lines
On Thu, Apr 12, 2012 at 5:20 PM, Mattias Gaertner wrote: > On Thu, 12 Apr 2012 12:34:59 -0300 > Marcos Douglas wrote: > >> Hi, >> >> I'm using the example in FreePascal wiki to execute external programs: >> >> http://wiki.freepascal.org/Executing_External_Programs#Reading_large_output >> >> I adapted this code to work in LCL, using a simple TMemo. >> All "write" and "writeln" was replaced with >> Memo1.Lines.Append(ConsoleToUTF8(<text or variable>)). > > What is the source of <text or variable>? > The output of the other process? I mean Write('.') or WriteLn(OutputLines[NumBytes]) etc. See the original code in the wiki. >> Everything works fine... but since I changed this line: >> OurProcess.Options := [poUsePipes]; >> to >> OurProcess.Options := [poUsePipes, poNoConsole]; >> >> ...the conversion ConsoleToUTF8 do not work. >> >> Any tips? > > Maybe the other process's output is not in console codepage. > Try > > Memo1.Lines.Append(<text or variable>) > or > Memo1.Lines.Append(SysToUTF8(<text or variable>)). I will try... but I see other problem now. The example read all buffer before print on screen (in my case, a TMemo). I want to print on time. I will change the code for this before try UTF8 conversion. Do you have an example for I need?

I resolved using:

procedure TConsoleTask.ReadingOutput;
var
  NoMoreOutput: Boolean;
  Buffer: string;
  BytesAvailable: DWord;
  BytesRead: LongInt;
begin
  while FProcess.Running do
  begin
    BytesRead := 0;
    BytesAvailable := FProcess.Output.NumBytesAvailable;
    if BytesAvailable > 0 then
    begin
      SetLength(Buffer, BytesAvailable);
      BytesRead := FProcess.OutPut.Read(Buffer[1], BytesAvailable);
      DoLog(Copy(Buffer, 1, BytesRead));  //<<<< here fires an event
      BytesAvailable := FProcess.Output.NumBytesAvailable;
    end
    else
      Sleep(100);
  end;
end;

IMHO, this could be present in TProcess, don't?
Or this is TAsyncProcess class serves?

Marcos Douglas

Reply by email

Jürgen Hestermann
to Lukasz Sokol: No one prohibits you to use an identifier name to reflect encoding ;) Also : how do you…
> IMO it must be possible to predict the encoding of strings > when writing the code (without running the program). No one prohibits you to use an identifier name to reflect encoding ;)

That's true and that's what I am doing of course.

But if you use a function from a (Free Pascal or Lazarus) library it is not clear which kind of encoding this function expects. As I already mentioned, for example CopyFile (from LCL) and FindFirst (from SysUtils) have no hint in their documentation on what encoding is expected. I know, somewhere it says that library x has enconding y but why wasn't this information written to the documentation for the indiviudal functions? I don't get it. It's a very important information. I think that many Free Pascal (and Lazarus) users come from other platforms like Delphi, Virtual Pascal, Turbo Pascal etc. and many want to use parts of their old code. These people do not sit down for months to find all the spread information that *may* be important for FindFirst, CopyFile, etc. They expect all releveant information at the docu for the functions.

Also : how do you think you'd guess encoding of a text file on disk before reading it ? Some people don't like to have the decision taken by the compiler for themselves...

That's not what we are talking about here. If I understood Marcos problem correctly the topic was the output of another function where the encoding was unclear.

Other area where this may be important: web applications. Database fields may (each) have different encoding (and we would be

able to know it),

internals of the app would work on their own encoding (and we would

know it)

the web frontend may run on different encoding every time (and we

would be able to know it )

(imagine somebody forces a certain encoding on their web browser and

tells

the web app developer to support THAT)

As long as you *know* about each encoding you can manage it. But if you have to guess the encoding then it will fail in general.

I for one /like/ that The New Pascal has become highly customizable

even if

some things have to be more explicit than in Ye Olden Days... It's still way more 'high level' than plain c that some people dub

'assembler on drugs'....

I only see that everything that has been added since Delphi (mainly by Borland) is more C style than Pascal (pchar, operator overloading, context dependend meaning of indentifiers, poor documentation, etc.). The focus is more on a "me too" attitude (assimilation of all all other programming languages) and not on clear, easy and readable program code.

Reply by email

Felipe Monteiro de Carvalho
to Jürgen Hestermann
J?rgen Hestermann wrote 6 lines
But if you use a function from a (Free Pascal or Lazarus) library it is not clear which kind of encoding this function expects. As I already mentioned, for example CopyFile (from LCL) and FindFirst (from SysUtils) have no hint in their documentation on what encoding is expected. I know, somewhere it says that library x has enconding y but why wasn't this information written to the documentation for the indiviudal functions?

It would be a huge duplication of documentation to write in every single Lazarus function that uses string that it expects UTF-8.

It would be like writing in every function that string means longstring (aka ansistring), that the routine is not using a shortstring ... well, this is obvious.

Felipe Monteiro de Carvalho

Reply by email

Jürgen Hestermann
to Hans-Peter Diettrich: The Delphi Unicode solution: set the proper encoding in TFileStream (? or TStringList),…
Show quoted text 6 lines
The Delphi Unicode solution: set the proper encoding in TFileStream (? or TStringList), then the file is converted into UTF-16 on read, and back again when written to disk. Then the coder has to deal only with UnicodeStrings, and with AnsiStrings of codepage CP_ACP (system default) if ever required.

At least I was *not* talking about reading text files. I was talking about strings as parameters to functions (like FindFirst etc.).

Reply by email

Mattias Gaertner
to Jürgen Hestermann: That's true and that's what I am doing of course. But if you use a function from a (Free…
Lukasz Sokol schrieb: >> IMO it must be possible to predict the encoding of strings >> when writing the code (without running the program).

Marcos didn't wrote what program he called.
Maybe the output is not even text.

Show quoted text 11 lines
> No one prohibits you to use an identifier name to reflect encoding ;) That's true and that's what I am doing of course. But if you use a function from a (Free Pascal or Lazarus) library it is not clear which kind of encoding this function expects. As I already mentioned, for example CopyFile (from LCL) and FindFirst (from SysUtils) have no hint in their documentation on what encoding is expected. I know, somewhere it says that library x has enconding y but why wasn't this information written to the documentation for the indiviudal functions?

Normally defaults are not explained for every function of a unit/package.
Feel free to add the encoding to those functions you think it is not clear and send a patch.

Show quoted text 6 lines
I don't get it. It's a very important information. I think that many Free Pascal (and Lazarus) users come from other platforms like Delphi, Virtual Pascal, Turbo Pascal etc. and many want to use parts of their old code. These people do not sit down for months to find all the spread information that *may* be important for FindFirst, CopyFile, etc. They expect all releveant information at the docu for the functions.

A volunteer project like Lazarus requires the help of volunteers.

Show quoted text 7 lines
> Also : how do you think you'd guess encoding of a text file on disk > before reading it ? Some people don't like to have the decision taken > by the compiler for themselves... That's not what we are talking about here. If I understood Marcos problem correctly the topic was the output of another function where the encoding was unclear.

What function are you talking? Have you read the example Marcos used?

[...] As long as you *know* about each encoding you can manage it. But if you have to guess the encoding then it will fail in general.

Yes.
I hope the Windows Codepages will eventually vanish.

[...]

Mattias

Reply by email

Jürgen Hestermann
to Felipe Monteiro de Carvalho: On Fri, Apr 13, 2012 at 5:18 PM, J?rgen Hestermann It would be a huge duplication of…
Show quoted text 5 lines
It would be a huge duplication of documentation to write in every single Lazarus function that uses string that it expects UTF-8. It would be like writing in every function that string means longstring (aka ansistring), that the routine is not using a shortstring ... well, this is obvious.

Huh? Now I know why it is as it is.
How can you say that all this is obvious?
Why is it obvious that FindFirst expects ANSI enconding while CopyFile needs UTF8. How should a programmer know this? It does not fall from sky.

When I use a function that I used before (in Turbo Pascal, Virtual Pascal, Delphi) but now want to use with Free Pascal (Lazarus) then the first thing is to google for it. For CopyFile I find a link to the documentation but it only says:

-----------------------------------
const SrcFilename: String;
const DestFilename: String

SrcFilename The source filename for the Copy
DestFilename The destination filename for the Copy -----------------------------------

String is generic so it can be pchar, shortstring or ansistring or .... But what is the encoding? It does not tell me. If the parameter I want to feed in comes from a different source (database, file, ...) where I know the encoding how do I find out to which encoding it has to be converted to?

Reply by email

Mattias Gaertner
to Felipe Monteiro de Carvalho: On Fri, Apr 13, 2012 at 5:18 PM, J?rgen Hestermann It would be a huge duplication of…
Show quoted text 11 lines
On Fri, Apr 13, 2012 at 5:18 PM, J?rgen Hestermann wrote: > But if you use a function from a (Free Pascal or Lazarus) library it is not > clear which kind of encoding this function expects. As I already mentioned, > for example CopyFile (from LCL) and FindFirst (from SysUtils) have no hint > in their documentation on what encoding is expected. I know, somewhere it > says that library x has enconding y but why wasn't this information written > to the documentation for the indiviudal functions? It would be a huge duplication of documentation to write in every single Lazarus function that uses string that it expects UTF-8.

Maybe a simple link UTF-8 to a topic in lazutf8 is sufficient.

It would be like writing in every function that string means longstring (aka ansistring), that the routine is not using a shortstring ... well, this is obvious.

Mattias

Reply by email

Felipe Monteiro de Carvalho
to Jürgen Hestermann: Huh? Now I know why it is as it is. How can you say that all this is obvious? Why is it…
J?rgen Hestermann wrote 5 lines
Huh? Now I know why it is as it is. How can you say that all this is obvious? Why is it obvious that FindFirst expects ANSI enconding while CopyFile needs UTF8. How should a programmer know this? It does not fall from sky.

I said that the ansistring example is obvious, not the encodings, which indeed are a gotcha. For the encodings I only said that it would be too much duplication. It is better to document this issues once in 1 single place. And we already have a large documentation about all of this. Just read here:

http://wiki.freepascal.org/LCL_Unicode_Support

About FindFirst, you should know that there is FindFirstUTF8: http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/findfirstutf8.html

Felipe Monteiro de Carvalho

Reply by email

Hans-Peter Diettrich
to Jürgen Hestermann: I am always astonished that we have come so far already! Today programmers have to guess…
Show quoted text 16 lines
Mattias Gaertner schrieb: > Maybe the other process's output is not in console codepage. > Try > Memo1.Lines.Append(<text or variable>) > or > Memo1.Lines.Append(SysToUTF8(<text or variable>)). > I am always astonished that we have come so far already! Today programmers have to guess about coding of strings, they cannot find out in documentation or by identifier name. Only trial and error (the latter mostly when the program is in production use) can be used. That's what I call C style and is not what Niklaus Wirth had in mind. IMO it must be possible to predict the encoding of strings when writing the code (without running the program).

The Delphi Unicode solution: set the proper encoding in TFileStream (? or TStringList), then the file is converted into UTF-16 on read, and back again when written to disk. Then the coder has to deal only with UnicodeStrings, and with AnsiStrings of codepage CP_ACP (system default) if ever required.

DoDi

Reply by email

Jürgen Hestermann
to Mattias Gaertner: On Fri, 13 Apr 2012 17:18:37 +0200 Marcos didn't wrote what program he called. Maybe the…
> But if you use a function from a (Free Pascal or Lazarus) library it is > not clear which kind of encoding this function expects. As I already > mentioned, for example CopyFile (from LCL) and FindFirst (from

SysUtils)

Show quoted text 7 lines
> have no hint in their documentation on what encoding is expected. I > know, somewhere it says that library x has enconding y but why wasn't > this information written to the documentation for the indiviudal > functions? Normally defaults are not explained for every function of a unit/package.

??? What defaults? The topic is string encoding not defaults.

Feel free to add the encoding to those functions you think it is not clear and send a patch.

I would like to. But how do I get the information? You see the vicious circle?
Or do you mean I should find out the encoding by trial and error for each function
myself (bulding a test program around them) because this is the only way to get it?
Who wants to program with such a programming language where encoding for function parameters is not documented?
It seems it's for the hard core developers only.

A volunteer project like Lazarus requires the help of volunteers.

Yes. If you send me a list of the expected/used string encoding for *all* function parameters then I can add this information to the documentation when I find out how to do that. How can I change it here: http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/copyfile.html ?

> That's not what we are talking about here. If I understood Marcos > problem correctly the topic was the output of another function where

the

> encoding was unclear. What function are you talking? Have you read the example Marcos used?

Well, I was mainly talking about any string parameter to any function in any library that comes with Free Pascal and/or Lazarus and I was under the impression that Marco's problem was based on the same issue: A string parameter
is required ("Memo1.Lines.Append") but it is not clear what encoding is expected.
This isssue exists for *all* functions of Free Pascal and Lazarus that expect
strings as parameters. I already mentioned the example of CopyFile: To my astonishment the function CopyFile not only exists in the unit Windows (where
I expected it) but also in the LCL (with different string encoding). The same applies to
FindFirst and other file functions.

Reply by email

Jürgen Hestermann
to Felipe Monteiro de Carvalho: On Fri, Apr 13, 2012 at 5:52 PM, J?rgen Hestermann I said that the ansistring example is…
It is better to document this issues once in 1 single place.

Definitely not! Why is it such a problem so write the encoding type for a function like CopyFile into the documentation for it? It belongs there. Of course, there could also be a link to somewhere but it must be reachable from the documentation of the function. The first information available is this entry. When I have a question to any of these functions the first place to go is google. And then I am stuck because there is no further information about encoding of the string parameters.

And we already have a large documentation about all of

Then this link has to be added to each of the affected functions. How else should someone get there from the documentation of CopyFile for example?
And it is only a very crude way to answer the simple question: What encoding is expected to the string paramters of CopyFile (or FindFirst)?

About FindFirst, you should know that there is FindFirstUTF8: http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/findfirstutf8.html

Yes, but why do I get this information only after lengthy discussions in this list? Why does no link appear unter "See also" in the FindFirst documenation? Aren't you annoyed by all these questions here in the list? If this would be answered in the documenation then it would not come up here (and would not annoy and displease so many new joiners to Free Pascal). If each and every parameter would have the same encoding then it would not be such a problem but in this case where each function has its own encoding it is essential.

Reply by email

Hans-Peter Diettrich
to Felipe Monteiro de Carvalho: On Fri, Apr 13, 2012 at 5:18 PM, J?rgen Hestermann It would be a huge duplication of…
Show quoted text 11 lines
On Fri, Apr 13, 2012 at 5:18 PM, J?rgen Hestermann wrote: > But if you use a function from a (Free Pascal or Lazarus) library it is not > clear which kind of encoding this function expects. As I already mentioned, > for example CopyFile (from LCL) and FindFirst (from SysUtils) have no hint > in their documentation on what encoding is expected. I know, somewhere it > says that library x has enconding y but why wasn't this information written > to the documentation for the indiviudal functions? It would be a huge duplication of documentation to write in every single Lazarus function that uses string that it expects UTF-8.

It would be much easier to use an TFileName string type instead, for self-documenting declarations.

DoDi

Reply by email

Michael Van Canneyt
to Jürgen Hestermann: Definitely not! Why is it such a problem so write the encoding type for a function like…
J?rgen Hestermann wrote 33 lines
Felipe Monteiro de Carvalho schrieb: > It is better to document this issues once in 1 single place. Definitely not! Why is it such a problem so write the encoding type for a function like CopyFile into the documentation for it? It belongs there. Of course, there could also be a link to somewhere but it must be reachable from the documentation of the function. The first information available is this entry. When I have a question to any of these functions the first place to go is google. And then I am stuck because there is no further information about encoding of the string parameters. And we already have a large documentation about all of > this. Just read here: > http://wiki.freepascal.org/LCL_Unicode_Support Then this link has to be added to each of the affected functions. How else should someone get there from the documentation of CopyFile for example? And it is only a very crude way to answer the simple question: What encoding is expected to the string paramters of CopyFile (or FindFirst)? > About FindFirst, you should know that there is FindFirstUTF8: > http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/findfirstutf8.html Yes, but why do I get this information only after lengthy discussions in this list? Why does no link appear unter "See also" in the FindFirst documenation? Aren't you annoyed by all these questions here in the list? If this would be answered in the documenation then it would not come up here (and would not annoy and displease so many new joiners to Free Pascal). If each and every parameter would have the same encoding then it would not be such a problem but in this case where each function has its own encoding it is essential.

Because FindFirst is part of the RTL, and FindFirstUTF8 is part of Lazarus. FPC cannot refer to the lazarus docs.

Also:
Lazarus happened to choose UTF-8 as the encoding of their LCL. By contrast, MSEGui chose UTF-16 as it's encoding.

Work is in progress to make the RTL Unicode Aware, and as soon as it is so, the encoding issues will be documented.

Michael.

Reply by email

Marcos Douglas
to Jürgen Hestermann: That's true and that's what I am doing of course. But if you use a function from a (Free…
J?rgen Hestermann wrote 20 lines
Lukasz Sokol schrieb: >> IMO it must be possible to predict the encoding of strings >> when writing the code (without running the program). > No one prohibits you to use an identifier name to reflect encoding ;) That's true and that's what I am doing of course. But if you use a function from a (Free Pascal or Lazarus) library it is not clear which kind of encoding this function expects. As I already mentioned, for example CopyFile (from LCL) and FindFirst (from SysUtils) have no hint in their documentation on what encoding is expected. I know, somewhere it says that library x has enconding y but why wasn't this information written to the documentation for the indiviudal functions? I don't get it. It's a very important information. I think that many Free Pascal (and Lazarus) users come from other platforms like Delphi, Virtual Pascal, Turbo Pascal etc. and many want to use parts of their old code. These people do not sit down for months to find all the spread information that *may* be important for FindFirst, CopyFile, etc. They expect all releveant information at the docu for the functions.

+1

Show quoted text 7 lines
> Also : how do you think you'd guess encoding of a text file on disk > before reading it ? Some people don't like to have the decision taken > by the compiler for themselves... That's not what we are talking about here. If I understood Marcos problem correctly the topic was the output of another function where the encoding was unclear.

That was one of problems.

Show quoted text 12 lines
> Other area where this may be important: web applications. > Database fields may (each) have different encoding (and we would be able > to know it), > internals of the app would work on their own encoding (and we would know > it) > the web frontend may run on different encoding every time (and we would be > able to know it ) > (imagine somebody forces a certain encoding on their web browser and tells > the web app developer to support THAT) As long as you *know* about each encoding you can manage it. But if you have to guess the encoding then it will fail in general.

The major problem is work with FPC (Ansi), LCL (UTF8) and Console on Windows (UTF16)!

Show quoted text 11 lines
> I for one /like/ that The New Pascal has become highly customizable even > if > some things have to be more explicit than in Ye Olden Days... > It's still way more 'high level' than plain c that some people dub > 'assembler on drugs'.... I only see that everything that has been added since Delphi (mainly by Borland) is more C style than Pascal (pchar, operator overloading, context dependend meaning of indentifiers, poor documentation, etc.). The focus is more on a "me too" attitude (assimilation of all all other programming languages) and not on clear, easy and readable program code.

Marcos Douglas

Reply by email

Marcos Douglas
to Hans-Peter Diettrich: It would be much easier to use an TFileName string type instead, for self-documenting…
Hans-Peter Diettrich wrote 25 lines
Felipe Monteiro de Carvalho schrieb: > On Fri, Apr 13, 2012 at 5:18 PM, J?rgen Hestermann > wrote: >> >> But if you use a function from a (Free Pascal or Lazarus) library it is >> not >> clear which kind of encoding this function expects. As I already >> mentioned, >> for example CopyFile (from LCL) and FindFirst (from SysUtils) have no >> hint >> in their documentation on what encoding is expected. I know, somewhere it >> says that library x has enconding y but why wasn't this information >> written >> to the documentation for the indiviudal functions? > > > It would be a huge duplication of documentation to write in every > single Lazarus function that uses string that it expects UTF-8. It would be much easier to use an TFileName string type instead, for self-documenting declarations. DoDi

+1

Marcos Douglas

Reply by email

Marcos Douglas
to Mattias Gaertner: On Fri, 13 Apr 2012 17:18:37 +0200 Marcos didn't wrote what program he called. Maybe the…
Mattias Gaertner wrote 9 lines
On Fri, 13 Apr 2012 17:18:37 +0200 J?rgen Hestermann wrote: > Lukasz Sokol schrieb: > ?>> IMO it must be possible to predict the encoding of strings > ?>> when writing the code (without running the program). Marcos didn't wrote what program he called. Maybe the output is not even text.

The output is text.
The process I call is the ffmpeg ( http://ffmpeg.org ) tool.

[...] Mattias

Marcos Douglas

Reply by email

Mattias Gaertner
to Jürgen Hestermann: SysUtils) ??? What defaults? The topic is string encoding not defaults. I would like to.…
Show quoted text 14 lines
Mattias Gaertner schrieb: >> But if you use a function from a (Free Pascal or Lazarus) library it is >> not clear which kind of encoding this function expects. As I already >> mentioned, for example CopyFile (from LCL) and FindFirst (from SysUtils) >> have no hint in their documentation on what encoding is expected. I >> know, somewhere it says that library x has enconding y but why wasn't >> this information written to the documentation for the indiviudal >> functions? > > Normally defaults are not explained for every function of a > unit/package. ??? What defaults? The topic is string encoding not defaults.

All strings in the LCL are UTF-8 unless explicitly noted otherwise. There are more defaults for example coordinate systems.

> Feel free to add the encoding to those functions you think it is not > clear and send a patch. I would like to. But how do I get the information?

It's open source. You are a programmer. You have an IDE. How do you think others are getting the information?

You see the vicious circle?

Yes, but I hope others will not follow your example.

Show quoted text 14 lines
Or do you mean I should find out the encoding by trial and error for each function myself (bulding a test program around them) because this is the only way to get it? Who wants to program with such a programming language where encoding for function parameters is not documented? It seems it's for the hard core developers only. > A volunteer project like Lazarus requires the help of volunteers. Yes. If you send me a list of the expected/used string encoding for *all* function parameters then I can add this information to the documentation when I find out how to do that.

lol

Show quoted text 17 lines
How can I change it here: http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/copyfile.html ? >> That's not what we are talking about here. If I understood Marcos >> problem correctly the topic was the output of another function where the >> encoding was unclear. > What function are you talking? Have you read the example Marcos used? Well, I was mainly talking about any string parameter to any function in any library that comes with Free Pascal and/or Lazarus and I was under the impression that Marco's problem was based on the same issue: A string parameter is required ("Memo1.Lines.Append") but it is not clear what encoding is expected.

Read his first mail again. He used ConsoleToUTF8, which is correct, if the process prints in console encoding.

Show quoted text 8 lines
This isssue exists for *all* functions of Free Pascal and Lazarus that expect strings as parameters. I already mentioned the example of CopyFile: To my astonishment the function CopyFile not only exists in the unit Windows (where I expected it) but also in the LCL (with different string encoding). The same applies to FindFirst and other file functions.

Where do you see FindFirst with different encoding?

Mattias

Reply by email

Martin Schreiber
to Michael Van Canneyt: Because FindFirst is part of the RTL, and FindFirstUTF8 is part of Lazarus. FPC cannot…
Michael Van Canneyt wrote 5 lines
Also: Lazarus happened to choose UTF-8 as the encoding of their LCL. By contrast, MSEGui chose UTF-16 as it's encoding.

In order to differentiate from other string types and encodings MSEgui uses "msestring" in properties, variables and parameters. msestring is defined as
"
type
msestring = UnicodeString;
"
Martin

Reply by email

Marcos Douglas
to Jürgen Hestermann: SysUtils) ??? What defaults? The topic is string encoding not defaults. I would like to.…
J?rgen Hestermann wrote 61 lines
Mattias Gaertner schrieb: >> But if you use a function from a (Free Pascal or Lazarus) library it is >> not clear which kind of encoding this function expects. As I already >> mentioned, for example CopyFile (from LCL) and FindFirst (from SysUtils) >> have no hint in their documentation on what encoding is expected. I >> know, somewhere it says that library x has enconding y but why wasn't >> this information written to the documentation for the indiviudal >> functions? > > Normally defaults are not explained for every function of a > unit/package. ??? What defaults? The topic is string encoding not defaults. > Feel free to add the encoding to those functions you think it is not > clear and send a patch. I would like to. But how do I get the information? You see the vicious circle? Or do you mean I should find out the encoding by trial and error for each function myself (bulding a test program around them) because this is the only way to get it? Who wants to program with such a programming language where encoding for function parameters is not documented? It seems it's for the hard core developers only. > A volunteer project like Lazarus requires the help of volunteers. Yes. If you send me a list of the expected/used string encoding for *all* function parameters then I can add this information to the documentation when I find out how to do that. How can I change it here: http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/copyfile.html ? >> That's not what we are talking about here. If I understood Marcos >> problem correctly the topic was the output of another function where the >> encoding was unclear. > What function are you talking? Have you read the example Marcos used? Well, I was mainly talking about any string parameter to any function in any library that comes with Free Pascal and/or Lazarus and I was under the impression that Marco's problem was based on the same issue: A string parameter is required ("Memo1.Lines.Append") but it is not clear what encoding is expected. This isssue exists for *all* functions of Free Pascal and Lazarus that expect strings as parameters. I already mentioned the example of CopyFile: To my astonishment the function CopyFile not only exists in the unit Windows (where I expected it) but also in the LCL (with different string encoding). The same applies to FindFirst and other file functions.

IMHO, I think all functions (even classes) should be a prefix or use the own unit as a prefix, for these conflicts do not exist. Only FPC, the compiler, could be use "simple" names like CopyFile.

Examples
CopyFile (FPC)
LazCopyFile (LCL)

Just using a better organization. But these tips continues allowing declare CopyFile in my own sources so, should have mandatory to use unit as a prefix -- and should exists a sintaxe do use an "alias" (readable names) to units.

Marcos Douglas

Reply by email

Marcos Douglas
to Michael Van Canneyt: Because FindFirst is part of the RTL, and FindFirstUTF8 is part of Lazarus. FPC cannot…

2012/4/13 Michael Van Canneyt :

Show quoted text 55 lines
On Fri, 13 Apr 2012, J?rgen Hestermann wrote: > Felipe Monteiro de Carvalho schrieb: >> >> It is better to document this issues once in 1 single place. > > > Definitely not! Why is it such a problem so write the encoding type for a > function like CopyFile into the documentation for it? It belongs there. Of > course, there could also be a link to somewhere but it must be reachable > from the documentation of the function. The first information available is > this entry. When I have a question to any of these functions the first place > to go is google. And then I am stuck because there is no further information > about encoding of the string parameters. > > > And we already have a large documentation about all of >> >> this. Just read here: >> http://wiki.freepascal.org/LCL_Unicode_Support > > > Then this link has to be added to each of the affected functions. > How else should someone get there from the documentation of CopyFile for > example? > And it is only a very crude way to answer the simple question: > What encoding is expected to the string paramters of CopyFile (or > FindFirst)? > > >> About FindFirst, you should know that there is FindFirstUTF8: >> http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/findfirstutf8.html > > > Yes, but why do I get this information only after lengthy discussions in > this list? Why does no link appear unter "See also" in the FindFirst > documenation? Aren't you annoyed by all these questions here in the list? If > this would be answered in the documenation then it would not come up here > (and would not annoy and displease so many new joiners to Free Pascal). If > each and every parameter would have the same encoding then it would not be > such a problem but in this case where each function has its own encoding it > is essential. Because FindFirst is part of the RTL, and FindFirstUTF8 is part of Lazarus. FPC cannot refer to the lazarus docs. Also: Lazarus happened to choose UTF-8 as the encoding of their LCL. By contrast, MSEGui chose UTF-16 as it's encoding. Work is in progress to make the RTL Unicode Aware, and as soon as it is so, the encoding issues will be documented.

Cool.

Marcos Douglas

Reply by email

Marcos Douglas
to Martin Schreiber: In order to differentiate from other string types and encodings MSEgui uses "msestring"…
Martin Schreiber wrote 13 lines
On Friday 13 April 2012 18:51:42 Michael Van Canneyt wrote: > > Also: > Lazarus happened to choose UTF-8 as the encoding of their LCL. > By contrast, MSEGui chose UTF-16 as it's encoding. > In order to differentiate from other string types and encodings MSEgui uses "msestring" in properties, variables and parameters. msestring is defined as " type ?msestring = UnicodeString; "

But even so, we still can pass AnsiString <UTF8String, string, whatever> to a function:

type
  MyString = UnicodeString;
procedure Foo(const s: MyString);
begin
  ShowMessage(s);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  s: AnsiString;
begin
  s := 'hi';
  Foo(s);
end;

Marcos Douglas

Reply by email

Martin Schreiber
to Marcos Douglas
Marcos Douglas wrote
On Fri, Apr 13, 2012 at 2:59 PM, Martin Schreiber
Show quoted text 32 lines
> On Friday 13 April 2012 18:51:42 Michael Van Canneyt wrote: >> Also: >> Lazarus happened to choose UTF-8 as the encoding of their LCL. >> By contrast, MSEGui chose UTF-16 as it's encoding. > > In order to differentiate from other string types and encodings MSEgui > uses "msestring" in properties, variables and parameters. msestring is > defined as > " > type > ?msestring = UnicodeString; > " But even so, we still can pass AnsiString <UTF8String, string, whatever> to a function: type MyString = UnicodeString; procedure Foo(const s: MyString); begin ShowMessage(s); end; procedure TForm1.Button1Click(Sender: TObject); var s: AnsiString; begin s := 'hi'; Foo(s); end;

Yes. And if "s" is not in utf-8 but in current system encoding it even will be translated correctly in FPC 2.6.0. ;-)
But IIRC the question was about the documentation of the encoding of framework procedure or function parameters. If the types are "lazstring" or "utf8string" the expected encoding is clear.

Martin

Reply by email

Hans-Peter Diettrich
to Jürgen Hestermann: Huh? Now I know why it is as it is. How can you say that all this is obvious? Why is it…
When I use a function that I used before (in Turbo Pascal, Virtual Pascal, Delphi) but now want to use with Free Pascal (Lazarus) then the first thing is to google for it.

Have you ever opened the FPDoc Editor window? In the trunk version the available documentation also is displayed in a hint window, when moving the mouse over source code.

Show quoted text 16 lines
For CopyFile I find a link to the documentation but it only says: ----------------------------------- const SrcFilename: String; const DestFilename: String SrcFilename The source filename for the Copy DestFilename The destination filename for the Copy ----------------------------------- String is generic so it can be pchar, shortstring or ansistring or .... But what is the encoding? It does not tell me. If the parameter I want to feed in comes from a different source (database, file, ...) where I know the encoding how do I find out to which encoding it has to be converted to?

The documentation definitely is in a bad state. I already tried to improve it, adding questions about omissions etc. which I couldn't answer myself. But it turned out that the Lazarus team is not willing to provide the missing information, so I stopped any further updates. As the only "improvement" a Notes section has been added to every documentation entry, where questions and rants can be added. But this new section is not visible nor editable in LazDE nor FPDocEditor, is not included in the final documentation (by default). So it also will stay a hidden and ignored Hall of Shame :-(

DoDi

Reply by email

Hans-Peter Diettrich
to Felipe Monteiro de Carvalho: On Fri, Apr 13, 2012 at 5:52 PM, J?rgen Hestermann I said that the ansistring example is…
About FindFirst, you should know that there is FindFirstUTF8: http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/findfirstutf8.html

You just revealed another problem in the documentation: While FindFirst is documented by FPC, but FindFirstUTF8 is a Lazarus extension, a user never will find a link to it in the FPC docs. Apart from that, FindFirstUTF8 is not

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Fri, 13 Apr 2012 17:18:37 +0200 Marcos didn't wrote what program he called. Maybe the…
A volunteer project like Lazarus requires the help of volunteers.

This requires support (documentation, answers...) that allows the volunteers to contribute.

I found above statement in many open source projects, which left the nasty or unsolvable problems to others, and mostly died sooner or later due to a lack of such "useful idiots". But in contrast to Lenin's idiots, which only have to be given a direction to go, this doesn't work when these idiots shall fill the documentation gaps left open by their leaders.

DoDi

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Fri, 13 Apr 2012 18:21:34 +0200 All strings in the LCL are UTF-8 unless explicitly…
Show quoted text 7 lines
> > Feel free to add the encoding to those functions you think it is not > > clear and send a patch. > > I would like to. But how do I get the information? It's open source. You are a programmer. You have an IDE. How do you think others are getting the information?

Information should be provided in a useful manner, not by pointing out ways how a *guru* might obtain it.

> You see the vicious circle? Yes, but I hope others will not follow your example.

You really hope so? :-(

I.e. you hope that others will give in before asking questions, which are required to improve the documentation? When they read in contributions (like yours) that they will never get substancial answers, and no real assistance by the core developers?

How much could have been changed in the documentation until now, when the contributing gurus had spent their time in improving it on every question, instead of defending their disgust of doing so themselves, over and over again?

Show quoted text 7 lines
> Or do you mean I should find out the encoding by trial and error for > each function > myself (bulding a test program around them) because this is the only way > to get it? > Who wants to program with such a programming language where encoding for > function parameters is not documented? > It seems it's for the hard core developers only.

Ah, no answer on these questions?

Show quoted text 7 lines
> > A volunteer project like Lazarus requires the help of volunteers. > > Yes. If you send me a list of the expected/used string encoding for *all* > function parameters then I can add this information to the documentation > when I find out how to do that. lol

What a nice and encouraging attitude :-(

DoDi

Reply by email

Sven Barth
to Jürgen Hestermann: Huh? Now I know why it is as it is. How can you say that all this is obvious? Why is it…
J?rgen Hestermann wrote 13 lines
----------------------------------- const SrcFilename: String; const DestFilename: String SrcFilename The source filename for the Copy DestFilename The destination filename for the Copy ----------------------------------- String is generic so it can be pchar, shortstring or ansistring or .... But what is the encoding? It does not tell me. If the parameter I want to feed in comes from a different source (database, file, ...) where I know the encoding how do I find out to which encoding it has to be converted to?

Please note that String can NEVER be PChar (though there is assignment compatibility between the two to some extent). The possible types for String are ShortString, AnsiString and maybe in the future (and in Delphi 2009+) UnicodeString.

Regards,
Sven

Reply by email

Hans-Peter Diettrich
to Marcos Douglas: On Fri, Apr 13, 2012 at 12:18 PM, J?rgen Hestermann +1 That was one of problems. The…
The major problem is work with FPC (Ansi), LCL (UTF8) and Console on Windows (UTF16)!

Then I'd suggest that you wait for the Unicode version of FPC/Lazarus, where all such problems have gone away. In the meantime you can do something less fruitless than pointing to well known problems, which never will solve themselves. Or spend the time to look for a tool that better fits your needs, coming with useful documentation...

DoDi

Reply by email

Sven Barth
to Martin Schreiber: Yes. And if "s" is not in utf-8 but in current system encoding it even will be translated…
Martin Schreiber wrote 37 lines
On Friday 13 April 2012 20:32:23 Marcos Douglas wrote: > On Fri, Apr 13, 2012 at 2:59 PM, Martin Schreiber wrote: >> On Friday 13 April 2012 18:51:42 Michael Van Canneyt wrote: >>> Also: >>> Lazarus happened to choose UTF-8 as the encoding of their LCL. >>> By contrast, MSEGui chose UTF-16 as it's encoding. >> >> In order to differentiate from other string types and encodings MSEgui >> uses "msestring" in properties, variables and parameters. msestring is >> defined as >> " >> type >> msestring = UnicodeString; >> " > > But even so, we still can pass AnsiString<UTF8String, string, > whatever> to a function: > > type > MyString = UnicodeString; > > procedure Foo(const s: MyString); > begin > ShowMessage(s); > end; > > procedure TForm1.Button1Click(Sender: TObject); > var > s: AnsiString; > begin > s := 'hi'; > Foo(s); > end; > Yes. And if "s" is not in utf-8 but in current system encoding it even will be translated correctly in FPC 2.6.0. ;-)

In that case it will also be translated correctly in 2.7.1. It will also be translated correctly if the AnsiString is defined as "AnsiString(CP_UTF8)" and has an UTF-8 encoded string in it.

Regards,
Sven

Reply by email

Jürgen Hestermann
to Sven Barth: Please note that String can NEVER be PChar (though there is assignment compatibility…
> String is generic so it can be pchar, shortstring or ansistring or .... Please note that String can NEVER be PChar (though there is

assignment compatibility between the two to some extent). The possible types for String are ShortString, AnsiString and maybe in the future (and in Delphi 2009+) UnicodeString.

So what? Can it NEVER be PChar or just SOMETIMES?
A small test program
----------------
procedure XTest(X : String);
begin
X := 'AA';
end;
var S : String;
      P : pchar;
begin
P := 'TEST';
S := P;
XTest(P);
end.
 ----------------
compiles without errors

Reply by email

Sven Barth
to Jürgen Hestermann
J?rgen Hestermann wrote 25 lines
Sven Barth schrieb: >> String is generic so it can be pchar, shortstring or ansistring or .... > Please note that String can NEVER be PChar (though there is assignment compatibility between the two to some extent). The possible types for String are ShortString, AnsiString and maybe in the future (and in Delphi 2009+) UnicodeString. So what? Can it NEVER be PChar or just SOMETIMES? A small test program ---------------- procedure XTest(X : String); begin X := 'AA'; end; var S : String; P : pchar; begin P := 'TEST'; S := P; XTest(P); end. ---------------- compiles without errors

There is a difference between "String" being a "PChar" and having internal type conversions between "String" and "PChar". The former is never the case while the second one is true.

"String" is defined as either being "AnsiString", "ShortString" or "UnicodeString" depending on the used compiler and settings.

Then again "PChar" is assignment compatible to "AnsiString", "ShortString" and "UnicodeString" and thus also to "String", as "String" is one of those three types. This does not mean though that "String" is a "PChar".

Regards,
Sven

Reply by email

Jürgen Hestermann
to Sven Barth
There is a difference between "String" being a "PChar" and having

internal type conversions between "String" and "PChar".

The former is never the case while the second one is true. "String" is defined as either being "AnsiString", "ShortString" or

"UnicodeString" depending on the used compiler and settings.

Then again "PChar" is assignment compatible to "AnsiString",

"ShortString" and "UnicodeString" and thus also to "String",

as "String" is one of those three types. This does not mean though

that "String" is a "PChar".

Yes, ok. I see now what you mean.
In the end it all seems to be some missunderstanding when Felipe wrote:

----------------------------------
It would be a huge duplication of documentation to write in every single Lazarus function that uses string that it expects UTF-8.

It would be like writing in every function that string means longstring (aka ansistring), that the routine is not using a shortstring ... well, this is obvious.
----------------------------------

where I answered:

----------------------------------
String is generic so it can be pchar, shortstring or ansistring or .... ----------------------------------

because I think that it is quite irrelevant what type of string (ShortString, AnsiString, pchar) is used for the parameter. My concern was the encoding of the string (UTF-8, ANSI, UTF-16 or ...). And you wrote:

----------------------------------
Please note that String can NEVER be PChar (though there is assignment compatibility between the two to some extent).
The possible types for String are ShortString, AnsiString and maybe in the future (and in Delphi 2009+) UnicodeString.
----------------------------------

I only wanted to point out that there is no relation between these two types of information about string parameters in functions:

1.) If a parameter is defined as STRING it can be fed with (nearly) any type of string like shortstring, ansistring, pchar or whatever. It will be converted automatically. There is no fundamental need for the programmer to know which type is actually used internally by the function.

2.) The expected encoding of a parameter. If no encoding is documented then an essential information is missing for the programmer.

So I don't understand Felipe when he says that giving information 2.) is like giving information 1.). They are not related and of very different importance.

Reply by email

Marcos Douglas
to Hans-Peter Diettrich: Then I'd suggest that you wait for the Unicode version of FPC/Lazarus, where all such…
Hans-Peter Diettrich wrote 12 lines
Marcos Douglas schrieb: > The major problem is work with FPC (Ansi), LCL (UTF8) and Console on > Windows (UTF16)! Then I'd suggest that you wait for the Unicode version of FPC/Lazarus, where all such problems have gone away. In the meantime you can do something less fruitless than pointing to well known problems, which never will solve themselves. Or spend the time to look for a tool that better fits your needs, coming with useful documentation...

Calm down.
I use FPC and Lazarus for real applications (on Windows) and I'm grateful for that; grateful for exists great developers working in the compiler and IDE, just using their free time...
I don't understand of compilers and Unicode is new to me. On Delphi (<=7) we do not have such problems, you know.
My comments are constructive criticism... sorry if I talked about "well known problems" but well known for who?

Marcos Douglas

Reply by email

Jürgen Hestermann
to Hans-Peter Diettrich: Have you ever opened the FPDoc Editor window? In the trunk version the available…
Have you ever opened the FPDoc Editor window?

No. Just tried it. Seems to be yet another tool do some kind of documentation. Can I use it to change the documenation of FindFirst and CopyFile? If yes, how? I cannot type anything into the two lines "Short:" and "Link:".

In the trunk version the available documentation also is displayed in

a hint window, when moving the mouse over source code.

Just tried this too and that's cool! If it works reliable it is definitely a nice thing. Though it does not redeem the missing documenation.

Reply by email

Jürgen Hestermann
to Marcos Douglas: On Sat, Apr 14, 2012 at 6:29 AM, Hans-Peter Diettrich Calm down. I use FPC and Lazarus…
I use FPC and Lazarus for real applications (on Windows) and I'm grateful for that; grateful for exists great developers working in the compiler and IDE, just using their free time...

+1

I don't understand of compilers and Unicode is new to me. On Delphi (<=7) we do not have such problems, you know. My comments are constructive criticism... sorry if I talked about "well known problems" but well known for who?

The problem is that the great advantage of Free Pascal and Lazarus of beeing available on multiple platforms has turned into a curse for those who work on one platform only. Suddenly they are confronted with things they usualy don't need to care about. And if in this situation the documentation is poor it becomes a real challenge to fight all these nasty little things instead of coding the program logic.

Reply by email

Marcos Douglas
to Sven Barth: In that case it will also be translated correctly in 2.7.1. It will also be translated…
Sven Barth wrote 51 lines
On 14.04.2012 07:20, Martin Schreiber wrote: > > On Friday 13 April 2012 20:32:23 Marcos Douglas wrote: >> >> On Fri, Apr 13, 2012 at 2:59 PM, Martin Schreiber > > wrote: >>> >>> On Friday 13 April 2012 18:51:42 Michael Van Canneyt wrote: >>>> >>>> Also: >>>> Lazarus happened to choose UTF-8 as the encoding of their LCL. >>>> By contrast, MSEGui chose UTF-16 as it's encoding. >>> >>> >>> In order to differentiate from other string types and encodings MSEgui >>> uses "msestring" in properties, variables and parameters. msestring is >>> defined as >>> " >>> type >>> ?msestring = UnicodeString; >>> " >> >> >> But even so, we still can pass AnsiString<UTF8String, string, >> whatever> ?to a function: >> >> type >> ? MyString = UnicodeString; >> >> procedure Foo(const s: MyString); >> begin >> ? ShowMessage(s); >> end; >> >> procedure TForm1.Button1Click(Sender: TObject); >> var >> ? s: AnsiString; >> begin >> ? s := 'hi'; >> ? Foo(s); >> end; >> > Yes. And if "s" is not in utf-8 but in current system encoding it even > will be > translated correctly in FPC 2.6.0. ;-) In that case it will also be translated correctly in 2.7.1. It will also be translated correctly if the AnsiString is defined as "AnsiString(CP_UTF8)" and has an UTF-8 encoded string in it.

I did understand.
I coded a console app (just FPC) on Windows:

program Project1;
{$mode objfpc}{$H+}
uses
  Classes, SysUtils;
var
  fname: UnicodeString;
  list: TStringList;
begin
  fname := 'c:\? b ?\?.txt';
  list := TStringList.Create;
  try
    list.LoadFromFile(fname);
    writeln(list.Text);
  finally
    list.Free;
  end;
end.

Should work? Here not worked...

Marcos Douglas

Reply by email

Marcos Douglas
to Jürgen Hestermann: +1 The problem is that the great advantage of Free Pascal and Lazarus of beeing available…
J?rgen Hestermann wrote 21 lines
Marcos Douglas schrieb: > I use FPC and Lazarus for real applications (on Windows) and I'm > grateful for that; grateful for exists great developers working in the > compiler and IDE, just using their free time... +1 > I don't understand of compilers and Unicode is new to me. On Delphi > (<=7) we do not have such problems, you know. > My comments are constructive criticism... sorry if I talked about > "well known problems" but well known for who? The problem is that the great advantage of Free Pascal and Lazarus of beeing available on multiple platforms has turned into a curse for those who work on one platform only. Suddenly they are confronted with things they usualy don't need to care about. And if in this situation the documentation is poor it becomes a real challenge to fight all these nasty little things instead of coding the program logic.

+1

Marcos Douglas

Reply by email

Hans-Peter Diettrich
to Jürgen Hestermann: No. Just tried it. Seems to be yet another tool do some kind of documentation. Can I use…
Show quoted text 7 lines
Hans-Peter Diettrich schrieb: > Have you ever opened the FPDoc Editor window? No. Just tried it. Seems to be yet another tool do some kind of documentation. Can I use it to change the documenation of FindFirst and CopyFile? If yes, how? I cannot type anything into the two lines "Short:" and "Link:".

You may have to press "Create help item" first, when the title bar shows "<NONE>".

Show quoted text 6 lines
> In the trunk version the available documentation also is displayed in a hint window, when moving the mouse over source code. Just tried this too and that's cool! If it works reliable it is definitely a nice thing. Though it does not redeem the missing documenation.

Every tool only can show existing facts, like previously entered descriptions ;-)

DoDi

Reply by email

Jürgen Hestermann
to Hans-Peter Diettrich
> > Have you ever opened the FPDoc Editor window? > No. Just tried it. Seems to be yet another tool do some kind of

documentation. Can I use it to change the documenation of FindFirst and CopyFile? If yes, how? I cannot type anything into the two lines "Short:" and "Link:".

You may have to press "Create help item" first, when the title bar

shows "<NONE>".

I found out now that I have to first put the cursor on the identifier to document ;-)

When I do this for CopyFile I get:

------------
No valid FPDOC path
The unit D:\Programme\lazarus\fpc\2.6.1\source\rtl\win32\windows.pp is part of the FPC souces, but the corresponding fpdoc xml file was not found. Either you have not yet added the fpcdocs directory to the search path or the unit is not yet documented. The fpdoc files for the FPC sources can be downloaded from: http://svn.freepascal.org/svn/fpcdocs/trunk ------------

When I go to "http://svn.freepascal.org/svn/fpcdocs/trunk" it is empty.

BTW: It's a shame that I had to type all the above text from the message window again because I could not copy/paste it. My own programs use "MessageBox" for such messges and the result *can* be copied with Ctrl+C. Why not from the IDE messages?

> > In the trunk version the available documentation also is

displayed in a hint window, when moving the mouse over source code.

> Just tried this too and that's cool! If it works reliable it is

definitely a nice thing. Though it does not redeem the missing documenation.

Every tool only can show existing facts, like previously entered

descriptions ;-)

Exactly. Therefore I was confused to see this as an answer for the topic of missing documentation :-)

Reply by email

Sven Barth
to Marcos Douglas: I did understand. I coded a console app (just FPC) on Windows: program Project1; {$mode…
Marcos Douglas wrote 78 lines
On Sat, Apr 14, 2012 at 6:36 AM, Sven Barth wrote: > On 14.04.2012 07:20, Martin Schreiber wrote: >> >> On Friday 13 April 2012 20:32:23 Marcos Douglas wrote: >>> >>> On Fri, Apr 13, 2012 at 2:59 PM, Martin Schreiber >> >> wrote: >>>> >>>> On Friday 13 April 2012 18:51:42 Michael Van Canneyt wrote: >>>>> >>>>> Also: >>>>> Lazarus happened to choose UTF-8 as the encoding of their LCL. >>>>> By contrast, MSEGui chose UTF-16 as it's encoding. >>>> >>>> >>>> In order to differentiate from other string types and encodings MSEgui >>>> uses "msestring" in properties, variables and parameters. msestring is >>>> defined as >>>> " >>>> type >>>> msestring = UnicodeString; >>>> " >>> >>> >>> But even so, we still can pass AnsiString<UTF8String, string, >>> whatever> to a function: >>> >>> type >>> MyString = UnicodeString; >>> >>> procedure Foo(const s: MyString); >>> begin >>> ShowMessage(s); >>> end; >>> >>> procedure TForm1.Button1Click(Sender: TObject); >>> var >>> s: AnsiString; >>> begin >>> s := 'hi'; >>> Foo(s); >>> end; >>> >> Yes. And if "s" is not in utf-8 but in current system encoding it even >> will be >> translated correctly in FPC 2.6.0. ;-) > > > In that case it will also be translated correctly in 2.7.1. It will also be > translated correctly if the AnsiString is defined as "AnsiString(CP_UTF8)" > and has an UTF-8 encoded string in it. I did understand. I coded a console app (just FPC) on Windows: program Project1; {$mode objfpc}{$H+} uses Classes, SysUtils; var fname: UnicodeString; list: TStringList; begin fname := 'c:\? b ?\?.txt'; list := TStringList.Create; try list.LoadFromFile(fname); writeln(list.Text); finally list.Free; end; end. Should work? Here not worked...

It won't work when interfacing with system functionality (like file loading) for now. At least on Windows, because there FPC still uses the Ansi (single character encoding) functions of the Windows API, but for your example to work it would need the WideString functions. This change was discussed some time ago, but I don't know what the final decission was...

Regards,
Sven

Reply by email

Sven Barth
to Jürgen Hestermann: internal type conversions between "String" and "PChar". "UnicodeString" depending on the…
J?rgen Hestermann wrote 14 lines
I only wanted to point out that there is no relation between these two types of information about string parameters in functions: 1.) If a parameter is defined as STRING it can be fed with (nearly) any type of string like shortstring, ansistring, pchar or whatever. It will be converted automatically. There is no fundamental need for the programmer to know which type is actually used internally by the function. 2.) The expected encoding of a parameter. If no encoding is documented then an essential information is missing for the programmer. So I don't understand Felipe when he says that giving information 2.) is like giving information 1.). They are not related and of very different importance.

I agree with you here that it would be viable to have in some way noted in LCL's documentation of functions what encoding they expect (even if it's only a link to some general document that says "the LCL uses UTF-8").

Regards,
Sven

Reply by email

Hans-Peter Diettrich
to Jürgen Hestermann: documentation. Can I use it to change the documenation of FindFirst and CopyFile? If yes,…
Show quoted text 24 lines
Hans-Peter Diettrich schrieb: >> > Have you ever opened the FPDoc Editor window? >> No. Just tried it. Seems to be yet another tool do some kind of documentation. Can I use it to change the documenation of FindFirst and CopyFile? If yes, how? I cannot type anything into the two lines "Short:" and "Link:". > You may have to press "Create help item" first, when the title bar shows "<NONE>". I found out now that I have to first put the cursor on the identifier to document ;-) When I do this for CopyFile I get: ------------ No valid FPDOC path The unit D:\Programme\lazarus\fpc\2.6.1\source\rtl\win32\windows.pp is part of the FPC souces, but the corresponding fpdoc xml file was not found. Either you have not yet added the fpcdocs directory to the search path or the unit is not yet documented. The fpdoc files for the FPC sources can be downloaded from: http://svn.freepascal.org/svn/fpcdocs/trunk ------------ When I go to "http://svn.freepascal.org/svn/fpcdocs/trunk" it is empty.

Not here, try again.

BTW: It's a shame that I had to type all the above text from the message window again because I could not copy/paste it. My own programs use "MessageBox" for such messges and the result *can* be copied with Ctrl+C. Why not from the IDE messages?

+1

File an bug/feature request?

DoDi

Reply by email

Marcos Douglas
to Sven Barth: It won't work when interfacing with system functionality (like file loading) for now. At…
Sven Barth wrote 100 lines
On 14.04.2012 15:39, Marcos Douglas wrote: > > On Sat, Apr 14, 2012 at 6:36 AM, Sven Barth > ?wrote: >> >> On 14.04.2012 07:20, Martin Schreiber wrote: >>> >>> >>> On Friday 13 April 2012 20:32:23 Marcos Douglas wrote: >>>> >>>> >>>> On Fri, Apr 13, 2012 at 2:59 PM, Martin Schreiber >>> >>> >>> wrote: >>>>> >>>>> >>>>> On Friday 13 April 2012 18:51:42 Michael Van Canneyt wrote: >>>>>> >>>>>> >>>>>> Also: >>>>>> Lazarus happened to choose UTF-8 as the encoding of their LCL. >>>>>> By contrast, MSEGui chose UTF-16 as it's encoding. >>>>> >>>>> >>>>> >>>>> In order to differentiate from other string types and encodings MSEgui >>>>> uses "msestring" in properties, variables and parameters. msestring is >>>>> defined as >>>>> " >>>>> type >>>>> ?msestring = UnicodeString; >>>>> " >>>> >>>> >>>> >>>> But even so, we still can pass AnsiString<UTF8String, string, >>>> whatever> ? ?to a function: >>>> >>>> type >>>> ? MyString = UnicodeString; >>>> >>>> procedure Foo(const s: MyString); >>>> begin >>>> ? ShowMessage(s); >>>> end; >>>> >>>> procedure TForm1.Button1Click(Sender: TObject); >>>> var >>>> ? s: AnsiString; >>>> begin >>>> ? s := 'hi'; >>>> ? Foo(s); >>>> end; >>>> >>> Yes. And if "s" is not in utf-8 but in current system encoding it even >>> will be >>> translated correctly in FPC 2.6.0. ;-) >> >> >> >> In that case it will also be translated correctly in 2.7.1. It will also >> be >> translated correctly if the AnsiString is defined as >> "AnsiString(CP_UTF8)" >> and has an UTF-8 encoded string in it. > > > I did understand. > I coded a console app (just FPC) on Windows: > > program Project1; > > {$mode objfpc}{$H+} > > uses > ? Classes, SysUtils; > > var > ? fname: UnicodeString; > ? list: TStringList; > begin > ? fname := 'c:\? b ?\?.txt'; > ? list := TStringList.Create; > ? try > ? ? list.LoadFromFile(fname); > ? ? writeln(list.Text); > ? finally > ? ? list.Free; > ? end; > end. > > Should work? Here not worked... It won't work when interfacing with system functionality (like file loading) for now. At least on Windows, because there FPC still uses the Ansi (single character encoding) functions of the Windows API, but for your example to work it would need the WideString functions. This change was discussed some time ago, but I don't know what the final decission was...
Well, works if I change this line:
  fname := 'c:\? b ?\?.txt';
to this:
  fname := UTF8Decode('c:\? b ?\?.txt');

And doesn't matter if fname is UnicodeString or string -- well, the debug hint to 'UnicodeString' is more beautiful than 'string' because the compiler translate.

But I ask:
A simple console program, on Windows, only using RTL, uses UTF8? I think not, but why I have to use UTF8 functions?

If RTL is AnsiString (for now), why we have UTF8 functions in RTL? Is part of the RTL or just utilities? Do not is better have this functions in a better unit name like utf8utils.pas or something like that?

Marcos Douglas

Reply by email

Marco van de Voort
to Marcos Douglas: On Fri, Apr 13, 2012 at 12:18 PM, J?rgen Hestermann +1 That was one of problems. The…
Marcos Douglas wrote 5 lines
> As long as you *know* about each encoding you can manage it. But if you have > to guess the encoding then it will fail in general. The major problem is work with FPC (Ansi), LCL (UTF8) and Console on Windows (UTF16)!

FPC Console and (base) Windows API is currently specified as ansi in FPC. (the ansi versions are the default type).

Only newer units that don't have ansi equivalents anymore are mandatory 2-byte.

Reply by email

Martin Schreiber
to Marcos Douglas: Well, works if I change this line: fname := 'c:\? b ?\?.txt'; to this: fname :=…
Marcos Douglas wrote 10 lines
Well, works if I change this line: fname := 'c:\? b ?\?.txt'; to this: fname := UTF8Decode('c:\? b ?\?.txt'); And doesn't matter if fname is UnicodeString or string -- well, the debug hint to 'UnicodeString' is more beautiful than 'string' because the compiler translate.

Add {$codepage utf8} to the unit header or compile with -Fcutf8, this is the default setting in MSEide+MSEgui for automatic Unicode handling. Warning: most likely this setting will break Lazarus on FPC 2.6.0. I don't know if Lazarus is fully tested with cpstrnew and -Fcutf8 already.

Martin

Reply by email

Michael Van Canneyt
to Jürgen Hestermann
J?rgen Hestermann wrote 8 lines
>>> When I go to "http://svn.freepascal.org/svn/fpcdocs/trunk" it is empty. I just found out that active scripting is required for this web page (I use the FireFox NoScript plugin). Is there a reason for this?

You are wrong. No scripting is needed for this page.

It is simply not meant for viewing in a browser, it returns XML used by a SVN client.

If you want to browse the repository, use the viewvc interface:

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/?root=docs

Michael.

Reply by email

Mattias Gaertner
to Martin Schreiber: Add {$codepage utf8} to the unit header or compile with -Fcutf8, this is the default…
Show quoted text 15 lines
On Saturday 14 April 2012 22:36:02 Marcos Douglas wrote: > > Well, works if I change this line: > fname := 'c:\? b ?\?.txt'; > to this: > fname := UTF8Decode('c:\? b ?\?.txt'); > > And doesn't matter if fname is UnicodeString or string -- well, the > debug hint to 'UnicodeString' is more beautiful than 'string' because > the compiler translate. > Add {$codepage utf8} to the unit header or compile with -Fcutf8, this is the default setting in MSEide+MSEgui for automatic Unicode handling. Warning: most likely this setting will break Lazarus on FPC 2.6.0. I don't know if Lazarus is fully tested with cpstrnew and -Fcutf8 already.

cpstrnew is part of fpc 2.7.1 and Lazarus runs fine with it since two months.

The -Fcutf8 and {$codepage utf8} exists since ages.

There are some traps with -Fcutf8 and {$codepage utf8}. It only works if the RTL DefaultSystemCodePage is CP_UTF8. Otherwise your strings are converted by the compiler.
For example under Linux the RTL default is CP_ACP, which defaults to ISO_8859-1. The RTL does *not* read your environment language on its own. So the the default is ISO_8859-1. This means your UTF-8 string constants are converted by the compiler:

Compile this with -Fcutf8 and run it on a Linux with LANG set to utf-8:

program project1;
{$mode objfpc}{$H+}
begin
  writeln(DefaultSystemCodePage,' ',CP_UTF8);
  writeln('?');
end.

This results in
0 65001
??

The LCL uses a widestringmanager (at the moment cwstring), which sets the DefaultSystemCodePage. You can do the same in your non LCL programs:

program project1;
{$mode objfpc}{$H+}
uses cwstring;
begin
  writeln(DefaultSystemCodePage,' ',CP_UTF8);
  writeln('?');
end.

This results in
65001 65001
?

The above is a lie for kids.
See the program below:

program project1;
{$mode objfpc}{$H+}
uses cwstring;
var
  a,b,c: string;
begin
  writeln(ord(DefaultSystemCodePage),' ',CP_UTF8);
  a:='?'; b:='='#$C3#$A4; // #$C3#$A4 is UTF-8 for ?
  c:=       '?='#$C3#$A4;
  writeln(a,b); // writes ?=?
  writeln(c);   // writes ?=??
end.

You can see that an UTF-8 string constant works, a string constant with UTF-8 codes works too, but the combination does not work. The above was compiled with -Fcutf8 and uses cwstring to set the DefaultSystemCodePage to CP_UTF8. So what went wrong? The compiler treats any non ascii string constant (here: the ?) as widestring (not UTF-16).

You can not fool the compiler with '?='+#$C3#$A4. You must define two separate string constants.

Using any character outside the UCS-2 range results in Fatal: illegal character "'?'" ($F0)

You can specify them with UTF-16 codes: #$D834#$DD1E Yes, you read right. Specifying the codepage with -Fcutf8 or {$codepage utf8} actually defines a mix of UTF-8 and UTF-16.

Now compile the above without -Fcutf8:

65001 65001
?=?
?=?

Wow, everything looks as expected. You can even mix ascii and non ascii string constants. Without the codepage the compiler stores string constants as byte sequences. That's what UTF-8 is.

That's why the LCL applications do not use the codepage flags.

msegui has implemented an ecosystem of widestrings, so it works better with a codepage.

Mattias

Reply by email

Martin Schreiber
to Mattias Gaertner
Mattias Gaertner wrote 6 lines
cpstrnew is part of fpc 2.7.1 and Lazarus runs fine with it since two months. The -Fcutf8 and {$codepage utf8} exists since ages.

I meant the combination of -Fcutf8, cpstrnew, and the Lazarus UTF8String which should be possible in FPC trunk but is not fully tested up to now maybe.

Martin

Reply by email

Mattias Gaertner
to Martin Schreiber
Show quoted text 9 lines
On Sunday 15 April 2012 11:32:21 Mattias Gaertner wrote: > > cpstrnew is part of fpc 2.7.1 and Lazarus runs fine with it since two > months. > > The -Fcutf8 and {$codepage utf8} exists since ages. > I meant the combination of -Fcutf8, cpstrnew, and the Lazarus UTF8String which should be possible in FPC trunk but is not fully tested up to now maybe.

I'm not sure what you mean with "the Lazarus UTF8String".

There is UTF8String = type AnsiString(CP_UTF8) defined in system.pp.

Under Linux and OS X any LCL application gets
DefaultSystemCodePage:=CP_UTF8, so all strings without an encoding are treated as CP_UTF8, which means encoded as UTF8String.

Maybe Paul can explain the details for MS Windows.

This does not change the fact that the -Fcutf8 and {$codepage utf8} have some drawbacks.

Mattias

Reply by email

Martin Schreiber
to Mattias Gaertner
Mattias Gaertner wrote 17 lines
On Sun, 15 Apr 2012 11:44:15 +0200 Martin Schreiber wrote: > On Sunday 15 April 2012 11:32:21 Mattias Gaertner wrote: > > cpstrnew is part of fpc 2.7.1 and Lazarus runs fine with it since two > > months. > > > > The -Fcutf8 and {$codepage utf8} exists since ages. > > I meant the combination of -Fcutf8, cpstrnew, and the Lazarus UTF8String > which should be possible in FPC trunk but is not fully tested up to now > maybe. I'm not sure what you mean with "the Lazarus UTF8String". There is UTF8String = type AnsiString(CP_UTF8) defined in system.pp.

I assume Lazarus uses that string type everywhere where it expects utf-8, same as MSEgui uses msestring (=UnicodeString) everywhere it expects utf-16?

Martin

Reply by email

Mattias Gaertner
to Martin Schreiber
Show quoted text 20 lines
On Sunday 15 April 2012 12:35:08 Mattias Gaertner wrote: > On Sun, 15 Apr 2012 11:44:15 +0200 > > Martin Schreiber wrote: > > On Sunday 15 April 2012 11:32:21 Mattias Gaertner wrote: > > > cpstrnew is part of fpc 2.7.1 and Lazarus runs fine with it since two > > > months. > > > > > > The -Fcutf8 and {$codepage utf8} exists since ages. > > > > I meant the combination of -Fcutf8, cpstrnew, and the Lazarus UTF8String > > which should be possible in FPC trunk but is not fully tested up to now > > maybe. > > I'm not sure what you mean with "the Lazarus UTF8String". > > There is UTF8String = type AnsiString(CP_UTF8) defined in system.pp. > I assume Lazarus uses that string type everywhere where it expects utf-8, same as MSEgui uses msestring (=UnicodeString) everywhere it expects utf-16?

UnicodeString has a clear advantage versus WideString (reference counting).

I don't see the clear advantage of UTF8String.
Using UTF8String instead of String (CP_UTF8 or CP_ACP) forces strings to CP_UTF8. This may slow down some assignments, may speed up some assignments or break some assignments.
Some benchmarks could be done, but I fear it is too early for that.

Mattias

Reply by email

Martin Schreiber
to Mattias Gaertner
Mattias Gaertner wrote 13 lines
On Sun, 15 Apr 2012 13:00:12 +0200 > I assume Lazarus uses that string type everywhere where it expects utf-8, > same as MSEgui uses msestring (=UnicodeString) everywhere it expects > utf-16? UnicodeString has a clear advantage versus WideString (reference counting). I don't see the clear advantage of UTF8String. Using UTF8String instead of String (CP_UTF8 or CP_ACP) forces strings to CP_UTF8. This may slow down some assignments, may speed up some assignments or break some assignments.

Now I don't understand, sorry. :-)
UTF8String = type AnsiString(CP_UTF8), is there another string type with CP_UTF8? What is the definition of "string" in cpstrnew? AnsiString(CP_ACP)? http://wiki.freepascal.org/FPC_Unicode_support does not answer the question AFAIK.
Hmm, I checked the Lazarus source, it seems I was wrong with the assumption that Lazarus uses "UTF8String" everywhere, it uses "String" instead, correct?

Example:
type
  TTranslateString = type String;
  TCaption = TTranslateString;

TControl = class(TLCLComponent)
[...]

    property Text: TCaption read GetText write SetText;

TCustomEdit = class(TWinControl)
[...]

    property SelText: String read GetSelText write SetSelText;

Martin

Reply by email

Mattias Gaertner
to Martin Schreiber
Show quoted text 16 lines
On Sunday 15 April 2012 13:33:05 Mattias Gaertner wrote: > On Sun, 15 Apr 2012 13:00:12 +0200 > > > I assume Lazarus uses that string type everywhere where it expects utf-8, > > same as MSEgui uses msestring (=UnicodeString) everywhere it expects > > utf-16? > > UnicodeString has a clear advantage versus WideString (reference > counting). > > I don't see the clear advantage of UTF8String. > Using UTF8String instead of String (CP_UTF8 or CP_ACP) forces strings > to CP_UTF8. This may slow down some assignments, may speed up some > assignments or break some assignments. Now I don't understand, sorry. :-)

No problem. The codepage strings are very new and I don't know yet all the details neither. So maybe some of my information is outdated or will soon be outdated.

UTF8String = type AnsiString(CP_UTF8), is there another string type with CP_UTF8? What is the definition of "string" in cpstrnew? AnsiString(CP_ACP)? http://wiki.freepascal.org/FPC_Unicode_support does not answer the question AFAIK.

This page is pretty outdated. I guess the fpc cpstrnew developers will update it when the dust has settled down.

Hmm, I checked the Lazarus source, it seems I was wrong with the assumption that Lazarus uses "UTF8String" everywhere, it uses "String" instead, correct?

Yes.

Show quoted text 12 lines
Example: type TTranslateString = type String; TCaption = TTranslateString; TControl = class(TLCLComponent) [...] property Text: TCaption read GetText write SetText; TCustomEdit = class(TWinControl) [...] property SelText: String read GetSelText write SetSelText;

The cpstrnew adds to every ansistring a codepage.
This codepage is like "length" and "reference count": it can be changed at runtime. This is usually done by assigning it to another string.

For example:

var s: string = 'a';
writeln(StringCodePage(s)); // writes 0 = CP_ACP
var u: utf8string = 'a';
writeln(StringCodePage(u)); // writes 65001 = CP_UTF8

With -Fcutf8 and without.

Assigning utf8string to a string:
s:=u;
writeln(StringCodePage(s)); // writes 65001 = CP_UTF8
Assigning a string (CP_ACP) to utf8string:
s:='a';
u:=s; // auto convert CP_ACP to CP_UTF8
writeln(StringCodePage(u)); // writes 65001 = CP_UTF8

Basically if you use "utf8string" you get a string that forces UTF-8.

Mattias

Reply by email

Marco van de Voort
to Mattias Gaertner: On Sun, 15 Apr 2012 11:44:15 +0200 I'm not sure what you mean with "the Lazarus…
Mattias Gaertner wrote 7 lines
I'm not sure what you mean with "the Lazarus UTF8String". There is UTF8String = type AnsiString(CP_UTF8) defined in system.pp. Under Linux and OS X any LCL application gets DefaultSystemCodePage:=CP_UTF8, so all strings without an encoding are treated as CP_UTF8, which means encoded as UTF8String.

Under OSes that have UTF-8 as default 1 byte encoding, CP_ACP should behave as if it were UTF-8.

The whole idea is that you mark the outside world with CP_ACP, and your own internal encoding UTF-8. (or unicodestring, the principle doesn't depend on that), and the RTL makes the conversion from ACP to UTF8 automatically.

So manually setting CP_UTF8 as system encoding is a workaround, not a long term solution.

Reply by email

Martin Schreiber
to Mattias Gaertner: On Sun, 15 Apr 2012 14:25:51 +0200 No problem. The codepage strings are very new and I…
Mattias Gaertner wrote
Basically if you use "utf8string" you get a string that forces UTF-8.

And if you use "String" (= AnsiString(CP_ACP) if my assumption about current FPC trunk is correct) it forces it to the 8bit system encoding. The only stringtype which does not enforce encoding is "RawByteString". All "AFAIK" of course. ;-)

Martin

Reply by email

Marco van de Voort
to Martin Schreiber
Martin Schreiber wrote 6 lines
> Basically if you use "utf8string" you get a string that forces UTF-8. > And if you use "String" (= AnsiString(CP_ACP) if my assumption about current FPC trunk is correct) it forces it to the 8bit system encoding. The only stringtype which does not enforce encoding is "RawByteString". All "AFAIK" of course. ;-)

That's correct. But in Windows, you use Windows functions for conversion, and CP_ACP is a valid value there. On *nix, you first have to find out what the local encoding is, and it seems that Mattias is detecting a problem there.

Be careful with assuming too much about RawBytestring being a normal type. In Delphi it is afaik only used in parameters (and function return values), more or less as a kind of open array type.

There are no variables of the type "rawbytestring" defined.

Reply by email

Martin Schreiber
to Marco van de Voort
Marco van de Voort wrote 19 lines
On Sun, Apr 15, 2012 at 03:24:32PM +0200, Martin Schreiber wrote: > > Basically if you use "utf8string" you get a string that forces UTF-8. > > And if you use "String" (= AnsiString(CP_ACP) if my assumption about > current FPC trunk is correct) it forces it to the 8bit system encoding. > The only stringtype which does not enforce encoding is "RawByteString". > All "AFAIK" of course. ;-) That's correct. But in Windows, you use Windows functions for conversion, and CP_ACP is a valid value there. On *nix, you first have to find out what the local encoding is, and it seems that Mattias is detecting a problem there. Be careful with assuming too much about RawBytestring being a normal type. In Delphi it is afaik only used in parameters (and function return values), more or less as a kind of open array type. There are no variables of the type "rawbytestring" defined.

And probably Mattias is wrong if he thinks "String" in FPC trunk does not enforce encoding if I understood correctly.

Martin

Reply by email

Graeme Geldenhuys
to Martin Schreiber: I assume Lazarus uses that string type everywhere where it expects utf-8, same as MSEgui…
Martin Schreiber wrote
as MSEgui uses msestring (=UnicodeString) everywhere it expects utf-16?

Sorry to nitpick, but I presume you meant "everywhere it expects UCS2". MSEgui doesn't fully support UTF-16, and UCS2 UTF-16.

ps:
I'm with Mattias on the -Fcutf8 being able to cause troubles with string type. Not specifying it makes the compiler treat string as a sequence of bytes - this is perfect for UTF-8.

Regards, ? - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

Graeme Geldenhuys
to Mattias Gaertner: On Sun, 15 Apr 2012 14:25:51 +0200 No problem. The codepage strings are very new and I…
Mattias Gaertner wrote
This page is pretty outdated. I guess the fpc cpstrnew developers will update it when the dust has settled down.

Yeah, it would be nice if we can get a progress report every now and again to the status of fpc cpstrnew. After all, this might have a big (or small) impact on framework developers.

Regards, ? - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

Mattias Gaertner
to Martin Schreiber: And probably Mattias is wrong if he thinks "String" in FPC trunk does not enforce…
Show quoted text 22 lines
On Sunday 15 April 2012 15:37:15 Marco van de Voort wrote: > On Sun, Apr 15, 2012 at 03:24:32PM +0200, Martin Schreiber wrote: > > > Basically if you use "utf8string" you get a string that forces UTF-8. > > > > And if you use "String" (= AnsiString(CP_ACP) if my assumption about > > current FPC trunk is correct) it forces it to the 8bit system encoding. > > The only stringtype which does not enforce encoding is "RawByteString". > > All "AFAIK" of course. ;-) > > That's correct. But in Windows, you use Windows functions for conversion, > and CP_ACP is a valid value there. On *nix, you first have to find out what > the local encoding is, and it seems that Mattias is detecting a problem > there. > > Be careful with assuming too much about RawBytestring being a normal type. > In Delphi it is afaik only used in parameters (and function return values), > more or less as a kind of open array type. > > There are no variables of the type "rawbytestring" defined. > And probably Mattias is wrong if he thinks "String" in FPC trunk does not enforce encoding if I understood correctly.

"string" enforces an 8-bit type.
It does not enforce a specific codepage like utf8string. At least under Linux.
Assign a CP_UTF8 and the string becomes CP_UTF8, assign a CP_ACP and it becomes CP_ACP, assign a CP_UTF16 and it becomes DefaultSystemCodePage. I have not tested under Windows.

Probably we should wait until the dust has settled before drawing conclusions.

Mattias

Reply by email

Jürgen Hestermann
to Michael Van Canneyt: You are wrong. No scripting is needed for this page. It is simply not meant for viewing…
Show quoted text 7 lines
>>>> When I go to "http://svn.freepascal.org/svn/fpcdocs/trunk" it is >>>> empty. > I just found out that active scripting is required for > this web page (I use the FireFox NoScript plugin). > Is there a reason for this? You are wrong. No scripting is needed for this page.

Well, if I look at this page with FireFox with scripting disabled I see nothing (white page).
If I allow scripting for "freepascal.org" I see directory structure (beginning with "trunk").
So it seems to make a difference whether I have scripting enabled or not.

It is simply not meant for viewing in a browser, it returns XML used by a SVN client.

Ok.

If you want to browse the repository, use the viewvc interface:

Well, I don't "want" it. I am just following hints that Hans-Peter gave me. It seems to be an odyssey just for changing documentation.

Yes, this works directly.

Reply by email

Martin Schreiber
to Mattias Gaertner: On Sun, 15 Apr 2012 15:58:24 +0200 "string" enforces an 8-bit type. It does not enforce a…
Mattias Gaertner wrote 9 lines
On Sun, 15 Apr 2012 15:58:24 +0200 Martin Schreiber wrote: > And probably Mattias is wrong if he thinks "String" in FPC trunk does not > enforce encoding if I understood correctly. "string" enforces an 8-bit type. It does not enforce a specific codepage like utf8string. At least under Linux.

"String" = "AnsiString(CP_APC)", quote:
"
Martin:

And if you use "String" (= AnsiString(CP_ACP) if my assumption about current FPC trunk is correct) it forces it to the 8bit system encoding. The only stringtype which does not enforce encoding is "RawByteString". All "AFAIK" of course. ;-)

Marco:
That's correct.
"

Assign a CP_UTF8 and the string becomes CP_UTF8, assign a CP_ACP and it becomes CP_ACP, assign a CP_UTF16 and it becomes DefaultSystemCodePage. I have not tested under Windows.

On most Linux CP_ACP is utf-8, on most Windows it is not utf-8.

Probably we should wait until the dust has settled before drawing conclusions.

We wait since several months. Anyway, as I wrote on lazarusforum.de, in the end it probably will be exactly like Delphi because Delphi compatibility has priority, maybe because several FPC core devels professionally work with Delphi.

http://www.lazarusforum.de/viewtopic.php?f=10&t=5855

Martin

Reply by email

Unknown author
to Jürgen Hestermann: Well, if I look at this page with FireFox with scripting disabled I see nothing (white…
J?rgen Hestermann wrote 12 lines
Michael Van Canneyt schrieb: >>>>> When I go to "http://svn.freepascal.org/svn/fpcdocs/trunk" it is empty. >> I just found out that active scripting is required for >> this web page (I use the FireFox NoScript plugin). >> Is there a reason for this? > > You are wrong. No scripting is needed for this page. Well, if I look at this page with FireFox with scripting disabled I see nothing (white page). If I allow scripting for "freepascal.org" I see directory structure (beginning with "trunk"). So it seems to make a difference whether I have scripting enabled or not.

I suspect that the fact that the server returns XML, not HTML, confuses the NoScript plugin.

If you look at the page source, you'll see there is absolutely no Javascript present. Just XML. And it is not shown in my browser either although I do not have the NoScript plugin.

Show quoted text 8 lines
> It is simply not meant for viewing in a browser, it returns XML used by a > SVN client. Ok. > > If you want to browse the repository, use the viewvc interface: Well, I don't "want" it. I am just following hints that Hans-Peter gave me. It seems to be an odyssey just for changing documentation.

The easy way is simply to report a bug in the bugtracker.

Then I'll look at it and either reply or correct the documentation.

Michael.

Reply by email

Mattias Gaertner
to Martin Schreiber: "String" = "AnsiString(CP_APC)", quote: " Martin: Marco: That's correct. " On most Linux…
Show quoted text 22 lines
On Monday 16 April 2012 00:04:41 Mattias Gaertner wrote: > On Sun, 15 Apr 2012 15:58:24 +0200 > > Martin Schreiber wrote: > > And probably Mattias is wrong if he thinks "String" in FPC trunk does not > > enforce encoding if I understood correctly. > > "string" enforces an 8-bit type. > It does not enforce a specific codepage like utf8string. At least under > Linux. "String" = "AnsiString(CP_APC)", quote: " Martin: > And if you use "String" (= AnsiString(CP_ACP) if my assumption about current > FPC trunk is correct) it forces it to the 8bit system encoding. The only > stringtype which does not enforce encoding is "RawByteString". > All "AFAIK" of course. ;-) Marco: That's correct. "

And your point is?
I only gave test results. "string" does not enforce CP_ACP under Linux with current FPC 2.7.1.

Show quoted text 15 lines
> Assign a CP_UTF8 and the string becomes CP_UTF8, assign a CP_ACP and it > becomes CP_ACP, assign a CP_UTF16 and it becomes DefaultSystemCodePage. > I have not tested under Windows. > On most Linux CP_ACP is utf-8, on most Windows it is not utf-8. > Probably we should wait until the dust has settled before drawing > conclusions. > We wait since several months. Anyway, as I wrote on lazarusforum.de, in the end it probably will be exactly like Delphi because Delphi compatibility has priority, maybe because several FPC core devels professionally work with Delphi. http://www.lazarusforum.de/viewtopic.php?f=10&t=5855

They will probably implement a very compatible solution. But the FPC team showed that they are capable of implementing and maintaining more than the Delphi mode.

Mattias

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich: You obviously talk about AnsiString, not the new String=UnicodeString. Do you see a…
Show quoted text 15 lines
Mattias Gaertner schrieb: >> And probably Mattias is wrong if he thinks "String" in FPC trunk does not >> enforce encoding if I understood correctly. > > "string" enforces an 8-bit type. You obviously talk about AnsiString, not the new String=UnicodeString. > It does not enforce a specific codepage like utf8string. At least under > Linux. > Assign a CP_UTF8 and the string becomes CP_UTF8, assign a CP_ACP and it > becomes CP_ACP, assign a CP_UTF16 and it becomes DefaultSystemCodePage. Do you see a difference between CP_ACP and DefaultSystemCodePage?

CP_ACP is a constant. DefaultSystemCodePage is a variable set to one of the CP_ constants.

In Delphi it's the same (by default), and AnsiString(0) is equivalent to AnsiString(CP_ACP).

CP_ACP is 0 under FPC too.

Mattias

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Sun, 15 Apr 2012 15:58:24 +0200 "string" enforces an 8-bit type. It does not enforce a…
> And probably Mattias is wrong if he thinks "String" in FPC trunk does not > enforce encoding if I understood correctly. "string" enforces an 8-bit type.

You obviously talk about AnsiString, not the new String=UnicodeString.

It does not enforce a specific codepage like utf8string. At least under Linux. Assign a CP_UTF8 and the string becomes CP_UTF8, assign a CP_ACP and it becomes CP_ACP, assign a CP_UTF16 and it becomes DefaultSystemCodePage.

Do you see a difference between CP_ACP and DefaultSystemCodePage? In Delphi it's the same (by default), and AnsiString(0) is equivalent to AnsiString(CP_ACP).

DoDi

Reply by email

Hans-Peter Diettrich
to Jürgen Hestermann: internal type conversions between "String" and "PChar". "UnicodeString" depending on the…
Show quoted text 8 lines
where I answered: ---------------------------------- String is generic so it can be pchar, shortstring or ansistring or .... ---------------------------------- because I think that it is quite irrelevant what type of string (ShortString, AnsiString, pchar) is used for the parameter.

Sorry, *generic* has nothing to do with string *assignment compatibility*. It means that String can be ShortString (long ago), and will become an UnicodeString soon.

PChar, ShortString and AnsiString are different types, but the compiler knows how to convert between each other.

DoDi

Reply by email

Ludo Brands
to Unknown author: I suspect that the fact that the server returns XML, not HTML, confuses the NoScript…
Show quoted text 22 lines
>>>>>> When I go to "http://svn.freepascal.org/svn/fpcdocs/trunk" it is >>>>>> empty. >>> I just found out that active scripting is required for >>> this web page (I use the FireFox NoScript plugin). >>> Is there a reason for this? >> >> You are wrong. No scripting is needed for this page. > Well, if I look at this page with FireFox with scripting disabled I > see > nothing (white page). > If I allow scripting for "freepascal.org" I see directory structure > (beginning with "trunk"). > So it seems to make a difference whether I have scripting enabled or not. I suspect that the fact that the server returns XML, not HTML, confuses the NoScript plugin. If you look at the page source, you'll see there is absolutely no Javascript present. Just XML. And it is not shown in my browser either although I do not have the NoScript plugin.

NoScript blocks XSLT by default. You can change this in the NoScript Options / Advanced / Untrusted panel, uncheck 'Forbid XSLT'. "http://svn.freepascal.org/svn/fpcdocs/trunk" uses XSLT to format the output. Start of http://svn.freepascal.org/svnindex.xsl called:

<!-- A sample XML transformation style sheet for displaying the Subversion directory listing that is generated by mod_dav_svn when the "SVNIndexXSLT" directive is used. -->

Ludo

Reply by email

Sven Barth
to Hans-Peter Diettrich: You obviously talk about AnsiString, not the new String=UnicodeString. Do you see a…
Hans-Peter Diettrich wrote 9 lines
Mattias Gaertner schrieb: >> And probably Mattias is wrong if he thinks "String" in FPC trunk does >> not enforce encoding if I understood correctly. > > "string" enforces an 8-bit type. You obviously talk about AnsiString, not the new String=UnicodeString.

As we are talking about FPC and not Delphi "String" still is "AnsiString" and not "UnicodeString".

Regards,
Sven

Reply by email

Lukasz Sokol
to Jürgen Hestermann: +1 The problem is that the great advantage of Free Pascal and Lazarus of beeing available…
J?rgen Hestermann wrote
The problem is that the great advantage of Free Pascal and Lazarus of beeing available on multiple platforms has turned into a curse for those who work on one platform only. Suddenly they are confronted with things they usualy don't need to care about.

I disagree this is multi-platform vs one-platform problem.

There are countless places where you have to care for the 'type of the string' you pass around even in Delphi <= Turbo (last version I used) if you have to interface with external (binary, C) libraries (binary dll's do as they like, some WinAPI functions commonly ask for POINTER to a string buffer and SIZE of it...). FPC/Lazarus handling is no different here - you only did not notice that because you did not have to use WinAPI or similar functions directly.

If you are advanced enough or just have to use these, string handling in the internals becomes suddenly very... simple and negligible. Just use String. If you need multi-language support, use [multi-byte-encoding-of-choice]String or wait till it's folded into String handling somewhere in the future. _Keep your choice consistent across your project_ no matter what you decide later.

And if in this situation the documentation is poor it becomes a real challenge to fight all these nasty little things instead of coding the program logic.
Programs := Algorithms[Logic] and Data Structures;

L.

Reply by email

waldo kitty
to Felipe Monteiro de Carvalho: On Fri, Apr 13, 2012 at 5:18 PM, J?rgen Hestermann It would be a huge duplication of…
Felipe Monteiro de Carvalho wrote 15 lines
On Fri, Apr 13, 2012 at 5:18 PM, J?rgen Hestermann wrote: > But if you use a function from a (Free Pascal or Lazarus) library it is not > clear which kind of encoding this function expects. As I already mentioned, > for example CopyFile (from LCL) and FindFirst (from SysUtils) have no hint > in their documentation on what encoding is expected. I know, somewhere it > says that library x has enconding y but why wasn't this information written > to the documentation for the indiviudal functions? It would be a huge duplication of documentation to write in every single Lazarus function that uses string that it expects UTF-8. It would be like writing in every function that string means longstring (aka ansistring), that the routine is not using a shortstring ... well, this is obvious.

actually, no it is not obvious... i still get bitten by this and i've been trying to get proficient with FPC/Lazarus for a year or more :? :(

Reply by email

waldo kitty
to Jürgen Hestermann: Huh? Now I know why it is as it is. How can you say that all this is obvious? Why is it…
J?rgen Hestermann wrote 12 lines
Felipe Monteiro de Carvalho schrieb: > It would be a huge duplication of documentation to write in every > single Lazarus function that uses string that it expects UTF-8. > It would be like writing in every function that string means > longstring (aka ansistring), that the routine is not using a > shortstring ... well, this is obvious. Huh? Now I know why it is as it is. How can you say that all this is obvious? Why is it obvious that FindFirst expects ANSI enconding while CopyFile needs UTF8. How should a programmer know this? It does not fall from sky.

+1000000000000000~!

When I use a function that I used before (in Turbo Pascal, Virtual Pascal, Delphi) but now want to use with Free Pascal (Lazarus) then the first thing is to google for it. For CopyFile I find a link to the documentation but it only says:

google, yes, to a point... but not everyone lives by google... especially those who are not on an always on network connection :? :(

but even so, google should NOT be required just to be a coder in pascal... too many seem to think that google is the do all, be all, end all of documentation :(

i cannot count the hours i've spent with google and some of the coding i've attempted to port over from TP/BP 6/7 with poor to no results that were anywhere near helpful :(

Reply by email

waldo kitty
to Hans-Peter Diettrich: The Delphi Unicode solution: set the proper encoding in TFileStream (? or TStringList),…
Hans-Peter Diettrich wrote 8 lines
J?rgen Hestermann schrieb: > IMO it must be possible to predict the encoding of strings > when writing the code (without running the program). The Delphi Unicode solution: set the proper encoding in TFileStream (? or TStringList), then the file is converted into UTF-16 on read, and back again when written to disk. Then the coder has to deal only with UnicodeStrings, and with AnsiStrings of codepage CP_ACP (system default) if ever required.

and for those, like myself, who never have seen delphi?? don't care about delphi because it seem(s|ed) to be a bastardization of the pascal language?? i don't even have a delphi book and cannot find one that comes close enough to lazarus to be of any benefit :(

Reply by email

waldo kitty
to Michael Van Canneyt: You are wrong. No scripting is needed for this page. It is simply not meant for viewing…
Michael Van Canneyt wrote 21 lines
On Sun, 15 Apr 2012, J?rgen Hestermann wrote: > > > >>>> When I go to "http://svn.freepascal.org/svn/fpcdocs/trunk" it is empty. > > I just found out that active scripting is required for > this web page (I use the FireFox NoScript plugin). > Is there a reason for this? You are wrong. No scripting is needed for this page. It is simply not meant for viewing in a browser, it returns XML used by a SVN client. If you want to browse the repository, use the viewvc interface: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/?root=docs

http does not denote that a browser is the default and main client to use for viewing this data?? that's a new one on me :? :(

Reply by email

Unknown author
to waldo kitty
waldo kitty wrote 26 lines
On 4/15/2012 05:25, Michael Van Canneyt wrote: > > > On Sun, 15 Apr 2012, J?rgen Hestermann wrote: > >> >> >> >>>>> When I go to "http://svn.freepascal.org/svn/fpcdocs/trunk" it is empty. >> >> I just found out that active scripting is required for >> this web page (I use the FireFox NoScript plugin). >> Is there a reason for this? > > You are wrong. No scripting is needed for this page. > > It is simply not meant for viewing in a browser, it returns XML used by a SVN > client. > > If you want to browse the repository, use the viewvc interface: > > http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/?root=docs http does not denote that a browser is the default and main client to use for viewing this data?? that's a new one on me :? :(

It does not. HTTP denotes a client/server communication protocol.

Nowhere does the HTTP protocol specify that the content must be displayable. It just happens to be the protocol used by a browser. And if the payload is HTML, then the browser can display it directly.

Michael.

Reply by email

waldo kitty
to Unknown author
Show quoted text 6 lines
On Mon, 16 Apr 2012, waldo kitty wrote: > On 4/15/2012 05:25, Michael Van Canneyt wrote: >>

[...]

Show quoted text 12 lines
>> If you want to browse the repository, use the viewvc interface: >> >> http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/?root=docs > > http does not denote that a browser is the default and main client to use for > viewing this data?? that's a new one on me :? :( It does not. HTTP denotes a client/server communication protocol. Nowhere does the HTTP protocol specify that the content must be displayable. It just happens to be the protocol used by a browser. And if the payload is HTML, then the browser can display it directly.

you are correct, of course... what i was trying to say/ask didn't come out correctly :? :(

Reply by email