How evaluate user condition script with my class
Dear Friends,
I am writing an application that in some steps should check user defined condition.
User condition is based on my defined class properties. I wrote bellow code but failed !!!
type
TMyClass = class(TObject)
fstr: string;
fval : integer;
public
property str: string read fstr write fstr;
property val: integer read fval write fval;
public
end;
function TForm37.GetProp(Instance: TObject; ClassType: TClass;const PropName: String): Variant;
begin
Result := 0;
if PropName = 'STR' then
Result := TMyClass(Instance).str;
if PropName = 'VAL' then
Result := TMyClass(Instance).val;
end;
procedure TForm37.SetProp(Instance: TObject; ClassType: TClass;const PropName: String; Value: Variant);
begin
if PropName = 'STR' then
TMyClass(Instance).str := Value;
if PropName = 'VAL' then
TMyClass(Instance).val := Value;
end;
var
cl: TMyClass;
begin
cl := TMyClass.Create;
cl.val := 120;
cl.str := 'book';
fsScript1.Clear;
with fsScript1.AddClass(TMyClass, 'TObject') do begin
AddProperty('str', 'String', GetProp, SetProp);
AddProperty('val', 'Integer', GetProp, SetProp);
end;
fsScript1.AddObject('cl', cl);
showMessage(fsScript1.Evaluate('cl.val > 100 '));
showMessage(fsScript1.Evaluate('cl.str=''Book'''));
showMessage(fsScript1.Evaluate('cl.val > 100 or cl.str=''Book'''));
end;
what is my mistake?
I am writing an application that in some steps should check user defined condition.
User condition is based on my defined class properties. I wrote bellow code but failed !!!
type
TMyClass = class(TObject)
fstr: string;
fval : integer;
public
property str: string read fstr write fstr;
property val: integer read fval write fval;
public
end;
function TForm37.GetProp(Instance: TObject; ClassType: TClass;const PropName: String): Variant;
begin
Result := 0;
if PropName = 'STR' then
Result := TMyClass(Instance).str;
if PropName = 'VAL' then
Result := TMyClass(Instance).val;
end;
procedure TForm37.SetProp(Instance: TObject; ClassType: TClass;const PropName: String; Value: Variant);
begin
if PropName = 'STR' then
TMyClass(Instance).str := Value;
if PropName = 'VAL' then
TMyClass(Instance).val := Value;
end;
var
cl: TMyClass;
begin
cl := TMyClass.Create;
cl.val := 120;
cl.str := 'book';
fsScript1.Clear;
with fsScript1.AddClass(TMyClass, 'TObject') do begin
AddProperty('str', 'String', GetProp, SetProp);
AddProperty('val', 'Integer', GetProp, SetProp);
end;
fsScript1.AddObject('cl', cl);
showMessage(fsScript1.Evaluate('cl.val > 100 '));
showMessage(fsScript1.Evaluate('cl.str=''Book'''));
showMessage(fsScript1.Evaluate('cl.val > 100 or cl.str=''Book'''));
end;
what is my mistake?