long time no code to write, more than a blog Park blog, bored to write a few lines to try the new grammar.
1 UnitMain;2 3 Interface4 5 uses6 winapi.windows, Winapi.messages, System.sysutils, System.variants, system.classes, Vcl.graphics ,7 Vcl.controls, Vcl.forms, Vcl.dialogs, Vcl.stdctrls, Vcl.comctrls,8 9 IHome.Helper.Telegram,Ten generics.collections; One A type -Tmainform =class(Tform) - Listview_queue:tlistview; the Btenqueue:tbutton; - Btdequeue:tbutton; - procedureBtenqueueclick (sender:tobject); - Private + {Private Declarations} -Fpriorityqueue:tqueue<ptelegram>; + A procedureSetuplistview (listview:tlistview); at procedureViewqueue (Listview:tlistview; Priorityqueue:tqueue<ptelegram>); - Public - {Public Declarations} - End; - - var in Mainform:tmainform; - to Implementation + - {$R *.DFM} the * $ procedureTmainform.setuplistview (listview:tlistview);Panax Notoginseng procedureSetuplistviewcolumns (columns:tlistcolumns); - begin the columns.clear; +Tlistcolumn (Columns.Add). caption:='Caption'; ATlistcolumn (Columns.Add). caption:='Message'; theTlistcolumn (Columns.Add). caption:='Sender'; +Tlistcolumn (Columns.Add). caption:='Receiver'; -Tlistcolumn (Columns.Add). caption:='Dispatchtime'; $Tlistcolumn (Columns.Add). caption:='ExtraInfo'; $ End; - begin -Listview.viewstyle:=vsreport;//Report Format display theSetuplistviewcolumns (Listview.columns);//set display column names - End;Wuyi the procedureTmainform.viewqueue (Listview:tlistview; Priorityqueue:tqueue<ptelegram>); - var Wu Fptelegram:ptelegram; - procedureViewqueueitem (listitem:tlistitem); About begin $ withListItem Do - begin -Caption: =IntToStr (fptelegram^.msg); - SubItems.Add (IntToStr (fptelegram^.msg)); A SubItems.Add (IntToStr (fptelegram^. Sender)); + SubItems.Add (IntToStr (fptelegram^. Receiver)); the SubItems.Add (IntToStr (fptelegram^. Dispatchtime)); - SubItems.Add (IntToStr (fptelegram^. ExtraInfo)); $ End; the End; the begin the Try the ListView.Items.BeginUpdate; - listview.clear; inSetuplistview (ListView);//Set listview display Settings the forFptelegraminchPriorityqueue DoViewqueueitem (LISTVIEW.ITEMS.ADD);//Show Queue Items the finally About ListView.Items.EndUpdate the End; the End; the + procedureTmainform.btenqueueclick (sender:tobject); - var the Ftelegram:ptelegram;Bayi the functionMakerqueue (Max:integer):tqueue<ptelegram>; the var - I:integer; - begin theResult:=tqueue<ptelegram>. Create;//Create a priority queue the forI: =0 toMax Do the begin the New (ftelegram); - withftelegram^ Do the begin thedispatchtime:=GetTickCount; thesender:=Self.handle;94receiver:=Self.handle; themsg:=i; theextrainfo:=0; the End;98Result.enqueue (Ftelegram);//Queue About End; - End;101 102 begin103 ifFpriorityqueue=Nil Then104Fpriorityqueue:=makerqueue ( the);//Create a 15 queue item theViewqueue (Listview_queue,fpriorityqueue);//ListView Display Queue106 End;107 108 End.
Queue and Delphixe new syntax