分享

盒子论坛 v2.1

 和谐世界 2020-09-01
My sample to how use IFDStanExpressionEvaluator to create a expression and evaluate it using a Interbase table values
by Emailx45

the 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!    

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多