frmProjectCollection.pas
上传用户:youjie821
上传日期:2013-01-27
资源大小:459k
文件大小:3k
源码类别:
PlugIns编程
开发平台:
Delphi
- unit frmProjectCollection;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, hxUpdate, StdCtrls, ComCtrls, CSIntf;
- type
- TProjectCollectionForm = class(TForm)
- btnAdd: TButton;
- btnRefresh: TButton;
- ListView1: TListView;
- btnView: TButton;
- btnClear: TButton;
- ListView2: TListView;
- btnAssign: TButton;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure btnAddClick(Sender: TObject);
- procedure btnRefreshClick(Sender: TObject);
- procedure btnViewClick(Sender: TObject);
- procedure btnClearClick(Sender: TObject);
- procedure btnAssignClick(Sender: TObject);
- private
- { Private declarations }
- FProjectCollection: TProjectCollection;
- procedure RefreshProjects(ProjectCollection: TProjectCollection; ListItems: TListItems);
- public
- { Public declarations }
- end;
- procedure ShowProjectCollectionForm;
- implementation
- {$R *.dfm}
- procedure ShowProjectCollectionForm;
- begin
- with TProjectCollectionForm.Create(nil) do
- try
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TProjectCollectionForm.FormCreate(Sender: TObject);
- begin
- FProjectCollection:= TProjectCollection.Create(nil, 'myproj.dat');
- end;
- procedure TProjectCollectionForm.FormDestroy(Sender: TObject);
- begin
- FProjectCollection.Free;
- end;
- procedure TProjectCollectionForm.btnAddClick(Sender: TObject);
- begin
- FProjectCollection.Add('我的工程', '测试项目', 'D:My Projects');
- end;
- procedure TProjectCollectionForm.btnRefreshClick(Sender: TObject);
- begin
- RefreshProjects(FProjectCollection, ListView1.Items);
- end;
- procedure TProjectCollectionForm.btnViewClick(Sender: TObject);
- var
- Str: string;
- begin
- if ListView1.Selected <> nil then
- begin
- with TProjectItem(ListView1.Selected.Data) do
- begin
- Str:= 'ProjectName: ' + ProjectName + #13#10;
- Str:= Str + 'Description: ' + Description + #13#10;
- Str:= Str + 'RootDir: ' + RootDir + #13#10;
- ShowMessage(Str);
- end;
- end;
- end;
- procedure TProjectCollectionForm.btnClearClick(Sender: TObject);
- begin
- FProjectCollection.Clear;
- btnRefresh.Click;
- end;
- procedure TProjectCollectionForm.btnAssignClick(Sender: TObject);
- var
- AProjectCollection: TProjectCollection;
- Stream: TStream;
- begin
- AProjectCollection:= TProjectCollection.Create(nil, 'temp.dat');
- try
- Stream:= TMemoryStream.Create;
- try
- FProjectCollection.SaveToStream(Stream);
- Stream.Position:= 0;
- AProjectCollection.LoadFromStream(Stream);
- RefreshProjects(AProjectCollection, ListView2.Items);
- finally
- Stream.Free;
- end;
- finally
- AProjectCollection.Free;
- end;
- end;
- procedure TProjectCollectionForm.RefreshProjects(ProjectCollection: TProjectCollection;
- ListItems: TListItems);
- var
- I: Integer;
- begin
- ListItems.Clear;
- for I:= 0 to ProjectCollection.Count - 1 do
- with ListItems.Add do
- begin
- Caption:= ProjectCollection.Items[I].ProjectName;
- SubItems.Add(ProjectCollection.Items[I].Description);
- SubItems.Add(ProjectCollection.Items[I].RootDir);
- Data:= ProjectCollection.Items[I];
- end;
- end;
- end.