<< Click to Display Table of Contents >> Navigation: Expressions > Using custom variables getter/setter |
In some cases it is useful to have custom getter and setter for expression variables. For example, expression is used to calculate field value in Dataset, and all variables should be mapped to Dataset fields:
procedure GetDatasetVar(const V: TExVariable);
var F: TField;
begin
F := Dataset.FindField(V.Name);
if Assigned(F) then
V.fValue := F.AsVariant
end;
procedure SetDatasetVar(const V: TExVariable);
var F: TField;
begin
F := Dataset.FindField(V.Name);
if Assigned(F) then
F.Value := V.fValue;
end;
E := TScriptExpression.CreateandParse('MyField1:=MyField2+MyField3');
E.OnGetVar := GetDatasetVar;
E.OnSetVar := SetDatasetVar;
E.Calc;