|How to write dynamic programs?|
What does it actually mean?
As is generally known tdbengine is a database engine, an interpreter and acompiler in one.
So we are happy that a source code written in EASY can be compiled.
Many potential errors in the code found without compiler only at
the runtime of Interpreter would cause a data chaos. Imagine while
doing a backup interpreter finds out that a parrameter of a function
will transfered as a wrong type and aborts the process. The question is
now do you have a backup or you don't.
sometime it would be of use if you could mix the fixed structure up.
That could help to keep source codes abstact to use them easier in
other projects. It would also allow us to give the user of our
applications powerful tools. In other database systems like MS ACCESS
you have a SQL editor, too, which you can do many things (in line with
Fortunately tdbengine offers divers options how to affect dynamic program stream. That's what I want to specify to you. DO _"continue_reading()"
Using DO combined with _ (underline) you can analyse and following run any expression.
VAR x : STRING = "cgiwriteln('hello world')"
at runtime more precisely when the interpreter comes in the second line
to the underline the value of the variable x will be analysed. Here
it's nothing mind because it's value is alleged. DO makes tdbengine running the expression delivered by the underline _. In this situation we also could do it easier:
It would suffice.
PROCEDURE deletefromadressen(nID : INTEGER)
//exemplarily delete routine
DelRec(dbADDRESSES, FindAuto(dbADDRESSES, nID))
PROCEDURE deletefromniederlassungen(nID : INTEGER)
DelRec(dbNETHERL, FindAuto(dbNETHERL, nID))
PROCEDURE delete(cTable : STRING; nID : INTEGER)
VAR x : STRING = "deletefrom"+cTable+"("+Str(nID)+")"
//analyse x at runtime AND "run" it's result
We assume that any table in our project will need a table specific
cleanup if datasets will be deleted. But in the whole application
should be used only one routine
delete(). This routine has to take care for running the deleteform...()
procedure that belongs to the table. Sure, we could do it with a
IF-THEN-ELSIF-ELSE-END monster ,too. But with any new table this IF tree would grow in and some projects it could pssibly become very
complex. In the example the variables affect the program action at the
The function Val()
Val() evaluates any strings. At least Val() tries to do it. In other words Val() makes a string out of an integer.
VAR c1 : STRING = "123"
VAR c2 : STRING = "123 + 321 + 1 / 2 * 3"
VAR c3 : STRING = "Val(c1) + Val(c2)"
VAR c4 : STRING = "Val('999' + Str(Val(c3),0,2))"
VAR n : REAL
n:=Val(c1) // n = 123
n:=Val(c2) // n = 445,5
n:=Val(c3) // n = 568,5
n:=Val(c4) // n = 999568,5
So you see with Val() you can evaluate nearly any string. Thereby they may also access functions and variables of the program.
However thereto you have to set the runtime switchnv to 0.
The function ExecProg()
ExecProg(cFilename : STRING)
Compiles and runs any EASY programs.
Thereby cFilename may refer both file and ramtext:.
(Very easy) Example:
VAR c : STRING
VAR f : INTEGER = Rewrite("ramtext:code")
WriteLn(f, "Procedure XYZ : String")
WriteLn(f, " RETURN 'xyz'")
WriteLn(f, "c := xyz")
Here the ramtext:code will be written only at the runtime following compiled and runed with ExecProg().
selection programs demonstrate an interesting application which will
be individually assembled only at runtime of the blocks. An (A very
application area is here for example analysis and conversion of SQL
statements Anwendungsgebiet wäre hier zum Beispiel die Auswertung
von SQL-Statements to EASY code.
Author: Thomas Friebel <email@example.com>