Forum > General

Accented characters in SynEdit

(1/3) > >>

typo:
When I load a file through LoadFromFile method in SynEdit, the accented characters appear with a question mark. This does not occur when I paste text from clipboard. Why? What should I do to get the accented characters appear correctly?

Thanks.

Martin_fr:
Sounds like your file is not utf-8 encoded?

Your trying this in the IDE, or SynEdit in your own app?

In the IDE use the context menu of the source-editor => file settings, encoding

typo:
I am trying this in my app.

Why can I paste text from clipboard correctly? Why SynEdit does not do the same thing to load the file as it does to paste it from clipboard?

Martin_fr:
SynEdit does nothing itself to the clipboard.

The clipboard is accessed via the LCL, which (probably) translates the content to utf8. (assuming your clipboard isn't utf8 anyway).

The LCL doesn't convert the content of files, if you open a file. You have to make this call explicitly.

Neither the LCL nor SynEdit can know what encoding the content of a file is. This is because often the same binary file, can be correctly interpreted as many different encodings. (Or may not even be text, in which case the data would be destroyed, if an encoding conversion was done).

Zoran:
The contents of the file is probably not encoded in utf8. You should convert it. You can first load it in StringList using LoadFromFile, then you can use correct xxxxToUTF8 function from LConvEncoding unit.

--- Code: ---uses
   ... LConvEncoding;

...
var
  SL: TStringList;

...
  SL := TStringList.Create;
  try
    SL.LoadFromFile(yourfile.txt);
    SynEdit1.Lines.Text := CP1250ToUTF8(SL.Text);
  finally
    SL.Free;
  end;

--- End code ---

Of course, instead of CP1250ToUTF8, you should use correct function for your file's encoding (if it's greek, then CP1253ToUTF8, if it's cyrilic then CP1251ToUTF8...)

Navigation

[0] Message Index

[#] Next page

Go to full version