Recent

Author Topic: Working with Unicode strings  (Read 6454 times)

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Working with Unicode strings
« on: June 05, 2020, 05:22:55 pm »
Hello!

I'm writing a Program like windows/notepad.exe
I'm using TMemo to show and edit the text, but It can't show unicode characters.
I changed the Font>Charset:
in the Form
In the Memo
and the coding of the source editor,
but not working

(I'm creating the memo(s) dynamically)
And the code:
« Last Edit: June 05, 2020, 05:24:34 pm by Jake012345 »

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: Working with Unicode strings
« Reply #1 on: June 05, 2020, 05:53:45 pm »
I'm writing a Program like windows/notepad.exe
I'm using TMemo to show and edit the text, but It can't show unicode characters.
I changed the Font>Charset:
in the Form
In the Memo
and the coding of the source editor,
but not working

(I'm creating the memo(s) dynamically)
What encoding is the file you are reading? Does it contain a BOM?

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Working with Unicode strings
« Reply #2 on: June 05, 2020, 06:06:36 pm »
EDITED
I don't know
simple .txt file
« Last Edit: June 05, 2020, 06:15:45 pm by Jake012345 »

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Working with Unicode strings
« Reply #3 on: June 05, 2020, 06:21:36 pm »
I couldn't understand what s the BOM but I want to write this program for multi language compatible.

The chinese characters not too important

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Working with Unicode strings
« Reply #4 on: June 05, 2020, 07:04:14 pm »
EDITED
I don't know
simple .txt file
A "simple" text file does not exist because the text can be written in various encodings, and often there is nothing in the file which tells about it, with the exception being that the file begins with a BOM (byte-order-mark) which tells whether the encoding is UTF8 or UTF16 or UTF32 (with variants for Big Endian and Little Endian byte orders).

When you load your film.txt file into Notepad there is a note in the statusbar that the file is an ANSI file, i.e. one of the old Windows files where the characters are arranged in "code pages" (256 characters max). Lazarus, however, expects the files to be UTF8 (without a BOM). So, you must either convert the file to UTF8 in an external editor like Notepad++ (menu "Encoding" > "Convert to UTF8 without BOM"), or you must do this in your code after reading each line by calling ConvertEncoding() from the unit LConvEncoding. Assuming the codepage of your file is CP1250 you do this:
Code: Pascal  [Select][+][-]
  1. var
  2.   s: RawByteString;
  3. ...
  4.   ReadLn(fileVar, s);
  5.   memo.Lines.Append(ConvertEncoding(s, EncodingCP1250, EncodingUTF8);
Of course, if you want a versatile solution your code must be flexible enough allow for other encodings. No conversion is required when the file is encoded as UTF8.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Working with Unicode strings
« Reply #5 on: June 05, 2020, 08:17:38 pm »
Thanks!!

I saw the 'show add tab buttons' and 'Show close buttons' in the page controls options property

They are theese: (attachment)?

And how can I use them?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Working with Unicode strings
« Reply #6 on: June 05, 2020, 09:18:07 pm »
For the "Close" button, add a handler for the OnCloseTabClicked event. I'm not sure about th "Add tab" button; never used it.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Working with Unicode strings
« Reply #7 on: June 06, 2020, 10:34:08 am »
That's not working..

Here's the code:

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Working with Unicode strings
« Reply #8 on: June 06, 2020, 11:38:07 am »
It works here: Laz/FPC 2.0.8/3.0.4 - Linux i386

Note, though, that instead of closing the currently active tab you should close the one pointed to by Sender, which is the one whose "Close" button was clicked:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PageControlCloseTabClicked(Sender: TObject);
  2. begin
  3.   if Assigned(Sender) and Sender.InheritsForm(TTabSheet) then
  4.     TTabSheet(Sender).Free;
  5. end;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Working with Unicode strings
« Reply #9 on: June 06, 2020, 11:48:47 am »
nothing...

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Working with Unicode strings
« Reply #10 on: June 06, 2020, 12:15:38 pm »
nothing...

Let me a little time to warm a Windows machine and test it there...
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Working with Unicode strings
« Reply #11 on: June 06, 2020, 12:30:36 pm »
 :D

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Working with Unicode strings
« Reply #12 on: June 06, 2020, 02:04:29 pm »
OK, I tested on two machines, Windows XP-SP3 and Windows 7 SK (both 32 bits), and none of them even showed the ("X") close button on the tabs, so that option is not very useful there.

Is that the problem you're having? Or are you seeing the button but it doesn't trigger the event?
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Working with Unicode strings
« Reply #13 on: June 06, 2020, 02:07:27 pm »
That's it

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Working with Unicode strings
« Reply #14 on: June 06, 2020, 02:31:49 pm »
That's it

Which of the two? Not seeing the button(s)? If so then bad luck, there's nothing you can do about it; the widgetset/OS simply doesn't support it.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018