/[projects]/dao/DelphiScanner/Components/tpsystools_4.04/examples/Delphi/ExExpr2U.pas
ViewVC logotype

Contents of /dao/DelphiScanner/Components/tpsystools_4.04/examples/Delphi/ExExpr2U.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2671 - (show annotations) (download)
Tue Aug 25 18:15:15 2015 UTC (8 years, 9 months ago) by torben
File size: 6000 byte(s)
Added tpsystools component
1 (* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is TurboPower SysTools
15 *
16 * The Initial Developer of the Original Code is
17 * TurboPower Software
18 *
19 * Portions created by the Initial Developer are Copyright (C) 1996-2002
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * ***** END LICENSE BLOCK ***** *)
25
26 unit ExExpr2U;
27
28 interface
29
30 uses
31 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
32
33 StExpr, StBase, StConst;
34
35 type
36 TForm1 = class(TForm)
37 Button1: TButton;
38 edVar1: TEdit;
39 edVar2: TEdit;
40 edFunc1Param: TEdit;
41 edMeth1Param: TEdit;
42 edFunc0Param: TEdit;
43 edMeth0Param: TEdit;
44 edFunc2Param: TEdit;
45 edFunc3Param: TEdit;
46 edMeth2Param: TEdit;
47 edMeth3Param: TEdit;
48 lblVar1: TLabel;
49 lblVar2: TLabel;
50 lblFunc1: TLabel;
51 lblMeth1: TLabel;
52 lblFunc0: TLabel;
53 lblMeth0: TLabel;
54 lblMeth2: TLabel;
55 lblFunc2: TLabel;
56 lblFunc3: TLabel;
57 lblMeth3: TLabel;
58 Label1: TLabel;
59 Label2: TLabel;
60 Label3: TLabel;
61 Label4: TLabel;
62 Label5: TLabel;
63 Label6: TLabel;
64 Label7: TLabel;
65 Label8: TLabel;
66 StExpressionEdit1: TStExpressionEdit;
67 ListBox1: TListBox;
68 Exp: TStExpression;
69 Label9: TLabel;
70 Label10: TLabel;
71 lblError: TLabel;
72 procedure Button1Click(Sender: TObject);
73 procedure StExpressionEdit1AddIdentifier(Sender: TObject);
74 procedure StExpressionEdit1Error(Sender: TObject; ErrorNumber: Longint;
75 const ErrorStr: string);
76 private
77 { Private declarations }
78 public
79 { Public declarations }
80 Ref : TStFloat;
81 function MyMethod0Param : TStFloat;
82 function MyMethod1Param(Value : TStFloat) : TStFloat;
83 function MyMethod2Param(Value1, Value2 : TStFloat) : TStFloat;
84 function MyMethod3Param(Value1, Value2, Value3 : TStFloat) : TStFloat;
85 end;
86
87 var
88 Form1: TForm1;
89
90 implementation
91
92 {$R *.DFM}
93
94 function MyFunc0Param : TStFloat; far;
95 begin
96 Result := 10;
97 end;
98
99 function MyFunc1Param(Value : TStFloat) : TStFloat; far;
100 begin
101 Result := Value * 10;
102 end;
103
104 function MyFunc2Param(Value1, Value2 : TStFloat) : TStFloat; far;
105 begin
106 Result := Value1 + Value2;
107 end;
108
109 function MyFunc3Param(Value1, Value2, Value3 : TStFloat) : TStFloat; far;
110 begin
111 Result := Value1 + Value2 + Value3;
112 end;
113
114
115 function TForm1.MyMethod0Param : TStFloat;
116 begin
117 Result := 10;
118 end;
119
120 function TForm1.MyMethod1Param(Value : TStFloat) : TStFloat;
121 begin
122 Result := Value * 10;
123 end;
124
125 function TForm1.MyMethod2Param(Value1, Value2 : TStFloat) : TStFloat;
126 begin
127 Result := Value1 + Value2;
128 end;
129
130 function TForm1.MyMethod3Param(Value1, Value2, Value3 : TStFloat) : TStFloat;
131 begin
132 Result := Value1 + Value2 + Value3;
133 end;
134
135 procedure TForm1.Button1Click(Sender: TObject);
136 begin
137 Exp.ClearIdentifiers;
138 Exp.AddInternalFunctions;
139
140 {add variables and functions}
141 Exp.AddConstant('X', 5.5);
142 Exp.AddVariable('Ref', @Ref);
143 Exp.AddFunction0Param('Func0', MyFunc0Param);
144 Exp.AddFunction1Param('Func1', MyFunc1Param);
145 Exp.AddFunction2Param('Func2', MyFunc2Param);
146 Exp.AddFunction3Param('Func3', MyFunc3Param);
147 Exp.AddMethod0Param('Meth0', MyMethod0Param);
148 Exp.AddMethod1Param('Meth1', MyMethod1Param);
149 Exp.AddMethod2Param('Meth2', MyMethod2Param);
150 Exp.AddMethod3Param('Meth3', MyMethod3Param);
151
152 Ref := 6.6;
153 Exp.Expression := 'X * 2';
154 lblVar1.Caption := Exp.Expression;
155 edVar1.Text := Exp.AsString;
156
157 Ref := 7.6;
158 Exp.Expression := '(X * 2) + Ref';
159 lblVar2.Caption := Exp.Expression;
160 edVar2.Text := Exp.AsString;
161
162 Exp.AddFunction0Param('Func0', MyFunc0Param);
163 Exp.Expression := 'Func0';
164 lblFunc0.Caption := Exp.Expression;
165 edFunc0Param.Text := Exp.AsString;
166
167 Exp.AddFunction1Param('Func1', MyFunc1Param);
168 Exp.Expression := 'Func1(50)';
169 lblFunc1.Caption := Exp.Expression;
170 edFunc1Param.Text := Exp.AsString;
171
172 Exp.AddFunction2Param('Func2', MyFunc2Param);
173 Exp.Expression := 'Func2(50' + ListSeparator + ' 2)';
174 lblFunc2.Caption := Exp.Expression;
175 edFunc2Param.Text := Exp.AsString;
176
177 Exp.AddFunction3Param('Func3', MyFunc3Param);
178 Exp.Expression := 'Func3(50' + ListSeparator + ' 2' + ListSeparator + ' 30)';
179 lblFunc3.Caption := Exp.Expression;
180 edFunc3Param.Text := Exp.AsString;
181
182 Exp.AddMethod0Param('Meth0', MyMethod0Param);
183 Exp.Expression := 'Meth0';
184 lblMeth0.Caption := Exp.Expression;
185 edMeth0Param.Text := Exp.AsString;
186
187 Exp.AddMethod1Param('Meth1', MyMethod1Param);
188 Exp.Expression := 'Meth1(50)';
189 lblMeth1.Caption := Exp.Expression;
190 edMeth1Param.Text := Exp.AsString;
191
192 Exp.AddMethod2Param('Meth2', MyMethod2Param);
193 Exp.Expression := 'Meth2(50' + ListSeparator + ' 2)';
194 lblMeth2.Caption := Exp.Expression;
195 edMeth2Param.Text := Exp.AsString;
196
197 Exp.AddMethod3Param('Meth3', MyMethod3Param);
198 Exp.Expression := 'Meth3(50' + ListSeparator + ' 2' + ListSeparator + ' 30)';
199 lblMeth3.Caption := Exp.Expression;
200 edMeth3Param.Text := Exp.AsString;
201 end;
202
203 procedure TForm1.StExpressionEdit1AddIdentifier(Sender: TObject);
204 begin
205 StExpressionEdit1.Expr.GetIdentList(ListBox1.Items);
206 end;
207
208 procedure TForm1.StExpressionEdit1Error(Sender: TObject;
209 ErrorNumber: Longint; const ErrorStr: string);
210 begin
211 if ErrorNumber > 0 then
212 lblError.Caption := ErrorStr
213 else
214 lblError.Caption := '';
215 end;
216
217 end.

  ViewVC Help
Powered by ViewVC 1.1.20