Re: Using ZLib
- From: erewhon@xxxxxxxxxx (J French)
- Date: Sun, 29 May 2005 08:27:14 +0000 (UTC)
On 28 May 2005 13:49:35 -0700, "QS Computing" <qscomputing@xxxxxxxxx>
wrote:
>Hi,
>
>I'm trying to use the ZLib units supplied with Delphi to decompress a
>file. So far I've got the following test procedure:
>
>procedure TForm1.Button1Click(Sender: TObject);
>var FS1, FS2: TFileStream;
> ZS: TDecompressionStream;
>begin
> FS1:=TFileStream.Create(ExtractFilePath(ParamStr(0))+'test.zlb',
>fmOpenRead);
> ZS:=TDecompressionStream.Create(FS1);
> FS2:=TFileStream.Create(ExtractFilePath(ParamStr(0))+'test.bin',
>fmCreate);
> FS2.CopyFrom(ZS, 0);
>
> FS1.Free();
> FS2.Free();
> ZS.Free();
>end;
>
>This doesn't work, because the length of the TDecompressionStream can't
>be read. So how can I decompress this file?
I don't have this component, so I can't test this :-
- have you tried: BytesCopied := FS2.CopyFrom(ZS, MaxInt );
That should attempt to read MaxInt bytes from the current .Position in
the Stream.
If that does not work then try repeatedly using CopyFrom on smaller
chunks
>Also, how can I create a array or list of an arbritrary number of
>record types, that is not known before the program is run?
Dynamic Arrays of Records
- available from D4 on
- the Arrays are always zero based
Here are two methods :-
Type TMyRecord = Record
S :String;
I :Integer;
End;
{Method One}
procedure TForm1.Button1Click(Sender: TObject);
Var
Ar :Array of TMyRecord;
begin
SetLength( Ar, 55 );
ShowMessage( IntToStr( Low( Ar ) ) + #13 +
IntToStr( High( Ar ) ) + #13 +
IntToStr( Length( Ar ) ) ) ;
end;
{Method Two}
Type TMyRecAr = Array Of TMyRecord;
procedure TForm1.Button2Click(Sender: TObject);
Var
Ar :TMyRecAr;
begin
SetLength( Ar, 55 );
ShowMessage( IntToStr( Low( Ar ) ) + #13 +
IntToStr( High( Ar ) ) + #13 +
IntToStr( Length( Ar ) ) ) ;
end;
The advantage of method two is that one can make procedures accept the
Type as a parameter.
Also note this:
procedure TForm1.Button3Click(Sender: TObject);
Var
Ar1, Ar2 :TMyRecAr;
begin
SetLength( Ar1, 55 );
Ar1[0].S := 'Hullo World';
Ar2 := Ar1;
ShowMessage( Ar2[0].S );
Ar2[0].S := Ar2[0].S + ' (modified)';
ShowMessage( Ar1[0].S );
end;
Unlike normal Arrays, assignment results in two pointers to the same
data.
.
- Follow-Ups:
- Re: Using ZLib
- From: QS Computing
- Re: Using ZLib
- References:
- Using ZLib
- From: QS Computing
- Using ZLib
- Prev by Date: Re: Farsi text in drawing and text editor
- Next by Date: How to restore the delphi 7 help file?
- Previous by thread: Using ZLib
- Next by thread: Re: Using ZLib
- Index(es):