Two potential problems. 1) If your user passes in a command line parameter which isn't -low but also isn't nothing, the length of the array won't get set.
2) Your for loop should probably run from 0 to Max -1. I think this is probably what is throwing your pointer error. You're trying to assign an Image to an element in the array with an index 1 greater than the size of the array. Why use arrays? Why not use something like TObjectList? TObjectList can handle freeing your images after you've finished with them etc. 500 objects doesn't seem that big to me, so I'm not quite sure why you're worrying about memory. HTH, Conor -----Original Message----- From: gajo [mailto:[EMAIL PROTECTED] Sorry, I've made this post have a little larger width, so that the code would fit right. I have a problem with handling memory. I have an array of objects, namely TImage. The length of the array is determined by the user, that is 500 by default, or 50 if the parameter -low is entered. When the application starts I begin creating the objects. I have also wrote what messages should appear when an exception is raised. Those messages never appear, so the problem doesn't happen during the creation, but a few seconds AFTER. In the end, I get the following message (this one is from the Delphi compiler): "Project MemTest.exe raised exception class EInvalidPointer with message 'Invalid pointer operation'. Process stopped. Use Step or Run to continue." In my opinion, the problem is that there isn't enough memory. It has to be that, because the only procedure used in the program is the one I've posted at the end of the message. I should probably do something else besides just creating objects, perhaps GetMem or such? Or raise the heap size? Anyway, before I do anything I would like top hear some suggestions from you guys! Gajo code --------> global types: type ObjGroup = array of TImage; global variables: var grp = ObjGroup; procedure Form1.OnCreate --- can also be anything else var i: integer; begin // if the user starts the program with -low, then the array will be of size 50; otherwise 500 if ParamStr(1) = '' then max := 500 else if ParamStr(1) = '-low' then max := 50; try SetLength(grp,max) // if the length is too large an exception will be raised except on Exception do begin if max = 500 then begin MessageBeep(MB_ICONEXCLAMATION); MessageDlg('Your computer is too weak. Try starting with the -low parameter!', mtError,[mbOK], 0); Application.Terminate end else if max = 50 then begin MessageBeep(MB_ICONEXCLAMATION); MessageDlg('Sorry, this will never work...', mtError,[mbOK], 0); Application.Terminate end end end; for i := 0 to max do begin // create an object for every item of the array try grp[i] := TImage.Create(Self); grp[i].Parent := Form1; grp[i].Visible := False; grp[i].Transparent := True; grp[i].Picture := Image1.Picture; grp[i].Width := Image1.Width; grp[i].Height := Image1.Height; except on Exception do MessageDlg('Something is not right.', mtError, [mbOK], 0) end; end; end; end; --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
