TListAdd (C++)
Description
This example creates a list object and inserts two records into it. The value of the record fields are written on a paintbox.
Code
#include <memory> //For STL auto_ptr class
typedef struct AList
{
int I;
char C;
} TAList;
typedef TAList* PAList;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
std::auto_ptr<TList> MyList(new TList);
// Fill the TList.
std::auto_ptr<TAList> AStruct1(new TAList);
AStruct1->I = 100;
AStruct1->C = 'Z';
MyList->Add(AStruct1.get());
std::auto_ptr<TAList> AStruct2(new TAList);
AStruct2->I = 200;
AStruct2->C = 'X';
MyList->Add(AStruct2.get());
// Go through the list, writing the elements to
// the canvas of a paintbox component.
int Y = 10; // Position on canvas
for (int i = 0; i < MyList->Count; i++)
{
TAList *AStruct = (PAList) MyList->Items[i];
PaintBox1->Canvas->TextOut(10, Y, IntToStr(AStruct->I));
Y += 30; // Increment the Y Value.
PaintBox1->Canvas->TextOut(10, Y, AStruct->C);
Y += 30; //Increment the Y Value again.
}
}
Uses
- System.Classes.TList.Add ( fr | de | ja )
- System.Classes.TList.Count ( fr | de | ja )
- System.Classes.TList.Items ( fr | de | ja )