Question

I have this type definition:

KMenuClass = class
    private
      pMenuID: String;
    public
      property MenuID: String read pMenuID;
      constructor Create(const paraMenuID: String);
  end;

Then I do this:

constructor KMenuClass.Create(const paraMenuID: String);
begin
  pMenuID:= paraMenuID;
end;

procedure TfrmPermissions.FormCreate(Sender: TObject);
begin
  clSetup.Items.AddObject('ant', KMenuClass.Create('a007'));
  clSetup.Items.AddObject('cat', KMenuClass.Create('x123'));

end;

The above two entries aer only test entries. I'm really looking at about 50 items. clSetup is of type TCheckListBox and I'm basically storing a second string along with the Items string.

I can output a specific item like this:

Var
  ThisItem : KMenuClass;
.
.
.
  ThisItem := clSetup.Items.Objects[clSetup.ItemIndex] as KMenuClass;

  ShowMessage(clSetup.Items[clSetup.ItemIndex] + ' : ' + ThisItem.MenuID);

But how do I dispose of my objects associated with each list item? Does it auto-dispose when I close the form?

Thanks!

Was it helpful?

Solution

Manually iterating over items.objects, items.count times and freeing each object is probably the only way, since the property is probably tstrings, and doesn't have an ownsobjects property (that only comes in at tstringlist).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top