Mega Code Archive
 
 
    
How to convert OEM to ANSI
Title: How to convert OEM to ANSI
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;