Watch, Follow, &
Connect with Us

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


ID: 19302, bug in ReadComponentResFile function

by majid assadi Email: Anonymous


ReadComponentResFile func
Download Details
FTP  download also available 0 bytes
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 1.0  to 1.0 9 downloads
Copyright: No significant restrictions


Size: 0 bytes
Updated on Thu, 28 Nov 2002 07:49:39 GMT
Originally uploaded on Thu, 28 Nov 2002 07:49:21 GMT
Description
I’ve found that there is a bug in ReadComponentResFile function, here is the bug and the solution for fixing it.

//the following codes is on classess Delphi Unit

// first called function
function ReadComponentResFile(const FileName: string; Instance: TComponent): TComponent;
var
Stream: TStream;
begin
Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
Result := Stream.ReadComponentRes(Instance);
finally
Stream.Free;
end;
end;

// second called function
function TStream.ReadComponentRes(Instance: TComponent): TComponent;
begin
ReadResHeader;
Result := ReadComponent(Instance);
end;

//third called function
procedure TStream.ReadResHeader;
var
ReadCount: Cardinal;
Header: array[0..79] of Char;
begin
FillChar(Header, SizeOf(Header), 0);
ReadCount := Read(Header, SizeOf(Header) - 1);
if (Byte((@Header[0])^) = $FF) and (Word((@Header[1])^) = 10) then
Seek(StrLen(Header + 3) + 10 - ReadCount, 1)
else
raise EInvalidImage.Create(SInvalidImage);
end;

//forth called function
function THandleStream.Seek(Offset: Longint; Origin: Word): Longint;
begin
Result := FileSeek(FHandle, Offset, Origin);
end;

Problem in the third called function
The result of "StrLen(Header + 3) + 10 - ReadCount" will be a cardinal value "because of the ReadCount definition" and the calling function (the forth called function) is looking for a Longint value; here it raises error. It will work fine if you change the type of ReadCount from Cardinal to Longint in the third function.


Best Regards
Majid

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC03