RAD Studio VCL Reference
|
Indicates the number of entries in the list that are in use.
property Count: Integer;
__property int Count;
Read Count to determine the number of entries in the Items array.
Increasing the size of Count will add the necessary number of nil (Delphi) or NULL (C++) pointers to the end of the Items array. Decreasing the size of Count will remove the necessary number of entries from the end of the Items array.
Count is not always the same as the number of objects referenced in the list. Some of the entries in the Items array may contain nil (Delphi) or NULL (C++) pointers. To remove the nil (Delphi) or NULL (C++) pointers and set Count to the number of entries that contain references to objects, call the Pack method.
C++ Examples:
/* 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'; 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 Y Value again PaintBox1->Canvas->TextOut(10, Y, AStruct->C); Y += 30; //Increment Y Value } }
Delphi Examples:
{ This example creates a list object and inserts two records into it. The value of the record fields are written on a paintbox: } procedure TForm1.Button1Click(Sender: TObject); type PMyList = ^AList; AList = record I: Integer; C: Char; end; var MyList: TList; ARecord: PMyList; B: Byte; Y: Word; begin MyList := TList.Create; try New(ARecord); ARecord^.I := 100; ARecord^.C := 'Z'; MyList.Add(ARecord); {Add integer 100 and character Z to list} New(ARecord); ARecord^.I := 200; ARecord^.C := 'X'; MyList.Add(ARecord); {Add integer 200 and character X to list} { Now paint the items onto the paintbox} Y := 10; {Variable used in TextOut function} for B := 0 to (MyList.Count - 1) do begin ARecord := MyList.Items[B]; Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I} Y := Y + 30; {Increment Y Value again} Canvas.TextOut(10, Y, ARecord^.C); {Display C} Y := Y + 30; {Increment Y Value} end; { Cleanup: must free the list items as well as the list } for B := 0 to (MyList.Count - 1) do begin ARecord := MyList.Items[B]; Dispose(ARecord); end; finally MyList.Free; end; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|