...convert OEM to ANSI?
Author: DELPHI ASSIST - TIPS
procedure ConvertFile(const FileName: string; fromCodepage: Integer);
var
ms: TMemoryStream;
begin
if getOEMCP <> fromCodepage then
raise Exception.Create('ConvertFile: Codepage doesn't match!');
ms := TMemoryStream.Create;
try
ms.LoadFromFile(FileName);
// make backup
ms.Position := 0;
ms.SaveToFile(ChangeFileExt(FileName, '.BAK'));
// convert text
OEMToCharBuff(ms.Memory, ms.Memory, ms.Size);
// save back to original file
ms.Position := 0;
ms.SaveToFile(FileName);
finally
ms.Free;
end;
end;
printed from
www.swissdelphicenter.ch
developers knowledge base