<div dir="ltr"><div>Override:</div>
<div> function GetItemsClass: TCustomComboBoxStringsClass; virtual; abstract;<br></div>
<div>Create your own subclass of TCustomComboBoxStrings and override the Item add and Item delete routines. You need to place a synched copy of your objects into a seperate list so that when the windows handle to the combobox is released or recreated you don't loose your object pointers. you can also add asserts or tests on the combobox.handle rather than letting it crash all the time. then on the destroy of your TCustomCombobox strings free all the objects in the list.. This would be easiest by using a TObjectList with owns objects = true.</div>
<div><br><br> </div>
<div class="gmail_quote">On Wed, Oct 15, 2008 at 4:22 PM, Robert martin <span dir="ltr"><<a href="mailto:rob@chreos.co.nz">rob@chreos.co.nz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi<br><br>Just trying to make a TComboBox that automatically frees its items.<br><br>I have the following code in the destructor<br>
<br> if (fAutomaticallyFreeObjects = True)<br> and ((csDesigning in ComponentState) = False) then begin<br> try<br> for Counter := 0 to Self.Items.Count - 1 do begin<br> O := Items.Objects[Counter];<br>
if (O <> nil) then begin<br> O.Free;<br> end;<br> end;<br> except<br> on e: exception do begin<br> ShowMessage(IntToStr(i) + ' ' + 'Attempting to<br>
automatically free object memory. The following error occured...' +<br>#13#13 + e.message);<br> end;<br> end;<br> end;<br><br><br>I get a 'Control '' has no parent error. This happens when attempting<br>
to access the .Items property. My custom error handling does not trigger.<br><br>Any suggestions ?<br><br>Thanks<br>Rob<br>_______________________________________________<br>NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><br>Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<br>
</blockquote></div><br><br clear="all"><br>-- <br>Kyley Harris<br>Harris Software<br>+64-21-671-821<br></div>