Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Anyone familiar with the HKStreams Components?



Permlink Replies: 7 - Last Post: Feb 12, 2015 7:05 AM Last Post By: Todd Frankson
Todd Frankson

Posts: 39
Registered: 12/19/14
Anyone familiar with the HKStreams Components?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 10, 2015 11:54 AM
I have a D7 app that relies heavily on this component.

I recently have upgraded to XE7 and am having a few issues I believe to resolve around the ANSI/Unicode string issue.

I need some help if anyone can assist....

The Component is here: https://code.google.com/p/xplib/source/browse/trunk/StFLib/Src/HKStreamCol.pas
and it requires this unit too https://code.google.com/p/xplib/source/browse/trunk/StFLib/Src/HKStreamRoutines.pas

The problem I have is the following- in D7- I add several ID's and images to my stream, LZH compress the stream, encrypt it, save it and then load it, decrypt it, inflate the stream and then I can access the images via the ID.

In XE7 I can add several ID's and images to my stream, LZH compress the stream, encrypt it, save it. I can open it with the D7 version of the app fine.
If I step through in the XE7 version of the app (Same code-only changed the Unit names to XE equivalents) I never can get the Image by ID. For example, if I name image 1 "packs", the stream after inflating has the ID of "pa~~" or some other garbage.

I really need some help here.

Thanks!

Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Anyone familiar with the HKStreams Components?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 10, 2015 12:38 PM   in response to: Todd Frankson in response to: Todd Frankson
I didn't have had time yet to read the entire code but in ReadStr and
WriteStr you don't write the entire string (a character is 2 bytes):

function THKStreams.ReadStr(Stream: TStream): string;
var
  i: word;
  S: string;
begin
  Stream.read(i, sizeof(i));
  setlength(S, i);
  Stream.read(s[1], 2*i);
  Result := S;
end;
 
procedure THKStreams.WriteStr(S: string; Stream: TStream);
var
  i: word;
begin
  i := length(S);
  Stream.Write(i, sizeof(i));
  Stream.Write(S[1], 2*i);
end;
Todd Frankson

Posts: 39
Registered: 12/19/14
Re: Anyone familiar with the HKStreams Components?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 10, 2015 3:29 PM   in response to: Lajos Juhasz in response to: Lajos Juhasz
Lajos Juhasz wrote:
I didn't have had time yet to read the entire code but in ReadStr and
WriteStr you don't write the entire string (a character is 2 bytes):

function THKStreams.ReadStr(Stream: TStream): string;
var
  i: word;
  S: string;
begin
  Stream.read(i, sizeof(i));
  setlength(S, i);
  Stream.read(s[1], 2*i);
  Result := S;
end;
 
procedure THKStreams.WriteStr(S: string; Stream: TStream);
var
  i: word;
begin
  i := length(S);
  Stream.Write(i, sizeof(i));
  Stream.Write(S[1], 2*i);
end;

That seems to help a bit.

Now I fail in the strmroutines unit.

IF start[17]<>0 THEN
begin
raise ECorruptFile.Create('Compressed file is corrupt');
exit;
end;

Start[17] is never 0.
I also seem to not be able to evaluate anything in this unit. XE7 is a lot different than D7 or D2006 (the last 2 versions I used).

Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Anyone familiar with the HKStreams Components?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 11, 2015 6:12 AM   in response to: Todd Frankson in response to: Todd Frankson
Todd

I used it ages ago in D6, these days I run D2006 so can't test but have you tried the simple fix of altering all strings to AnsiString?

Roy Lambert
Todd Frankson

Posts: 39
Registered: 12/19/14
Re: Anyone familiar with the HKStreams Components?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 11, 2015 7:07 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:
Todd

I used it ages ago in D6, these days I run D2006 so can't test but have you tried the simple fix of altering all strings to AnsiString?

Roy Lambert

Roy,

I did try that. It compiled but failed the same way. I think it has to do with the TStringlist used internally, specifically the Tstring used for the ID. Whatever I do, I think the String is being converted to Unicode with the Stringlist.AddObject(ID,Object) method. What is weird to me is that I am not using any special characters, so I should not loose anything due to code pages.

The ID's I use are usually the file names of the images, without the paths. I would think "packs" would go through an implicit conversion between Unicode and ansi just fine regardless.

I also noted that sometimes when compressing and Encrypting, the code would hang with certain ID/Image combinations. Haven't gotten a handle on that yet...but I am going to look into it.

I also thought it was the LHA compression, but all sources I can find make it seem OK. I even have the same issue without compression. I looked into the Blowfish portion and it also looks fine(based on other versions of the translated algorithm I could find).

I am at a loss here. I have been out of the Delphi loop for a few years and the changes, although great as far as I am concerned, and the learning curve is a little overwhelming.

Thanks

Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Anyone familiar with the HKStreams Components?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 11, 2015 7:53 AM   in response to: Todd Frankson in response to: Todd Frankson
Todd

It sounds like its time for a bit of debugging <G>

Since you have the source you should be able to figure out what's going on.

First I would change all strings to AnsiString, Char to AnsiChar and PChar ti PAnsiChar (remember to change both HKStreamCol and HKStreamRoutines). If that doesn't work leave the changes in place and start testing what's going on.

Next put a breakpoint in GetStream at dest.CopyFrom(TMemoryStream(Streamlist.objects[i]), 0);. If you don't get there then that says the code for stringlist.IndexOf is failing. The most likely thing is that ID isn't right.

You can also seet what Dest.Size is and see if its the size you expect (start working with uncompressed streams)

Roy Lambert

Andrew Baylis

Posts: 27
Registered: 7/19/00
Re: Anyone familiar with the HKStreams Components?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 11, 2015 10:02 PM   in response to: Todd Frankson in response to: Todd Frankson
On 11/02/2015 6:54 AM, Todd Frankson wrote:
I have a D7 app that relies heavily on this component.

I recently have upgraded to XE7 and am having a few issues I believe to resolve around the ANSI/Unicode string issue.

I need some help if anyone can assist....

The Component is here: https://code.google.com/p/xplib/source/browse/trunk/StFLib/Src/HKStreamCol.pas
and it requires this unit too https://code.google.com/p/xplib/source/browse/trunk/StFLib/Src/HKStreamRoutines.pas

The problem I have is the following- in D7- I add several ID's and images to my stream, LZH compress the stream, encrypt it, save it and then load it, decrypt it, inflate the stream and then I can access the images via the ID.

In XE7 I can add several ID's and images to my stream, LZH compress the stream, encrypt it, save it. I can open it with the D7 version of the app fine.
If I step through in the XE7 version of the app (Same code-only changed the Unit names to XE equivalents) I never can get the Image by ID. For example, if I name image 1 "packs", the stream after inflating has the ID of "pa~~" or some other garbage.

I really need some help here.

Thanks!

Hi,
I have been using it for a very long time (now also in XE7).
It compiles and works well for me in XE7 (although I haven't tried
creating a compressed file in a unicode aware compiler (D2009+) and
reading in a non-unicode (D7 etc).

My ReadStr / WriteStr routines look like:

function THKStreams.ReadStr(Stream : TStream) : string;
var
   i : Word;
   s : string;
{$IFDEF UNICODE}
   b : TBytes;
{$ENDIF}
begin
{$IFDEF UNICODE}
   Stream.Read(i, SizeOf(i));
   SetLength(b, i);
   Stream.Read(b[0], i);
   s := StringOf(b);
{$ELSE}
   Stream.Read(i, SizeOf(i));
   SetLength(s, i);
   Stream.Read(PChar(s)^, i);
{$ENDIF}
   Result := s;
end;
 
procedure THKStreams.WriteStr(s : string; Stream : TStream);
var
   i : Word;
{$IFDEF UNICODE}
   b : TBytes;
{$ENDIF}
begin
{$IFDEF UNICODE}
   b := BytesOf(s);
   i := Length(b);
   Stream.Write(i, SizeOf(i));
   Stream.Write(b[0], i);
{$ELSE}
   i := Length(s);
   Stream.Write(i, SizeOf(i));
   Stream.Write(PChar(s)^, i);
{$ENDIF}
end;


HTH
Andrew
Todd Frankson

Posts: 39
Registered: 12/19/14
Re: Anyone familiar with the HKStreams Components?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2015 7:05 AM   in response to: Andrew Baylis in response to: Andrew Baylis
Hi,
I have been using it for a very long time (now also in XE7).
It compiles and works well for me in XE7 (although I haven't tried
creating a compressed file in a unicode aware compiler (D2009+) and
reading in a non-unicode (D7 etc).

My ReadStr / WriteStr routines look like:

function THKStreams.ReadStr(Stream : TStream) : string;
var
   i : Word;
   s : string;
{$IFDEF UNICODE}
   b : TBytes;
{$ENDIF}
begin
{$IFDEF UNICODE}
   Stream.Read(i, SizeOf(i));
   SetLength(b, i);
   Stream.Read(b[0], i);
   s := StringOf(b);
{$ELSE}
   Stream.Read(i, SizeOf(i));
   SetLength(s, i);
   Stream.Read(PChar(s)^, i);
{$ENDIF}
   Result := s;
end;
 
procedure THKStreams.WriteStr(s : string; Stream : TStream);
var
   i : Word;
{$IFDEF UNICODE}
   b : TBytes;
{$ENDIF}
begin
{$IFDEF UNICODE}
   b := BytesOf(s);
   i := Length(b);
   Stream.Write(i, SizeOf(i));
   Stream.Write(b[0], i);
{$ELSE}
   i := Length(s);
   Stream.Write(i, SizeOf(i));
   Stream.Write(PChar(s)^, i);
{$ENDIF}
end;


HTH
Andrew

Andrew,

I send you PM.

Thanks
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02