문제

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!

도움이 되었습니까?

해결책

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top