delphi - TComboBox 'Control has no parent window' in destructor -
i'm using delphi xe2. build custom tcombobox
can add key/string pairs , handle cleanup in component's destructor.
all if not (csdesigning in componentstate)
code omitted brevity.
interface type tkeyrec = class(tobject) key: string; value: string; end; tmycombobox = class(tcombobox) public destructor destroy; override; procedure additempair(const key, value: string); end; implementation destructor tmycombobox.destroy; var i: integer; begin := 0 self.items.count - 1 self.items.objects[i].free; self.clear; inherited; end; procedure tmycombobox.additempair(const key, value: string); var rec: tkeyrec; begin rec := tkeyrec.create; rec.key := key; rec.value := value; self.items.addobject(value, rec); end;
when application closes, destructor called, items.count
property inaccessible because tcombobox
must have parent control access property. time destructor called, no longer has parent control.
i saw problem once before , had store objects in separate tlist
, free them separately. worked because order added them tlist
same strings added combo box. when user selected string, use combo box index find correlating object in tlist
. if combo box sorted, indexes won't match, can't use solution.
has else seen this? how did workaround issue? nice able free objects in component's destructor!
you can override function getitemsclass
:
function getitemsclass: tcustomcomboboxstringsclass; override;
it called combo create items (by default tcomboboxstrings
probably). can create own tcomboboxstrings
descendant, example tcomboboxstringobjects
, can free object linked item (when item deleted).
Comments
Post a Comment