[Lazarus] WSRegister error on console application

Andrea Mauri andrea.mauri.75 at gmail.com
Fri Apr 24 16:27:59 CEST 2009


Hello Bart and others,

Thanks for your kindness to test my test case, which works fine in my
case too, but I have found something what maybe more explain my
problem.

TYPE TSomeItem = RECORD
                   First :single;
                   Second:Single;
                   Third :integer;

TYPE TSomethingArr = ARRAY OF TSomeItem;

TYPE TSomeHeader   =RECORD
                      ...
                    end;

TYPE TMyObject =class
                 private
                   FHeader:TSomeHeader;
                   FItems :TSomethingArr;

...

FUNCTION TMyObject.LoadFromStream (Stream:TStream):BOOLEAN;
...
  SetLength (FItems, 0); //!! for testing only -- this line works fine
  Stream.Read (FHeader, HeaderLen);
  SetLength (FItems, 0); //!! for testing only -- this line raises an exception
END;


If you see the declaration of TMyObject you will find that FHeader
declaration is followed by FItems and the length of read memory block
goes over size of FHeader and it affects FItems.

Hm?

TRoland;

<<< 23.4.2009 17:19 - Bart "bartjunk64 at gmail.com" >>>
B> This code works perfectly fine (at least it does not crash) with fpc 2.2.2

B> constructor TMyObject.Create;
B> begin
B>   DebugLn('Create');
B>   FItem := nil;
B>   DebugLn('nil');
B>   SetLength(FItem,3);
B>   DebugLn('SetLength');
B>   FItem[0].First:= 1.0;
B>   DebugLn('FItem[0].First = ',DbgS(FItem[0].First));
B> end;

B> Bart




-- 
Best regards, TRoland
http://www.rotursoft.sk
http://exekutor.rotursoft.sk




More information about the Lazarus mailing list