|
Software Development Kit to the Delphi-Win32 and Free Pascal compilers |
| Home > Wiki > br/Expressões Matemáticas |
br/Expressões Matemáticasenglish (en) | português (br) O Press possui um interpretador de expressões matemáticas com suporte a variáveis e funções. Segue um exemplo de uso. Unidade com função customizada: unit ufnc;
interface
uses
PressExpression;
type
TAoCubo = class(TPressExpressionFunction)
public
function MaxParams: Integer; override;
function MinParams: Integer; override;
class function Name: string; override;
procedure VarCalc; override;
end;
implementation
function TAoCubo.MaxParams: Integer;
begin
Result := 1;
end;
function TAoCubo.MinParams: Integer;
begin
Result := 1;
end;
class function TAoCubo.Name: string;
begin
Result := 'AoCubo';
end;
procedure TAoCubo.VarCalc;
begin
Res^ := Params[0]^ * Params[0]^ * Params[0]^;
end;
end.
Módulo principal: program expr;
uses
heaptrc, PressExpression, PressExpressionLib, ufnc;
var
e: TPressExpression;
begin
e := TPressExpression.Create('(2 = sqrt(b)) and (b-2 = c) and (AoCubo(c) = c*c*c)');
try
PressExpressionLibrary.RegisterFunctions([TAoCubo]);
e.Vars.VarByName('b').Value := 4;
e.Vars.VarByName('c').Value := 2;
writeln(e.VarValue);
e.Vars.VarByName('c').Value := 3;
writeln(e.VarValue);
finally
e.Free;
end;
readln;
end.
|
Personal tools |