System.Classes.TStringList.AddObject

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function AddObject(const S: string; AObject: TObject): Integer; override;

C++

virtual int __fastcall AddObject(const System::UnicodeString S, System::TObject* AObject);

Properties

Type Visibility Source Unit Parent
function public
System.Classes.pas
System.Classes.hpp
System.Classes TStringList

Description

Adds a string to the list, and associates an object with the string.

Call AddObject to add a string and its associated object to the list. AddObject returns the index of the new string and object.

Note: If the OwnsObjects property is set to False, the TStringList object does not own the objects you add using AddObject. Objects added to the TStringList object still exist even if the TStringList instance is destroyed. They must be explicitly destroyed by the application. If you want the objects to be automatically freed upon destroying the TStringList object, you should set OwnsObjects to True or use the overloaded Create constructor that accepts the Boolean OwnsObjects parameter, when creating the TStringList object.

Note: For sorted lists, AddObject raises an EListError exception if the string S already appears in the list and Duplicates is set to dupError. If Duplicates is set to dupIgnore, trying to add a duplicate string causes AddObject to return the index of the existing entry.

See Also