frmProjectCollection.pas
上传用户:youjie821
上传日期:2013-01-27
资源大小:459k
文件大小:3k
源码类别:

PlugIns编程

开发平台:

Delphi

  1. unit frmProjectCollection;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, hxUpdate, StdCtrls, ComCtrls, CSIntf;
  6. type
  7.   TProjectCollectionForm = class(TForm)
  8.     btnAdd: TButton;
  9.     btnRefresh: TButton;
  10.     ListView1: TListView;
  11.     btnView: TButton;
  12.     btnClear: TButton;
  13.     ListView2: TListView;
  14.     btnAssign: TButton;
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure FormDestroy(Sender: TObject);
  17.     procedure btnAddClick(Sender: TObject);
  18.     procedure btnRefreshClick(Sender: TObject);
  19.     procedure btnViewClick(Sender: TObject);
  20.     procedure btnClearClick(Sender: TObject);
  21.     procedure btnAssignClick(Sender: TObject);
  22.   private
  23.     { Private declarations }
  24.     FProjectCollection: TProjectCollection;
  25.     procedure RefreshProjects(ProjectCollection: TProjectCollection; ListItems: TListItems);
  26.   public
  27.     { Public declarations }
  28.   end;
  29.   procedure ShowProjectCollectionForm;
  30. implementation
  31. {$R *.dfm}
  32. procedure ShowProjectCollectionForm;
  33. begin
  34.   with TProjectCollectionForm.Create(nil) do
  35.   try
  36.     ShowModal;
  37.   finally
  38.     Free;
  39.   end;
  40. end;
  41. procedure TProjectCollectionForm.FormCreate(Sender: TObject);
  42. begin
  43.   FProjectCollection:= TProjectCollection.Create(nil, 'myproj.dat');
  44. end;
  45. procedure TProjectCollectionForm.FormDestroy(Sender: TObject);
  46. begin
  47.   FProjectCollection.Free;
  48. end;
  49. procedure TProjectCollectionForm.btnAddClick(Sender: TObject);
  50. begin
  51.   FProjectCollection.Add('我的工程', '测试项目', 'D:My Projects');  
  52. end;
  53. procedure TProjectCollectionForm.btnRefreshClick(Sender: TObject);
  54. begin
  55.   RefreshProjects(FProjectCollection, ListView1.Items);
  56. end;
  57. procedure TProjectCollectionForm.btnViewClick(Sender: TObject);
  58. var
  59.   Str: string;
  60. begin
  61.   if ListView1.Selected <> nil then
  62.   begin
  63.     with TProjectItem(ListView1.Selected.Data) do
  64.     begin
  65.       Str:= 'ProjectName: ' + ProjectName + #13#10;
  66.       Str:= Str + 'Description: ' + Description + #13#10;
  67.       Str:= Str + 'RootDir: ' + RootDir + #13#10;
  68.       ShowMessage(Str);
  69.     end;
  70.   end;
  71. end;
  72. procedure TProjectCollectionForm.btnClearClick(Sender: TObject);
  73. begin
  74.   FProjectCollection.Clear;
  75.   btnRefresh.Click;
  76. end;
  77. procedure TProjectCollectionForm.btnAssignClick(Sender: TObject);
  78. var
  79.   AProjectCollection: TProjectCollection;
  80.   Stream: TStream;
  81. begin
  82.   AProjectCollection:= TProjectCollection.Create(nil, 'temp.dat');
  83.   try
  84.     Stream:= TMemoryStream.Create;
  85.     try
  86.       FProjectCollection.SaveToStream(Stream);
  87.       Stream.Position:= 0;
  88.       AProjectCollection.LoadFromStream(Stream);
  89.       RefreshProjects(AProjectCollection, ListView2.Items);
  90.     finally
  91.       Stream.Free;
  92.     end;
  93.   finally
  94.     AProjectCollection.Free;
  95.   end;
  96. end;
  97. procedure TProjectCollectionForm.RefreshProjects(ProjectCollection: TProjectCollection;
  98.   ListItems: TListItems);
  99. var
  100.   I: Integer;
  101. begin
  102.   ListItems.Clear;
  103.   for I:= 0 to ProjectCollection.Count - 1 do
  104.     with ListItems.Add do
  105.     begin
  106.       Caption:= ProjectCollection.Items[I].ProjectName;
  107.       SubItems.Add(ProjectCollection.Items[I].Description);
  108.       SubItems.Add(ProjectCollection.Items[I].RootDir);
  109.       Data:= ProjectCollection.Items[I];
  110.     end;
  111. end;
  112. end.