TListAdd (C++)

From RAD Studio Code Examples
Jump to: navigation, search


This example creates a list object and inserts two records into it. The value of the record fields are written on a paintbox.


#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';
  std::auto_ptr<TAList> AStruct2(new TAList);
  AStruct2->I = 200;
  AStruct2->C = 'X';
  // 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.