RAD Studio VCL Reference
|
function Last: Pointer;
__fastcall void * Last();
Call Last to retrieve the last pointer in the Items array.
C++ Examples:
/* This example inserts two records into a list object and displays the contents of the last record in the list on the form: */ typedef struct AList { int I; char C; } TAList; typedef AList* PAList; TList *MyList; PAList ARecord1, ARecord2; void __fastcall TForm1::Button1Click(TObject *Sender) { PAList ARecord = (AList *)(MyList->Last()); PaintBox1->Canvas->TextOut(10, 10, IntToStr(ARecord->I)); // Display I PaintBox1->Canvas->TextOut(10, 40, ARecord->C); // Display C } void __fastcall TForm1::Button2Click(TObject *Sender) { Refresh(); } void __fastcall TForm1::FormCreate(TObject *Sender) { MyList = new TList; ARecord1 = new TAList; ARecord1->I = 100; ARecord1->C = 'Z'; MyList->Add(ARecord1); ARecord2 = new TAList; ARecord2->I = 200; ARecord2->C = 'X'; MyList->Add(ARecord2); } void __fastcall TForm1::FormDestroy(TObject *Sender) { // Clean up - must free memory for the items as well as the list for (int i = 0; i < MyList->Count; i++) { PAList ARecord = (PAList) MyList->Items[i]; delete ARecord; } delete MyList; }
Delphi Examples:
{ This example inserts two records into a list object and displays the contents of the last record in the list on the form: } procedure TForm1.Button1Click(Sender: TObject); type PMyList = ^AList; AList = record I: Integer; C: Char; end; var MyList: TList; ARecord: PMyList; I: integer; begin MyList := TList.Create; 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} ARecord := MyList.Last; Canvas.TextOut(10, 10, IntToStr(ARecord^.I)); {Display I} Canvas.TextOut(10, 40, ARecord^.C); {Display C} { Cleanup: must free the list items as well as the list } for I := 0 to (MyList.Count - 1) do begin ARecord := MyList.Items[I]; Dispose(ARecord); end; MyList.Free; end; procedure TForm1.Button2Click(Sender: TObject); begin Refresh; end;
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|