From Clomosy Docs

No edit summary
No edit summary
Line 14: Line 14:
Here are some important properties of the TclStringList class:
Here are some important properties of the TclStringList class:


*'''Capacity'''<br>
=Capacity=
Determines or returns the capacity of the list. Capacity represents the size of the allocated memory space for the list. The capacity is dynamically adjusted automatically during operations such as adding or removing elements.
Determines or returns the capacity of the list. Capacity represents the size of the allocated memory space for the list. The capacity is dynamically adjusted automatically during operations such as adding or removing elements.


Line 55: Line 55:
In the above example, we set the capacity of the list to 10 using the Capacity property of the TclStringList class. Then, by adding elements that exceed the capacity, we create a situation where the capacity is exceeded. In this case, the list automatically expands, and we check the new capacity.
In the above example, we set the capacity of the list to 10 using the Capacity property of the TclStringList class. Then, by adding elements that exceed the capacity, we create a situation where the capacity is exceeded. In this case, the list automatically expands, and we check the new capacity.


*'''Count'''
=Count=
The Count property of the TclStringList class returns the number of items in the list. Here is an example:<br>
The Count property of the TclStringList class returns the number of items in the list. Here is an example:<br>


Line 82: Line 82:
  There are 4 items in the list.
  There are 4 items in the list.


*'''Sorted'''
=Sorted=


The Sorted property of the TclStringList class returns or sets a Boolean value that indicates whether the elements of the list are ordered.
The Sorted property of the TclStringList class returns or sets a Boolean value that indicates whether the elements of the list are ordered.
Line 123: Line 123:
  Orange
  Orange


*'''Delimiter''' and '''DelimitedText'''
=Delimiter and DelimitedText=
Sets or returns the separator character. Specifies the character used to separate the string when using the DelimitedText property.
Sets or returns the separator character. Specifies the character used to separate the string when using the DelimitedText property.


Line 141: Line 141:
  '''end;'''
  '''end;'''


*'''Add'''
=Add=
The Add property of the TclStringList class is used to add a new item to the end of the list.
The Add property of the TclStringList class is used to add a new item to the end of the list.


Line 159: Line 159:
  '''end;'''
  '''end;'''


*'''Insert'''
=Insert=
The Insert property of the TclStringList class is used to insert a new item at a specific location.
The Insert property of the TclStringList class is used to insert a new item at a specific location.


Line 182: Line 182:
As a result, the contents of the list are displayed using the ShowMessage function. You will get a message like "Items: Apple Grape Banana Orange" as output.
As a result, the contents of the list are displayed using the ShowMessage function. You will get a message like "Items: Apple Grape Banana Orange" as output.


*'''Delete'''
=Delete=
The Delete property of the TclStringList class is used to delete the item at a particular index from the list.
The Delete property of the TclStringList class is used to delete the item at a particular index from the list.


Line 203: Line 203:
  '''end;'''
  '''end;'''


*'''Clear'''
=Clear=
The clear property is used to clear all the items of the list.
The clear property is used to clear all the items of the list.


Line 227: Line 227:
As a result, the updated content of the list is displayed using the ShowMessage function. You will get a message like "Items:" (empty) as output because all items have been deleted.
As a result, the updated content of the list is displayed using the ShowMessage function. You will get a message like "Items:" (empty) as output because all items have been deleted.


*'''IndexOf'''
=IndexOf=


The IndexOf property of the TclStringList class is used to find the index of a particular item in the list.
The IndexOf property of the TclStringList class is used to find the index of a particular item in the list.
Line 249: Line 249:
  '''end;'''
  '''end;'''


*'''Exchange'''
=Exchange=
The Exchange feature is used to swap two items.
The Exchange feature is used to swap two items.


Line 272: Line 272:
As a result, the contents of items that have been updated using the ShowMessage function are displayed. You will get a message like "Items: Orange Banana Apple" as output.
As a result, the contents of items that have been updated using the ShowMessage function are displayed. You will get a message like "Items: Orange Banana Apple" as output.


*'''Sort'''
=Sort=
The sort property is used to sort the items of the list alphabetically.
The sort property is used to sort the items of the list alphabetically.



Revision as of 15:29, 20 June 2023

TclStringList is a convenient class used to store and manage an array of strings, providing a list-like structure. TclStringList enables the ability to add, remove, sort, search, and perform other operations on string elements within the list.

To utilize TclStringList, a variable of type TclStringList should be defined.

Var
List:TclStringList;

Then the list should be created in the application.

List := Clomosy.StringListNew;

The StringListItemString(ListVariable,index) property of the Clomosy library is used to provide access to the items in the list.

Str:=Clomosy.StringListItemString(List,0);

Here are some important properties of the TclStringList class:

Capacity

Determines or returns the capacity of the list. Capacity represents the size of the allocated memory space for the list. The capacity is dynamically adjusted automatically during operations such as adding or removing elements.

Example:

procedure TclStringListCapacityOrnegi;
var
  List: TclStringList;
begin
  List := Clomosy.StringListNew; //A new list has been created
  try
    List.Capacity := 5; // Set capacity to 10 

    // Check capacity
    ShowMessage('Capacity: '+IntToStr(List.Capacity)); 

    // Let's exceed capacity by adding more items
    List.Add('Item 1');
    List.Add('Item 2');
    List.Add('Item 3');
    List.Add('Item 4');
    List.Add('Item 5');
    List.Add('Item 6');
    List.Add('Item 7');

    // Check new capacity
    ShowMessage('New capacity: '+ IntToStr(List.Capacity));
  finally
    List.Free;
  end;
end;

begin
  TclStringListCapacityOrnegi;
end;

Output:

Capacity: 5
New capacity: 9

