Main page
KCompiler
Download
Contact Us
KCompiler component, v.1.11, copyright (C) 2002-2003, DOMIN Software

Here you may found some simple examples of KCompiler's usage

Evaluating the formula

KCompiler1.ExprString := 'a + b*sin(c)';
if KCompiler1.CompError = eNone then
  Edit1.Text := FloatToStr(KCompiler1.Evaluate)
else
  Edit1.Text := Msgs[KCompiler1.CompError]; //Msgs should contain error strings

Adding new variables

var
e : extended;
i : Integer;
w : word;
begin
KCompiler1.RegisterVarExt('VarE', vtExtended, @e);
KCompiler1.RegisterVarExt('VarI', vtInt32, @i);
KCompiler1.RegisterVarExt('VarW', vtUInt16, @w);
end;

Adding new functions

function SomeFunc(a : extended; b : double; var i : Integer) : word;
begin
  //some code
end;

//somewhere in your program
var
  AFunction : TFunction;
begin
  with AFunction do begin
    name := 'AFunc';
    CallType := ctRegister;
    SetLength(VarList, 3);
    VarList[0].VarType := vtExtended;
    VarList[0].PushStyle := psValue;
    VarList[1].VarType := vtDouble;
    VarList[1].PushStyle := psValue;
    VarList[2].VarType := vtInt32;
    VarList[2].PushStyle := psReference;
    FuncResult := frUInt16;
    StackNeeds := 8; //this value depends on function code
    FuncAddr := @SomeFunc;
    Simplify := true;
    InlinePart := nil;
  end;
  KCompiler1.RegisterFunc(AFunction);
end;
Hosted by uCoz