[delphizip] Code Pages

  • From: "James Turner" <james.d.h.turner@xxxxxxxxxxxx>
  • To: <delphizip@xxxxxxxxxxxxx>
  • Date: Thu, 11 Aug 2005 10:41:49 +0100

I've been looking at the issue of code pages.

My copy of DelphiZip is pretty ancient , so this may have been addressed but
it appears that the function ConvCodePage
is faulty (requiring extra brackets around the ( ) or ( ) or ( ) I think).
I've always struggled with the whole concept of codepages so I could be
wrong.

The code that I have reads as follows.
function TZipMaster.ConvCodePage( Source: String; Direction:
CodePageDirection ): String;
const
   FS_FAT:  Integer =  0;
   FS_HPFS: Integer =  6;
   FS_NTFS: Integer = 11;
var
   i: Integer;
begin
   SetLength( Result, Length( Source ) );
   if ((FCodePage = cpAuto) and (FVersionMadeBy1 = FS_FAT) or
(FVersionMadeBy1 = FS_HPFS)
        or ((FVersionMadeBy1 = FS_NTFS) and (FVersionMadeBy0 = 50))) or
(FCodePage = cpOEM) then
   begin
      for i := 1 to Length( Source ) do
         if Char( Source[i] ) < Char( $80 ) then
            Result[i] := Source[i]
         else
            if Direction = cpdOEM2ISO then
               OemToCharBuff( @Source[i], @Result[i], 1 )
            else
               CharToOemBuff( @Source[i], @Result[i], 1 )
   end
   else
      Result := Source;
end;

This function also appears to be very inefficient. To perform the conversion
you could use something like this
procedure OEMConvert(var s:string);
begin
  if s = '' then exit;

  UniqueString(s); OEMToChar(pointer(s),pointer(s));
end;
(Obviously, this only performs the conversion one way.)

Alternatively
function OEMConvert(const s:string):string;
begin
  result := s; if result = '' then exit;

  UniqueString(result); OEMToChar(pointer(result),pointer(result));
end;

-- James Turner

-----------
To unsubscribe from this list, send an empty e-mail 
message to:
  delphizip-request@xxxxxxxxxxxxx 
and put the word unsubscribe in the subject.

Other related posts: