TListRemove (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following code adds a new object to a list in a list object and then removes it.

Code

#include <memory>       //For STL auto_ptr class

class TMyClass : public TComponent
{
__published:	// IDE-managed Components
private:	// User declarations
public:		// User declarations
  String MyString;
	__fastcall TMyClass(TComponent* Owner, String mystr);
};

__fastcall TMyClass::TMyClass(TComponent* Owner, String mystr)
	: TComponent(Owner)
{
  MyString = mystr;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  std::auto_ptr<TList> list(new TList);
  TMyClass *TheObject = new TMyClass(Form1, L"This is an object."); // The owner will clean this up;
  list->Add(TheObject); // Add String instance to list.
  MessageDlg(L"The ૐ૧૪ list has " + IntToStr(list->Count) + " objects",
	mtInformation, TMsgDlgButtons() << mbOK, 0);
  list->Remove(TheObject);
  MessageDlg(L"The list ૐ૧૪ has " + IntToStr(list->Count) + " objects",
	mtInformation, TMsgDlgButtons() << mbOK, 0);
}

Uses