Load file into TAdvMemo with specified codepage

How do I specify a codepage to use when loading a document into TAdvMemo?

I'd like to be able to do something like this:



Similar to the standard TMemo, you can specify the encoding with


but it is not possible to specify the code page. You'd need to set AdvMemo.Font.CharSet according to the code page.

Thanks. This seems more limited though if it can only accept encodings like UTF8, ASCII, Unicode, and BigEndianUnicode. Someone please correct me if I'm wrong. :)

As explained, the codepage should be set via AdvMemo.Font.Charset.

That affects loading files into a MemoSource object? Isn't that only used for displaying the text in the memo with a certain font?

NOTE: I really wish this forum let you edit your posts but I don't see that option. I often like to go back and clarify things or make corrections in my posts and replies but it seems I can't do that in this forum.

  1. This doesn't affect loading file. There is no such capability to store along with a plain text file a code page. Setting the font.CharSet should be sufficient.
    2. Sorry, editing is preserved for admins. 

Hello Bruno,  

1. CSS, HTML and XML allow one to specify the encoding in the file. Currently, I search for that encoding before loading the file into the editor. With the current editor component I use, I can specify a codepage when loading a document from a file. Unfortunately it looks like my options are more limited with TAdvMemo and the encodings it supports while loading.

2. You may want to reconsider and let people edit their own posts... at least give them 15 minutes or so to edit their own posts. I find this really useful.

  1. I don't understand how you cannot aplply the codepage found to AdvMemo.Font.CharSet.
    2. The forum software is a module we bought and I'm not sure it is configurable in such way. We'd need to investigate.

1. You said yourself that AdvMemo.Font.CharSet doesn't affect loading of files.... or am I misunderstanding? To ensure that files are always loaded correctly (or at least as much as possible), shouldn't a codepage or encoding be specified with the load method? I don't think AdvMemo.Font.CharSet is relevant here (when loading files)... or am I missing something?

2. OK. Just thought I'd mention it as a suggestion... if you can do it then great, if not then I'll just have to be more careful before I post my replies since I won't be able to edit them later. :) I won't mention it again.

Oh, I do realize that you already pointed out that some encodings can be specified when loading, but not nearly as many as would be able to with a codepage parameter.

Then please explain what you think you can NOT do?

For example, how would I load a file encoded with codepage 28598 (iso-8859-8)? And then save it back out using the same codepage?

As I explained already, there is no convention for storing codepage in a plaintext file. You'd need to determine this somehow from the content. As such there is also not a convention for storing it. 
All that can be done is heuristically determine it from an existing file and adapt the Font.Charset for it. The only other encodings are for non-ANSI text files, like UTF8,  UTF16 encoding etc.. and this can be handled with the Encoding parameter of LoadFromFile()

Some further information:

This is exactly the same with the standard VCL TMemo, simply because other than heuristic guesses there simply is not a convention for storing codepage in a plain text file.

This is my last and final answer on this topic.

So the final answer is that TAdvMemo cannot load a document using a given codepage (except for the few that can be specified with System::Sysutils::TEncoding) even though LMD SyntaxEdit allows this... and apparently there is no interest in adding support for this.

As for heuristic guessing, I've already explained that documents like CSS, HTML, and XML can specify the encoding in the document... there is no need to guess if the encoding is specified in the document. If it is specified then it make sense to use that encoding when loading but I can't with TAdvMemo unless it is one of the few supported by System::Sysutils::TEncoding.

So it would have been a lot easier if you'd just say that TAdvMemo cannot do what I asked about and you don't want to add support for it. The only helpful info I got from this thread was that I have the option to use the limited encodings that can be specified by using System::Sysutils::TEncoding. At least that is better than not being able to specify any encoding at all.

Nothing prevents you from extracting this codepage from the file type you wish to use with TAdvMemo and apply the code page you retrieve to Font.CharSet. TAdvMemo primary focus is programming languages (Pascal, Basic, C#, JS that have no codepage at all)