-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerMain.pas
198 lines (156 loc) · 5.24 KB
/
ServerMain.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
unit ServerMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, KmarDataStructure;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Edit1: TMenuItem;
Changeform1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure Changeform1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure recive(NewStruct:TFormStructure);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses FormEditor;
var
FormStructure: TFormStructure;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i,o,u,ilimit,ulimit:integer;
filehandle:THandle;
begin
//p:=Formstructure;
FormStructure:=TFormStructure.Create;
//load last form from file if it exists
if fileexists('kmarstructdata.ksd') then
begin
//load lines into the structure
filehandle:=fileopen( 'kmarstructdata.ksd', fmopenread);
fileread(filehandle, o, sizeof(o)); //got field count
i:=0;
while (o>i) do i:=formstructure.incdatalength+1;
for i:=0 to length(formstructure.structure)-1 do
begin //for every field
fileread(filehandle, o, sizeof(o));
setlength(formstructure.structure[i].Name, o);
fileread(filehandle, PChar(formstructure.structure[i].Name)^, o*sizeof(Char)); //got name
fileread(filehandle, o, sizeof(o));
case o of
0: FormStructure.Structure[i].DataType:=Default;
1: FormStructure.Structure[i].DataType:=MyInteger;
2: FormStructure.Structure[i].DataType:=MyFloat;
3: FormStructure.Structure[i].DataType:=MyString;
end; //end of case
fileread(filehandle, o, sizeof(integer)); //filter count
u:=0;
while (u<o) do u:=formstructure.structure[i].incfilterlength+1;
for u:=0 to length(FormStructure.structure[i].Filters)-1 do
begin
fileread(filehandle, o, sizeof(integer));
case o of
0: FormStructure.Structure[i].Filters[u].FilterType:=MinLength;
1: FormStructure.Structure[i].Filters[u].FilterType:=MaxLength;
2: FormStructure.Structure[i].Filters[u].FilterType:=LessThen;
3: FormStructure.Structure[i].Filters[u].FilterType:=MoreThen;
4: FormStructure.Structure[i].Filters[u].FilterType:=ExcludeChar;
5: FormStructure.Structure[i].Filters[u].FilterType:=IncludeChar;
end; //end of case
fileread(filehandle, o, sizeof(integer));
setlength(FormStructure.structure[i].Filters[u].FilterValue, o);
fileread(filehandle, PChar(FormStructure.structure[i].Filters[u].FilterValue)^, o*sizeof(char)); //got filter value!
end; //end of for(u)
end; //end of for(i)
end; //end of fileexists
end;
procedure TForm1.Changeform1Click(Sender: TObject);
begin
//summon form2
form2.Visible:=true;
form2.Summon(FormStructure);
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
i,o,u,ilimit,ulimit:integer;
filehandle:THandle;
begin
//save current structure in some file.
fileHandle:=filecreate('kmarstructdata.ksd', fmopenwrite);
o:=length(formstructure.structure);
filewrite(filehandle, o, sizeof(o));
for i:=0 to length(formstructure.structure)-1 do
begin
// formstructure.structure[i].Name, datatype, filter;
o:=length(formstructure.structure[i].Name); //name
filewrite(filehandle, o,sizeof(o));
filewrite(filehandle, PChar(formstructure.structure[i].name)^, o*sizeof(char));
{
case formstructure.structure[i].DataType of
default:
begin
o:=0;
end;
MyInteger:
begin
o:=1;
end;
MyFloat:
begin
o:=2;
end;
Mystring:
begin
o:=3;
end;
else o:=0;
end; //end of case }
o:=integer(formstructure.structure[i].DataType);
u:=filewrite(filehandle, o, sizeof(o)); //datatype
if u=-1 then showmessage('oops on file write!');
o:=length(formstructure.structure[i].Filters)-1;
filewrite(filehandle, o, sizeof(integer)); //how many filters
for u:=0 to length(formstructure.structure[i].Filters)-1-1 do
begin
//formstructure.structure[i].Filters[u].FilterType, value
case formstructure.structure[i].Filters[u].FilterType of
MinLength: o:=0;
MaxLength: o:=1;
LessThen: o:=2;
MoreThen: o:=3;
ExcludeChar: o:=4;
IncludeChar: o:=5;
else o:=0;
end; //end of case
filewrite(filehandle, o, sizeof(integer)); //filtertype
o:=length(formstructure.structure[i].Filters[u].FilterValue);
filewrite(filehandle, o, sizeof(integer));
filewrite(filehandle, PChar(formstructure.structure[i].Filters[u].FilterValue)^, o*sizeof(char)); //filtervalue
end; //end of for(u);
end; //end of for(i)
fileclose(filehandle);
FormStructure.Free;
end;
procedure TForm1.recive(NewStruct:TFormStructure);
var i:integer;
begin
//get new form to work with - this form will be saved in the future
// FormStructure.Free;
// FormStructure:=NewStruct;
caption:='';
for i:=0 to length(formstructure.structure)-1 do
caption:=caption+ ' ' + formstructure.structure[i].Name;
end;
Procedure StructUpdate;
begin
end;
end.