My sample to how use IFDStanExpressionEvaluator to create a expression and evaluate it using a Interbase table values
by Emailx45the Interface is used for Evaluator of expressions, like in LiveBinding "magic"
as Interface, it dont need be "released", but is necessary "Null it" before close your table!
as necessary activate your table before create the expression to evaluate
as necessary re-positionate the cursor for next records, before use it!
is necessary study its use in each case!
/* Table: MYORACLETB, Owner: SYSDBA */
CREATE TABLE MYORACLETB
(
ID INTEGER NOT NULL,
MYNUMERIC2X0 NUMERIC(2, 0),
MYNUMERIC4X0 NUMERIC(4, 0),
MYNUMERIC8X0 NUMERIC(8, 0),
MYNUMERIC18X0 NUMERIC(18, 0),
MYNUMERIC20X4 NUMERIC(18, 4)
);
/* Meta data descriptions. This syntax requires InterBase 2020 or higher. Some tables require ODS18 and higher */
Source code using Interbase table for test
procedure TForm1.btnUsingIFDStanExpressionEvaluatorClick(Sender: TObject);
var
lIFDSExpEval: IFDStanExpressionEvaluator;
lResulted : Variant;
lExpression : string;
begin
lExpression := '((MYNUMERIC2X0 + MYNUMERIC4X0) + MYNUMERIC8X0)'; // cannot contain aggregate funcions!!!
//
try
FDQuery1.Open(); // before, it's necessary open your dataset!
//
if FDQuery1.IsEmpty then // are you want a exception?
begin
ShowMessage('Hey man, where are the values to evaluate?' + sLineBreak + 'So, I''m going to fuck you baby!');
exit;
end;
//
// dataset should be active!
lIFDSExpEval := FDQuery1.CreateExpression(lExpression);
//
// This method returns the evaluator, which can be used several times to effectively
// evaluate a specified expression by calling its Evaluate method. The evaluator is
// associated with the current record. After the position is changed, the application
// must adjust the evaluator
lResulted := lIFDSExpEval.Evaluate;
//
ShowMessage(lResulted);
//
FDQuery1.Next; // next record... same evaluator expression.
//
if not FDQuery1.Eof then // testing EOF for "end" evaluator-life!
begin
lIFDSExpEval.DataSource.Position := FDQuery1.GetRow;
//
lResulted := lIFDSExpEval.Evaluate;
//
ShowMessage(lResulted);
end;
//
// IMPORTANT: is necessary before close your dataset! dont need release it, is a Interface!
lIFDSExpEval := nil;
//
FDQuery1.Close;
except
on E: Exception do
ShowMessage('My Error: ' + sLineBreak + E.Message);
end;
end;
----------------------------------------------The higher the degree, the greater the respect given to the humblest!