In the above example, we set the capacity of the list to 10 using the Capacity property of the TclStringList class. Then, by adding elements that exceed the capacity, we create a situation where the capacity is exceeded. In this case, the list automatically expands, and we check the new capacity.

Count

The Count property of the TclStringList class returns the number of items in the list. Here is an example:

Example:

var
  MyList: TclStringList;
  ItemCount: Integer;
begin
  MyList := Clomosy.StringListNew;

  // Add items
  MyList.Add('Apple');
  MyList.Add('Banana');
  MyList.Add('Orange');

  // Get item count
  ItemCount := MyList.Count;
  
  // Show result
  ShowMessage('There are ' + IntToStr(ItemCount) + ' items in the list.');
  
  MyList.Free;
end;

Output:

There are 4 items in the list.

Sorted

The Sorted property of the TclStringList class returns or sets a Boolean value that indicates whether the elements of the list are ordered.

Example:

var
  MyList: TclStringList;
  i: Integer;
begin
  MyList := Clomosy.StringListNew;
  
  // Add unordered items
  MyList.Add('Orange');
  MyList.Add('Banana');
  MyList.Add('Apple');
  
  // Show unordered list items
  ShowMessage('Unsorted List:');
  for i := 0 to MyList.Count - 1 do
    ShowMessage(Clomosy.StringListItemString(MyList,i));
  
  // Sort items
  MyList.Sorted := True;
  
  // Show sorted list items
  ShowMessage('Sorted List:');
  for i := 0 to MyList.Count - 1 do
    ShowMessage(Clomosy.StringListItemString(MyList,i));
  MyList.Free;
end;

Output:

Unsorted List:
Orange
Banana
Apple
Sorted list:
Apple
Banana
Orange

Delimiter and DelimitedText

Sets or returns the separator character. Specifies the character used to separate the string when using the DelimitedText property.

Example:

var
 list:TclStringList;
 str:String;
begin
  str := 'hello,world,test';
  list := Clomosy.StringListNew;
  
  List.Delimiter := ',';
  List.DelimitedText := str; 
  Str:=Clomosy.StringListItemString(List,0);//Returns element 0
  ShowMessage(str);
  ShowMessage(List.Count);
end;

Add

The Add property of the TclStringList class is used to add a new item to the end of the list.

Example:

var
  MyList: TclStringList;
begin
  MyList := Clomosy.StringListNew;
  
  MyList.Add('Blue');
  MyList.Add('Red');
  MyList.Add('Yellow');
  MyList.Add('Purple');

  ShowMessage('Items: ' + MyList.Text);
  MyList.Free;
end;

Insert

The Insert property of the TclStringList class is used to insert a new item at a specific location.

Example:

var
  MyList: TclStringList;
begin
  MyList := Clomosy.StringListNew;
  
  MyList.Add('Apple');
  MyList.Add('Banana');
  MyList.Add('Orange');
  
  // Add "Grape" to Index 1
  MyList.Insert(1, 'Grape');
  
  ShowMessage('Items: ' + MyList.Text);
  
  MyList.Free;
end;

As a result, the contents of the list are displayed using the ShowMessage function. You will get a message like "Items: Apple Grape Banana Orange" as output.

Delete

The Delete property of the TclStringList class is used to delete the item at a particular index from the list.

Example:

var
  MyList: TclStringList;
begin
  MyList := Clomosy.StringListNew;
  
  MyList.Add('Apple');
  MyList.Add('Banana');
  MyList.Add('Orange');
  
  // Delete "Grape" to Index 1
  MyList.Delete(1);
  
  ShowMessage('Items: ' + MyList.Text);
  
  MyList.Free;
end;

Clear

The clear property is used to clear all the items of the list.

Example:

var
  MyList: TclStringList;
begin
  MyList := Clomosy.StringListNew;
  
  MyList.Add('Apple');
  MyList.Add('Banana');
  MyList.Add('Orange');
  ShowMessage('Items: ' + MyList.Text);
  
  // Clear "Grape" to Index 1
  MyList.Clear;
  
  ShowMessage('Items: ' + MyList.Text);
  
  MyList.Free;
end;

As a result, the updated content of the list is displayed using the ShowMessage function. You will get a message like "Items:" (empty) as output because all items have been deleted.

IndexOf

The IndexOf property of the TclStringList class is used to find the index of a particular item in the list.

Example:

var
  MyList: TclStringList;
  Index: Integer;
begin
  MyList := Clomosy.StringListNew;
  
  MyList.Add('Apple');
  MyList.Add('Banana');
  MyList.Add('Orange');
  
  Index := MyList.IndexOf('Banana');
  
  ShowMessage('Indeks: ' + IntToStr(Index));
  
  MyList.Free;
end;

Exchange

The Exchange feature is used to swap two items.

Example:

var
  MyList: TclStringList;
  Index: Integer;
begin
  MyList := Clomosy.StringListNew;
 
  MyList.Add('Apple');
  MyList.Add('Banana');
  MyList.Add('Orange');
  
  MyList.Exchange(0,2);
  
  ShowMessage('Items: ' + MyList.Text);
  
  MyList.Free;
end;

As a result, the contents of items that have been updated using the ShowMessage function are displayed. You will get a message like "Items: Orange Banana Apple" as output.

Sort

The sort property is used to sort the items of the list alphabetically.

Example:

var
  MyList: TclStringList;
  Index: Integer;
begin
  MyList := Clomosy.StringListNew;
  
  MyList.Add('Orange');
  MyList.Add('Banana');
  MyList.Add('Apple');
  
  ShowMessage('Items: ' + MyList.Text);
  
  MyList.Sort;
  
  ShowMessage('Items: ' + MyList.Text);
  MyList.Free;
end;

As a result, the content of items sorted using the ShowMessage function is displayed. You will get a message like "Items: Apple Banana Orange" as output.