source: branches/test1/Client/Forms/UFormItemSelect.pas

Last change on this file was 46, checked in by chronos, 13 years ago
File size: 2.5 KB
Line 
1unit UFormItemSelect;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, EditBtn,
9 ComCtrls, StdCtrls, USystem;
10
11type
12
13 { TItemSelectForm }
14
15 TItemSelectForm = class(TForm)
16 ButtonSelect: TButton;
17 ButtonCancel: TButton;
18 ListView1: TListView;
19 procedure FormCreate(Sender: TObject);
20 procedure FormDestroy(Sender: TObject);
21 procedure FormShow(Sender: TObject);
22 procedure ListView1Data(Sender: TObject; Item: TListItem);
23 procedure ListView1Resize(Sender: TObject);
24 private
25 function GetSelectedId: Integer;
26 { private declarations }
27 public
28 Report: TReport;
29 ObjectId: Integer;
30 ListObject: TChronisObject;
31 procedure LoadList;
32 property SelectedId: Integer read GetSelectedId;
33 end;
34
35var
36 ItemSelectForm: TItemSelectForm;
37
38implementation
39
40{$R *.lfm}
41
42uses
43 UCore;
44
45{ TItemSelectForm }
46
47procedure TItemSelectForm.ListView1Data(Sender: TObject; Item: TListItem);
48var
49 I: Integer;
50begin
51 if Item.Index < Report.Count then
52 with TReportLine(Report[Item.Index]) do begin
53 Item.Caption := Items[0];
54 Item.Data := Pointer(Id);
55 for I := 1 to Items.Count - 1 do
56 if not TReportColumn(Report.Columns[I]).VirtualItem then
57 Item.SubItems.Add(Items[I]);
58 end;
59end;
60
61procedure TItemSelectForm.ListView1Resize(Sender: TObject);
62var
63 I: Integer;
64begin
65 for I := 0 to ListView1.Columns.Count - 1 do
66 ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count;
67end;
68
69function TItemSelectForm.GetSelectedId: Integer;
70begin
71 if Assigned(ListView1.Selected) then Result := Integer(ListView1.Selected.Data)
72 else Result := -1;
73end;
74
75procedure TItemSelectForm.LoadList;
76begin
77 // SelectedObjectId := 0;
78 with ListView1 do begin
79 ListObject.Load(ObjectId);
80 Report.Load(ListObject); //, '`' + PropertyName + '`=' + IntToStr(TabObjectList[TabControl1.TabIndex]));
81
82 Report.FillListColumns(Columns);
83 Items.Count := Report.Count;
84 Refresh;
85 end;
86 ListView1Resize(Self);
87end;
88
89procedure TItemSelectForm.FormCreate(Sender: TObject);
90begin
91 Report := TReport.Create;
92 Report.Base := Core.System;
93 ListObject := TChronisObject.Create;
94 ListObject.Base := Core.System;
95end;
96
97procedure TItemSelectForm.FormDestroy(Sender: TObject);
98begin
99 Report.Free;
100 ListObject.Free;
101end;
102
103procedure TItemSelectForm.FormShow(Sender: TObject);
104begin
105 LoadList;
106end;
107
108end.
109
Note: See TracBrowser for help on using the repository browser.