[Reply]
HI Gajo,
In essence it should work, however thinking beyond what you have described, the
following may help.
The array, when created (or extended using setlength(myArray,i+1).. etc), should have
each new item set to nil. You can test this in two ways:
if (myArray[i] = nil) then ...
or
if assigned(myArray[i]) then ...
The catch is, that each item is a pointer to a memory location, and after the object
instance is created, will point to the location of the memory allocated bu the OS to
the object instance. If that object is freed (myArray[i].free) then the memory is
deallocated by the OS (Windows), but the array item still points to that location in
memory that was allocated.
So for this to work, you also need to reset the array pointer, eg
myArray[i].free;
myArray[i] := nil;
or
freeAndNil(myArray[i]);
Then the array item is reset to nil, and the tests above will continue to work.
kind regards
Gary
| To : [EMAIL PROTECTED]
| CC :
| From: Gajo Istvan, [EMAIL PROTECTED]
| Content Type: text/plain
| Attached:
|
| Hi,
| I have an array of TObjects. A cell of the array may not have been created,
| so I want to check if it exists or not. This doesn't work:
| if myArray[i] = nil then ShowMessage('Object doesn't exist')
|
| What should I do?
| Gajo
|
|
| _______________________________________________
| Delphi mailing list
| [EMAIL PROTECTED]
| http://ns3.123.co.nz/mailman/listinfo/delphi
|
<DIV style="WIDTH: 260px; HEIGHT: 50px"><MARQUEE id=marquee1 style="WIDTH: 260px;
HEIGHT: 200px" trueSpeed scrollAmount=5 scrollDelay=20 direction=right behavior=slide
loop=1 border="2"><hr><table><tr><td><FONT color=black size=4 face =
"helvetica,verdana,arial">Gary Benner </FONT></td></tr><tr><td><FONT face="arial,
arial, helvetica, sans-serif" color=black size=2>e-Engineer, Lecturer, and Software
Developer</FONT></td></tr>
<tr><td bgcolor=><FONT face="arial, arial, helvetica, sans-serif" color=#000099
size=2><B><A HREF="http://www.123.co.nz" style="text-decoration:none; color:blue">123
Internet Limited</A></B></FONT></td></tr><tr><td bgcolor=><FONT face="arial, arial,
helvetica, sans-serif" color=#000099 size=2><B><A HREF="http://www.waiariki.ac.nz"
style="text-decoration:none; color:#993333">Waiariki Institute of
Technology</A></B></FONT></td></tr><tr><td bgcolor=><FONT face="arial, arial,
helvetica, sans-serif" color=#CECE00 size=2><B><A HREF="http://www.sunshinebags.co.nz"
style="text-decoration:none; color:#CECE00">Sunshine Garden Bag
Co.</A></B></FONT></td></tr><tr><td bgcolor=><FONT face="arial, arial, helvetica,
sans-serif" color=red size=2><B><A HREF="http://www.sommnet.com"
style="text-decoration:none; color:red" >Sommnet.com
Limited</A></B></FONT></td></tr><tr><td><font face = "helvetica,verdana,arial" size =
1>Mob: 021 966 992</font></td></tr><tr><td><font face = "helvetica,verdana,!
arial" size = 1>Email: <A href="mailto:[EMAIL PROTECTED]" >[EMAIL PROTECTED]</A>
</font></td></tr></table></MARQUEE></DIV>
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi