-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.pas
128 lines (108 loc) · 2.54 KB
/
group.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
unit group;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ValEdit, Grids,
StdCtrls, StrUtils, DB;
type
{ TGroupDlg }
TGroupDlg = class(TForm)
OKButton: TButton;
CancelButton: TButton;
GroupEditor: TValueListEditor;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure OKButtonClick(Sender: TObject);
private
public
Factors: string;
GroupVariable: string;
GroupValues: TStringList;
end;
var
GroupDlg: TGroupDlg;
implementation
{$R *.lfm}
uses main, child;
resourcestring
strWarning = 'Aviso';
strGroup = 'Grupo';
strNoGroups = 'Número insuficiente de grupos';
function FindString(const SearchKey: string; SearchList: TStrings): integer;
var
Found: boolean;
I: integer;
SearchStr: string;
begin
Found := False;
I := 0;
while (I < SearchList.Count) and (not Found) do
begin
SearchStr := SearchList.Strings[I];
if (Pos(SearchKey, SearchStr) <> 0) then
begin
Result := I;
Found := True;
Exit;
end;
Inc(I);
end;
if not Found then
Result := -1;
end;
{ TGroupDlg }
procedure TGroupDlg.FormShow(Sender: TObject);
var
bm: TBookmark;
begin
GroupEditor.Strings.Clear;
with GroupEditor.TitleCaptions do
begin
Add(GroupVariable);
Add(strGroup);
end;
with MainForm.MultiDoc.ActiveObject as TMDIChild do
begin
bm := Dataset1.GetBookmark;
Dataset1.DisableControls;
Dataset1.First;
while not Dataset1.EOF do
begin
if FindString(Dataset1.FieldByName(GroupVariable).AsString, GroupValues) < 0 then
GroupValues.Add(Dataset1.FieldByName(GroupVariable).AsString + '=0');
Dataset1.Next;
end;
Dataset1.EnableControls;
Dataset1.GotoBookmark(bm);
end;
GroupEditor.Strings.AddStrings(GroupValues);
GroupEditor.KeyOptions := [keyEdit];
end;
procedure TGroupDlg.FormCreate(Sender: TObject);
begin
GroupValues := TStringList.Create;
Factors := '';
end;
procedure TGroupDlg.FormDestroy(Sender: TObject);
begin
GroupValues.Free;
end;
procedure TGroupDlg.OKButtonClick(Sender: TObject);
var
gp: string;
i: integer;
begin
gp := '';
for i := 0 to GroupEditor.Strings.Count - 1 do
begin
if StrToInt(GroupEditor.Strings.ValueFromIndex[i]) > 0 then
gp := gp + GroupEditor.Strings.ValueFromIndex[i] + ',';
end;
gp := Copy(gp, 1, RPos(',', gp) - 1);
if Length(gp) > 0 then
Factors := gp
else
MessageDlg(strWarning, strNoGroups, mtWarning, [mbOK], 0);
end;
end.