// Borland C++ Builder
// Copyright (c) 1995, 1999 by Borland International
// All rights reserved

// (DO NOT EDIT: machine generated header) 'AdvPars.pas' rev: 5.00

#ifndef AdvParsHPP
#define AdvParsHPP

#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include <AdvGrid.hpp>	// Pascal unit
#include <Grids.hpp>	// Pascal unit
#include <SysUtils.hpp>	// Pascal unit
#include <Classes.hpp>	// Pascal unit
#include <Windows.hpp>	// Pascal unit
#include <SysInit.hpp>	// Pascal unit
#include <System.hpp>	// Pascal unit

//-- user supplied -----------------------------------------------------------

namespace Advpars
{
//-- type declarations -------------------------------------------------------
#pragma option push -b-
enum TokenType { Delimiter, Non, Variable, Digit, EndExpr, Error, Func, Operator };
#pragma option pop

struct TokenRec;
typedef TokenRec *TokenPtr;

struct TokenRec
{
	TokenRec *Next;
	short Start;
	short Close;
} ;

typedef void __fastcall (__closure *TIsCustomFunction)(System::TObject* sender, AnsiString &func, bool 
	&match);

typedef void __fastcall (__closure *TCalcCustomFunction)(System::TObject* sender, AnsiString &func, 
	double &param);

typedef void __fastcall (__closure *TErrorEvent)(System::TObject* Sender, int ACol, int ARow, int ErrType
	, int ErrPos, int ErrParam, AnsiString ErrStr);

class DELPHICLASS TParamList;
class PASCALIMPLEMENTATION TParamList : public System::TObject 
{
	typedef System::TObject inherited;
	
private:
	void *FList;
	int FCount;
	int __fastcall GetCount(void);
	double __fastcall GetItem(int Index);
	void __fastcall SetItem(int Index, const double Value);
	
public:
	__fastcall TParamList(void);
	__fastcall virtual ~TParamList(void);
	void __fastcall Add(double Item);
	void __fastcall Clear(void);
	__property int Count = {read=GetCount, nodefault};
	__property double Items[int Index] = {read=GetItem, write=SetItem};
};


class DELPHICLASS TMathLib;
class PASCALIMPLEMENTATION TMathLib : public Classes::TComponent 
{
	typedef Classes::TComponent inherited;
	
public:
	virtual bool __fastcall HandlesConstant(AnsiString Constant);
	virtual double __fastcall GetConstant(AnsiString Constant);
	virtual bool __fastcall HandlesFunction(AnsiString FuncName);
	virtual double __fastcall CalcFunction(AnsiString FuncName, TParamList* Params, int &ErrType, int &
		ErrParam);
	AnsiString __fastcall GetErrorMessage(int ErrType);
	virtual AnsiString __fastcall GetEditHint(AnsiString FuncName, int ParamIndex);
public:
	#pragma option push -w-inl
	/* TComponent.Create */ inline __fastcall virtual TMathLib(Classes::TComponent* AOwner) : Classes::TComponent(
		AOwner) { }
	#pragma option pop
	#pragma option push -w-inl
	/* TComponent.Destroy */ inline __fastcall virtual ~TMathLib(void) { }
	#pragma option pop
	
};


class DELPHICLASS TGridBinderItem;
class PASCALIMPLEMENTATION TGridBinderItem : public Classes::TCollectionItem 
{
	typedef Classes::TCollectionItem inherited;
	
private:
	Grids::TStringGrid* FGrid;
	AnsiString FName;
	
public:
	__fastcall virtual TGridBinderItem(Classes::TCollection* Collection);
	__fastcall virtual ~TGridBinderItem(void);
	virtual void __fastcall Assign(Classes::TPersistent* Source);
	
__published:
	__property Grids::TStringGrid* Grid = {read=FGrid, write=FGrid};
	__property AnsiString Name = {read=FName, write=FName};
};


class DELPHICLASS TGridBinderItems;
class DELPHICLASS TGridBinder;
class PASCALIMPLEMENTATION TGridBinder : public Classes::TComponent 
{
	typedef Classes::TComponent inherited;
	
private:
	TGridBinderItems* FGrids;
	void __fastcall SetGrids(const TGridBinderItems* Value);
	
protected:
	virtual void __fastcall Notification(Classes::TComponent* AComponent, Classes::TOperation AOperation
		);
	
public:
	__fastcall virtual TGridBinder(Classes::TComponent* AOwner);
	__fastcall virtual ~TGridBinder(void);
	
__published:
	__property TGridBinderItems* Grids = {read=FGrids, write=SetGrids};
};


class PASCALIMPLEMENTATION TGridBinderItems : public Classes::TCollection 
{
	typedef Classes::TCollection inherited;
	
private:
	TGridBinder* FOwner;
	HIDESBASE TGridBinderItem* __fastcall GetItem(int Index);
	HIDESBASE void __fastcall SetItem(int Index, const TGridBinderItem* Value);
	Grids::TStringGrid* __fastcall GetGridByName(AnsiString Name);
	
public:
	HIDESBASE TGridBinderItem* __fastcall Add(void);
	__fastcall TGridBinderItems(TGridBinder* AOwner);
	DYNAMIC Classes::TPersistent* __fastcall GetOwner(void);
	__property TGridBinderItem* Items[int Index] = {read=GetItem, write=SetItem};
	__property Grids::TStringGrid* GridByName[AnsiString Name] = {read=GetGridByName};
public:
	#pragma option push -w-inl
	/* TCollection.Destroy */ inline __fastcall virtual ~TGridBinderItems(void) { }
	#pragma option pop
	
};


class DELPHICLASS TLibBinderItem;
class PASCALIMPLEMENTATION TLibBinderItem : public Classes::TCollectionItem 
{
	typedef Classes::TCollectionItem inherited;
	
private:
	TMathLib* FMathLib;
	
public:
	__fastcall virtual TLibBinderItem(Classes::TCollection* Collection);
	__fastcall virtual ~TLibBinderItem(void);
	virtual void __fastcall Assign(Classes::TPersistent* Source);
	
__published:
	__property TMathLib* MathLib = {read=FMathLib, write=FMathLib};
};


class DELPHICLASS TLibBinderItems;
class DELPHICLASS TLibBinder;
class PASCALIMPLEMENTATION TLibBinder : public Classes::TComponent 
{
	typedef Classes::TComponent inherited;
	
private:
	TLibBinderItems* FLibs;
	void __fastcall SetLibs(const TLibBinderItems* Value);
	
protected:
	virtual void __fastcall Notification(Classes::TComponent* AComponent, Classes::TOperation AOperation
		);
	
public:
	__fastcall virtual TLibBinder(Classes::TComponent* AOwner);
	__fastcall virtual ~TLibBinder(void);
	
__published:
	__property TLibBinderItems* Libs = {read=FLibs, write=SetLibs};
};


class PASCALIMPLEMENTATION TLibBinderItems : public Classes::TCollection 
{
	typedef Classes::TCollection inherited;
	
private:
	TLibBinder* FOwner;
	HIDESBASE TLibBinderItem* __fastcall GetItem(int Index);
	HIDESBASE void __fastcall SetItem(int Index, const TLibBinderItem* Value);
	
public:
	HIDESBASE TLibBinderItem* __fastcall Add(void);
	__fastcall TLibBinderItems(TLibBinder* AOwner);
	DYNAMIC Classes::TPersistent* __fastcall GetOwner(void);
	__property TLibBinderItem* Items[int Index] = {read=GetItem, write=SetItem};
public:
	#pragma option push -w-inl
	/* TCollection.Destroy */ inline __fastcall virtual ~TLibBinderItems(void) { }
	#pragma option pop
	
};


class DELPHICLASS TGridFormula;
class PASCALIMPLEMENTATION TGridFormula : public System::TObject 
{
	typedef System::TObject inherited;
	
private:
	int i;
	int Varlen;
	bool FFirstError;
	AnsiString FOrigExpression;
	AnsiString FExpression;
	int FCol;
	int FRow;
	int FErrorPosition;
	Advgrid::TAdvStringGrid* FStringGrid;
	Classes::TStringList* FCellNameList;
	TIsCustomFunction FIsCustomFunction;
	TCalcCustomFunction FCalcCustomFunction;
	bool FUseRCNames;
	TLibBinder* FMathLib;
	TGridBinder* FBinder;
	TErrorEvent FOnError;
	System::Set<char, 0, 255>  FTokenEnd;
	System::Set<char, 0, 255>  FParamEnd;
	AnsiString __fastcall ReadWord();
	double __fastcall ReadNumber(void);
	TokenType __fastcall GetToken(void);
	bool __fastcall MatchFunc(AnsiString Match, double &Res, TokenType &n);
	bool __fastcall MatchDualParamFunc(AnsiString Match, double &Res1, double &Res2, TokenType &n);
	bool __fastcall MatchTriParamFunc(AnsiString Match, double &Res1, double &Res2, double &Res3, TokenType 
		&n);
	bool __fastcall MatchVarParamFunc(AnsiString Match, TParamList* pl, TokenType &n);
	bool __fastcall MatchToken(AnsiString Match);
	bool __fastcall DoPI(double &r);
	bool __fastcall DoE(double &r);
	bool __fastcall DoTrue(double &r);
	bool __fastcall DoFalse(double &r);
	bool __fastcall DoCol(double &r);
	bool __fastcall DoRow(double &r);
	bool __fastcall DoNow(double &r);
	bool __fastcall DoToday(double &r);
	bool __fastcall DoChoose(double &Res, TokenType &n);
	bool __fastcall DoLt(double &Res, TokenType &n);
	bool __fastcall DoSt(double &Res, TokenType &n);
	bool __fastcall DoEq(double &Res, TokenType &n);
	bool __fastcall DoFrac(double &Res, TokenType &n);
	bool __fastcall DoFact(double &Res, TokenType &n);
	bool __fastcall DoInt(double &Res, TokenType &n);
	bool __fastcall DoChs(double &Res, TokenType &n);
	bool __fastcall DoSin(double &Res, TokenType &n);
	bool __fastcall DoCos(double &Res, TokenType &n);
	bool __fastcall DoTan(double &res, TokenType &n);
	bool __fastcall DoCoTan(double &res, TokenType &n);
	bool __fastcall DoSinh(double &Res, TokenType &n);
	bool __fastcall DoCosh(double &Res, TokenType &n);
	bool __fastcall DoTanh(double &res, TokenType &n);
	bool __fastcall DoCoTanh(double &res, TokenType &n);
	bool __fastcall DoMonth(double &res, TokenType &n);
	bool __fastcall DoYear(double &res, TokenType &n);
	bool __fastcall DoDay(double &res, TokenType &n);
	bool __fastcall DoDayOfWeek(double &res, TokenType &n);
	bool __fastcall DoMinute(double &res, TokenType &n);
	bool __fastcall DoSecond(double &res, TokenType &n);
	bool __fastcall DoHour(double &res, TokenType &n);
	bool __fastcall DoExp(double &Res, TokenType &n);
	bool __fastcall DoLn(double &res, TokenType &n);
	bool __fastcall DoLog10(double &res, TokenType &n);
	bool __fastcall DoLog2(double &res, TokenType &n);
	bool __fastcall DoAbs(double &res, TokenType &n);
	bool __fastcall DoArcTan(double &res, TokenType &n);
	bool __fastcall DoArcCoTan(double &res, TokenType &n);
	bool __fastcall DoRound(double &res, TokenType &n);
	bool __fastcall DoTrunc(double &res, TokenType &n);
	bool __fastcall DoDegrees(double &res, TokenType &n);
	bool __fastcall DoRadians(double &res, TokenType &n);
	bool __fastcall DoRand(double &res, TokenType &n);
	bool __fastcall DoSqr(double &res, TokenType &n);
	bool __fastcall DoCube(double &res, TokenType &n);
	bool __fastcall DoSqrt(double &res, TokenType &n);
	bool __fastcall DoArcSin(double &res, TokenType &n);
	bool __fastcall DoArcCos(double &res, TokenType &n);
	bool __fastcall DoSum(double &res, TokenType &n);
	bool __fastcall DoProduct(double &res, TokenType &n);
	bool __fastcall DoAverage(double &res, TokenType &n);
	bool __fastcall DoCount(double &res, TokenType &n);
	bool __fastcall DoMin(double &res, TokenType &n);
	bool __fastcall DoMax(double &res, TokenType &n);
	bool __fastcall DoStDev(double &res, TokenType &n);
	bool __fastcall DoDevSQ(double &res, TokenType &n);
	bool __fastcall DoStDevP(double &res, TokenType &n);
	bool __fastcall DoPower(double &res, TokenType &n);
	bool __fastcall DoVar(double &res, TokenType &n);
	void __fastcall DoFunc(double &res, TokenType &n);
	void __fastcall Primitive(double &Res, TokenType &n);
	double __fastcall Sign(double Number);
	void __fastcall Level6(double &res, TokenType &n);
	void __fastcall Level5(double &res, TokenType &n);
	void __fastcall Level4(double &res, TokenType &n);
	void __fastcall Level3(double &res, TokenType &n);
	void __fastcall Level2(double &res, TokenType &n);
	void __fastcall Level1(double &res, TokenType &n);
	double __fastcall GetExpr(bool &Valid);
	void __fastcall DoErr(TokenType &n, int ErrPos, int ErrType, AnsiString ErrStr);
	int __fastcall GetNextVar(AnsiString &Full, AnsiString &Expr, AnsiString &c, AnsiString &r);
	bool __fastcall IsCellVar(void);
	bool __fastcall GetCellRange(AnsiString Sheet, AnsiString Range, TParamList* Params);
	double __fastcall GetCellVar(void);
	double __fastcall GetCellVal(AnsiString Sheet, int ACol, int ARow);
	int __fastcall IsCellNameRef(AnsiString Match);
	bool __fastcall SolveCellNameRef(AnsiString Match, double &Res);
	Windows::TPoint __fastcall GetCoord(AnsiString rng);
	AnsiString __fastcall GetExpression();
	void __fastcall SetExpression(const AnsiString Value);
	
public:
	__fastcall TGridFormula(Advgrid::TAdvStringGrid* Grid);
	__fastcall virtual ~TGridFormula(void);
	__property AnsiString Expression = {read=GetExpression, write=SetExpression};
	__property int Row = {read=FRow, write=FRow, nodefault};
	__property int Col = {read=FCol, write=FCol, nodefault};
	__property int ErrorPosition = {read=FErrorPosition, write=FErrorPosition, nodefault};
	bool __fastcall Calc(double &r);
	__property Classes::TStringList* CellNameList = {read=FCellNameList};
	__property bool UseRCNames = {read=FUseRCNames, write=FUseRCNames, nodefault};
	
__published:
	__property TGridBinder* Binder = {read=FBinder, write=FBinder};
	__property TLibBinder* Libs = {read=FMathLib, write=FMathLib};
	__property TIsCustomFunction IsCustomFunction = {read=FIsCustomFunction, write=FIsCustomFunction};
	__property TCalcCustomFunction CalcCustomFunction = {read=FCalcCustomFunction, write=FCalcCustomFunction
		};
	__property TErrorEvent OnError = {read=FOnError, write=FOnError};
};


//-- var, const, procedure ---------------------------------------------------
static const Shortint Error_NoError = 0x0;
static const Shortint Error_NoFormula = 0x1;
static const Shortint Error_DivisionByZero = 0x2;
static const Shortint Error_InvalidValue = 0x3;
static const Shortint Error_InvalidCellRef = 0x4;
static const Shortint Error_InvalidRangeRef = 0x5;
static const Shortint Error_InvalidGridRef = 0x6;
static const Shortint Error_InvalidNrOfParams = 0x7;
static const Shortint Error_CircularReference = 0x8;
static const Shortint Error_NoOpenParenthesis = 0x9;
static const Shortint Error_NoCloseParenthesis = 0xa;
static const Shortint Error_PrematureEndOfFormula = 0xb;
static const Shortint Error_UnknownError = 0xc;
static const Shortint Error_InvalidQualifier = 0xd;
static const Shortint Error_InvalidTokenAtPosition = 0xe;
static const Shortint Error_Overflow = 0xf;
static const Shortint Error_Underflow = 0x10;
static const Shortint Error_MaxErrorNumber = 0x64;
#define err_recurs "Circular cell reference in formula"
#define err_recursrange "Circular range reference in formula"
#define err_invalrange "Invalid range"
#define err_empty "Empty formula"
extern PACKAGE int __fastcall VarPos(AnsiString su, AnsiString s, int &vp);

}	/* namespace Advpars */
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Advpars;
#endif
#pragma option pop	// -w-
#pragma option pop	// -Vx

#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif	// AdvPars
