home *** CD-ROM | disk | FTP | other *** search
- {* FormulaBuilder 1.0 *}
- {* YGB Software, Inc. *}
- {* Copyright 1995 Clayton Collie *}
-
- {* This unit implements a simple demo of FormulaBuilder using *}
- {* DLL level calls *}
-
- unit Testfrm;
- interface
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, Spin;
-
- type
- TForm1 = class(TForm)
- BitBtn1: TBitBtn;
- BitBtn2: TBitBtn;
- ResultsPanel: TPanel;
- ResultMemo: TMemo;
- FunctionCountLabel: TLabel;
- BitBtn3: TBitBtn;
- Panel1: TPanel;
- ListBox1: TListBox;
- ComboBox1: TComboBox;
- Label1: TLabel;
- Label2: TLabel;
- Bevel1: TBevel;
- procedure BitBtn1Click(Sender: TObject);
- procedure FormActivate(Sender: TObject);
- procedure FormDeactivate(Sender: TObject);
- procedure ListBox1DblClick(Sender: TObject);
- procedure ListBox1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure BitBtn3Click(Sender: TObject);
- procedure ComboBox1Enter(Sender: TObject);
- private
- { Private declarations }
- fHandle : integer;
- ResultBuf : array[0..255] of char;
- Procedure DisplayError(const ecode : integer);
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
- uses
- fbcalc,funcdlg;
-
- {$R *.DFM}
- CONST
- EXPRFILENAME = 'Exprlist.txt';
-
- procedure TForm1.BitBtn1Click(Sender: TObject);
- var expstr : String;
- ec : integer;
- res : PChar;
-
- begin
- ExpStr := ComboBox1.Text + #0;
- if Length(expStr) = 0 then
- begin
- DisplayError(EXPR_BAD_EXPRESSION);
- exit;
- end;
- res := Resultbuf;
- ec := fbSetExpression(fHandle,@expStr[1]);
- if ec = EXPR_SUCCESS then
- begin
- ec := fbEvaluate(fHandle,res,sizeof(resultbuf));
- if ec <> EXPR_SUCCESS then
- DisplayError(ec)
- else
- ResultMemo.Text := Strpas(res);
- end
- else
- DisplayError(ec);
- end;
-
- Procedure TForm1.DisplayError(const ecode : integer);
- var ErrorStr : array[0..255] of char;
- p : pchar;
- s : string;
- begin
- MessageBeep(mb_iconhand);
- p := @ErrorStr;
- FBGetErrorString(ecode,ErrorStr,sizeof(ErrorStr));
- resultMemo.Text := Strpas(p);
- end;
-
- procedure TForm1.FormActivate(Sender: TObject);
- begin
- InitFbuilder; { Make sure its loaded }
- fHandle := FBInitExpression(longint(self));
- if fHandle <> -1 then
- FunctionCountLabel.Caption := 'Registered Functions : '+
- IntToStr(FBGetFunctionCount)
- else
- FunctionCountLabel.Caption := '????';
- end;
-
- procedure TForm1.FormDeactivate(Sender: TObject);
- begin
- FBFreeExpression(fHandle);
- FreeFBuilder; {Unload DLL}
- end;
-
- procedure TForm1.ListBox1DblClick(Sender: TObject);
- begin
- with listbox1 do
- ComboBox1.Text := Items[ItemIndex];
- end;
-
- procedure TForm1.ListBox1Click(Sender: TObject);
- begin
- with listbox1 do
- ComboBox1.Text := Items[ItemIndex];
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- If FileExists(EXPRFILENAME) then
- begin
- ListBox1.Clear;
- ListBox1.Items.LoadFromFile(EXPRFILENAME);
- end;
- end;
-
- procedure TForm1.BitBtn3Click(Sender: TObject);
- begin
- Functiondlg.ShowModal;
- end;
-
- procedure TForm1.ComboBox1Enter(Sender: TObject);
- begin
- With ComboBox1 do
- Items.Add( ComboBox1.Text );
- end;
-
- end.
-