               UCalc Fast Math Parser 2.0
Spreadsheet sample code for VB, Delphi, and C++ Builder.


This sample consists of a grid which acts like a simple spreadsheet.
It includes the ucSpread.VBP project file for Visual Basic,
dlSpread.DPR for Delphi, and ucSpread.BPR for Borland C++ Builder,
as well as other associated files.

NOTE: Be sure UCALC32.DLL, and the include file(s) for your compiler
are there.  You may need to copy those files over to your sample
directory.

In a cell, you may either input a numeric value, or the = sign followed
by a formula which can refer to other cells.  Like:  

=A2+B1

When you leave the cell, all dependent cells are automatically updated.
You may rename a cell, by typing the new name in the text box next to
Cell Name, and press enter.  You can later use it in an expression
such as:   

=MyCell+B2+A1

There's also a box at the bottom where you can name a column (then
click on the button to activate it), and later refer to it as an
array as in:

=MyCol(3)+MyCol(2)-B5+10


Here's an explanation of how it works.  Cell values are mapped out into
an actual one-dimension array.  This array is named CellArray().  A
callback function, Cell(Row, Col) is created in order to access these
values.  The Cell() function can be thought of as a virtual 2-dimensional
array for the parser, which accesses the CellArray values.

When initialized, the grid columns, A, B, C, .... are mapped out as
functions which correspond to the appropriate cells, for instance
A(row) = Cell(row, 1),  B(row) = Cell(row, 2), etc...  At this point,
the parser doesn't recognize cell names like A1, B2, etc...  So,
the ProcessCellNames routine aliases names such as A1, B1 to
A(1), B(1) so that the parser now recognizes A1, B1 etc...

Each cell also has additional arrays to store a formula (when present)
in string form (only for displaying in the grid), and a pointer to the
parsed formula for the cell.  The pointers are used when dependent cells
are updated.  DepList is a kind of linked list, and DepStart holds
the starting point for the list of cells that depend on the current cell.

When a formula is entered in a cell, the current cell is added to the
dependency list of each cell referenced in the formula.  In turn, when
the values for those cells change, it goes through the dependency list
recursively updating all the dependent cells on its list.  The updated
dependent cells are not re-parsed, they are simply reevaluated.  This
is the key to making it run at maximum speed.

This is not by any means the only way of doing it.  But it is just to
give you an idea.  Also, this is just a starting point.  You will need
to make some adjustments if you want to make it more sophisticated.
The main idea in this code was to avoid the repeated use of time-
consuming process-intensive solutions like the ones that users were
showing me.

Daniel Corbier, UCALC
http://www.ucalc.com
Dancorbier@aol.com