Recent

Author Topic: TEncoding.GetEncoding with memo  (Read 7602 times)

cpalx

  • Hero Member
  • *****
  • Posts: 754
TEncoding.GetEncoding with memo
« on: July 04, 2016, 07:31:51 pm »
This work in delphi, How can i make it work in Laarus?


try
  Memo1.Lines.SaveT('d:/myfile.txt', TEncoding.GetEncoding('iso-8859-9'));
finally
//......
end;   

Bart

  • Hero Member
  • *****
  • Posts: 5648
    • Bart en Mariska's Webstek
Re: TEncoding.GetEncoding with memo
« Reply #1 on: July 04, 2016, 10:12:35 pm »
Not like in Delphi, but you can change the encoding of the strings you save.
The needed routies are in lconvencoding unit.

Bart

cpalx

  • Hero Member
  • *****
  • Posts: 754
Re: TEncoding.GetEncoding with memo
« Reply #2 on: July 05, 2016, 09:46:58 pm »
Code: Pascal  [Select][+][-]
  1.  Memo1.Text:= LConvEncoding.UTF8ToISO_8859_1( Memo1.Text );
  2.   Memo1.Lines.SaveToFile( 'd:/mytext.txt' )
  3.  
but does not work

rvk

  • Hero Member
  • *****
  • Posts: 6910
Re: TEncoding.GetEncoding with memo
« Reply #3 on: July 05, 2016, 10:16:39 pm »
but does not work
You shouldn't set the converted string back into the TMemo. It can't display ISO_8859_1 and will corrupt the string (or insert ?).

You need to put the converted string into a string which you can write to the file directly:
Code: Pascal  [Select][+][-]
  1. var
  2.   Fs: TFileStream;
  3.   Str: ansistring;
  4. begin
  5.   Fs := TFileStream.Create('d:\mytext.txt', fmCreate);
  6.   try
  7.     Str := LConvEncoding.UTF8ToISO_8859_1(Memo1.Text);
  8.     Fs.WriteBuffer(PAnsiChar(Str)^, Length(Str));
  9.   finally
  10.     Fs.Free;
  11.   end;
If you do this a lot in your program you might want to make a function for it.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4650
  • I like bugs.
Re: TEncoding.GetEncoding with memo
« Reply #4 on: July 05, 2016, 11:19:59 pm »
This work in delphi, How can i make it work in Laarus?
Code: Pascal  [Select][+][-]
  1. Memo1.Lines.SaveT('d:/myfile.txt', TEncoding.GetEncoding('iso-8859-9'));

I believe a patch for such method would be accepted.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018