Insert
procedure Insert(Index: Integer; S: string);
Example
procedure AddHeading(const Items: TStringList);
begin
if not Items.Sorted then
Items.Insert(0, 'Heading');
end;
Usage
Invokes the string list's abstract operation to insert a string before a zero-based position.
Index = Countis the append position;Index > Countand negative indexes are invalid.- Do not call on a sorted
TStringList. - Saved numeric indexes after the insertion may now refer to different entries.
Additional Technical Info
Insert is declared by hidden ancestor TStrings and is normally used through a concrete visible descendant such as TStringList. The base TStrings class has no storage implementation.
Source-backed behaviour
TStrings.Insert is abstract. TStringList.Insert delegates to its pair insertion with a nil object, requires 0 <= Index <= Count, and raises EStringListError when Sorted=True; sorted lists must use Add so the comparison logic chooses the position.
A successful insertion shifts the previous entry at Index and all later entries upward. It can allocate capacity and emits change notifications.
Related members
InsertObject inserts a paired object. Add is appropriate when order is descendant-controlled. Delete shifts later indexes down.