Board index » delphi » How to read different charsets (repost)

How to read different charsets (repost)

How do I read a OEM or Mac encoded textfile into a TRichedit or TMemo?
(Richedit has a property:  Font.Charset, but it does not appear to work)

Thankful for any help, I dont want to write my own converter...

--
---------------------------------------------------
Gustav ?hman            gustav.oh...@sg-guidance.se

 

Re:How to read different charsets (repost)


Quote
In article <38A7C90A.89F86...@sg-guidance.se>, Gustav ?hman wrote:
> How do I read a OEM or Mac encoded textfile into a TRichedit or
> TMemo?
> (Richedit has a property:  Font.Charset, but it does not appear to
> work)

> Thankful for any help, I dont want to write my own converter...

Well, you don't have to do that much work for OEM->ANSI conversions
since the OS offers functions for this: OemToChar and OemToCharBuff.
Loading a OEM file thus becomes

 var
   ms: TMemoryStream;
 begin
   ms:= TmemoryStream.Create;
   try
     ms.Loadfromfile( filename );
     ms.position := 0;
     OemToCharBuff( ms.memory, ms.memory, ms.size );
     memo1.lines.loadfromstream(ms);
   finally
     ms.free
   end;
 end;

 I have no idea what character encoding Mac use.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Sent using Virtual Access 5.00 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Re:How to read different charsets (repost)


Quote
"Peter Below (TeamB)" wrote:
> Well, you don't have to do that much work for OEM->ANSI conversions
> since the OS offers functions for this: OemToChar and OemToCharBuff.
> Loading a OEM file thus becomes

>  var
>    ms: TMemoryStream;
>  begin
>    ms:= TmemoryStream.Create;
>    try
>      ms.Loadfromfile( filename );
>      ms.position := 0;
>      OemToCharBuff( ms.memory, ms.memory, ms.size );
>      memo1.lines.loadfromstream(ms);
>    finally
>      ms.free
>    end;
>  end;

>  I have no idea what character encoding Mac use.

Thanks! I must have missed those functions when I searched the docs
That will solve the critical problem of OEM -> Ansi, but one of these
days I will have to deal with other charsets (including mac) too. Also
not having to reload the file to convert it would be nice.
Anyway I'm still confused: What is the Font.Charset property supposed to
do if it is not used for charset conversion?

--
---------------------------------------------------
Gustav ?hman            gustav.oh...@sg-guidance.se

Re:How to read different charsets (repost)


Quote
In article <38A923F3.B32F...@sg-guidance.se>, Gustav ?hman wrote:
> What is the Font.Charset property supposed to
> do if it is not used for charset conversion?

It selects one of several glyph mappings a font may contain, e.g.
between ANSI_CHARSET and EASTEUROPE_CHARSET. The problem seems to be
that most fonts do not have different glyph mappings, or have them only
on some language versions of Windows. Most fonts have one fixed charset
value build in (e.g. Symbol and WingDings are always SYMBOL_CHARSET)
and the charset then is simply one of the attributes an application can
specify when it asks for a font (CreateFontIndirect API, that is behind
TFont) and the Windows font mapper will then do its best to find a font
installed on the system that matches the requirements. But it may not
be able to find one and then selects a "closest match" using a set of
arcane criteria nobody outside MS understands.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Sent using Virtual Access 5.00 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Other Threads