码迷,mamicode.com
首页 > Windows程序 > 详细

队列与DelphiXe新语法

时间:2014-12-20 23:21:47      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:

好久没写代码了,更久没上博客园的博客了,无聊写几行试一下新语法。

1
unit Main; 2 3 interface 4 5 uses 6 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, 10 Generics.Collections; 11 12 type 13 TMainForm = class(TForm) 14 ListView_Queue: TListView; 15 btEnQueue: TButton; 16 btDeQueue: TButton; 17 procedure btEnQueueClick(Sender: TObject); 18 private 19 { Private declarations } 20 FPriorityQueue:TQueue<PTelegram>; 21 22 procedure SetupListView(ListView:TListView); 23 procedure ViewQueue(ListView:TListView;PriorityQueue:TQueue<PTelegram>); 24 public 25 { Public declarations } 26 end; 27 28 var 29 MainForm: TMainForm; 30 31 implementation 32 33 {$R *.dfm} 34 35 36 procedure TMainForm.SetupListView(ListView: TListView); 37 procedure SetupListViewColumns(Columns:TListColumns); 38 begin 39 Columns.Clear; 40 TListColumn(Columns.Add).Caption:=Caption; 41 TListColumn(Columns.Add).Caption:=Message; 42 TListColumn(Columns.Add).Caption:=Sender; 43 TListColumn(Columns.Add).Caption:=Receiver; 44 TListColumn(Columns.Add).Caption:=DispatchTime; 45 TListColumn(Columns.Add).Caption:=ExtraInfo; 46 end; 47 begin 48 ListView.ViewStyle:=vsReport;//报表格式显示 49 SetupListViewColumns(ListView.Columns); //设置显示列名 50 end; 51 52 procedure TMainForm.ViewQueue(ListView:TListView;PriorityQueue:TQueue<PTelegram>); 53 var 54 FpTelegram:PTelegram; 55 procedure ViewQueueItem(ListItem:TListItem); 56 begin 57 with ListItem do 58 begin 59 Caption := IntToStr(FpTelegram^.msg); 60 SubItems.Add(IntToStr(FpTelegram^.msg)); 61 SubItems.Add(IntToStr(FpTelegram^.Sender)); 62 SubItems.Add(IntToStr(FpTelegram^.Receiver)); 63 SubItems.Add(IntToStr(FpTelegram^.DispatchTime)); 64 SubItems.Add(IntToStr(FpTelegram^.ExtraInfo)); 65 end; 66 end; 67 begin 68 try 69 ListView.Items.BeginUpdate; 70 ListView.Clear; 71 SetupListView(ListView);//设置ListView显示设置 72 for FpTelegram in PriorityQueue do ViewQueueItem(ListView.Items.Add);//显示队列项目 73 finally 74 ListView.Items.EndUpdate 75 end; 76 end; 77 78 procedure TMainForm.btEnQueueClick(Sender: TObject); 79 var 80 FTelegram:PTelegram; 81 82 function MakerQueue(Max:Integer):TQueue<PTelegram>; 83 var 84 i:Integer; 85 begin 86 Result:=TQueue<PTelegram>.Create;//创建优先队列 87 for I := 0 to Max do 88 begin 89 New(FTelegram); 90 with FTelegram^ do 91 begin 92 DispatchTime:=GetTickCount; 93 Sender:=Self.Handle; 94 Receiver:=Self.Handle; 95 Msg:=i; 96 ExtraInfo:=0; 97 end; 98 Result.Enqueue(FTelegram);//入队 99 end; 100 end; 101 102 begin 103 if FPriorityQueue=nil then 104 FPriorityQueue:=MakerQueue(15);//创建15个队列项目 105 ViewQueue(ListView_Queue,FPriorityQueue);//ListView显示队列 106 end; 107 108 end.

 

队列与DelphiXe新语法

标签:

原文地址:http://www.cnblogs.com/ZhouXiHong/p/4175898.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!