Page 1 of 1

Sample code - calculator

Posted: Fri Aug 07, 2009 2:30 pm
by ConvertFromOldNGs
by Robert Barr >> Fri, 19 Jan 2001 0:49:09 GMT

The attached zip file contains some sample code for JADE 5.1.08 that may be of interest to those new to JADE. In fact I wrote this in response to a recent question from a client, who wished to allow users (I believe they were accounting clerks) to enter ad-hoc mathematical formulae, and pass these to the JADE compiler and interpreter for execution. The
sample calculator demonstrates this, and allows the user to select numerical property values of database instances (e.g. employee age, company asset value) and use these in the calculations.

Robert Barr
JADE Application Consultants


And the disclaimers ...

The intent of this code is to demonstrate a technique. I am aware of the potential for improvement to this code. However to encourage others to post code samples without apprehension, I request no critique on the newsgroup.

Aoraki Corporation Limited (Aoraki) believes that this software is accurate and reliable and has been prepared with care but can give no guarantee that the software will be free of defects or errors. No responsibility or liability, financial or otherwise, can be accepted for any consequences arising out of the use of this software including loss of profits, indirect, special or consequential losses or damages.

Re: Sample code - calculator

Posted: Fri Aug 07, 2009 2:30 pm
by ConvertFromOldNGs
by Wilfred Verkley >> Sun, 21 Jan 2001 0:33:36 GMT

Ive used the same technique for executing user-defined scripts in my applications. However, if your using 5.1.07+, i wouldnt use the JadeCompiler class. There are several as yet undocumented methods on the Process class which allow you to independtly compile and then execute scripts, and even pass parameters to them. Once compiled, the methods execute with the same performance as a native jade method. This will result in a massive performance improvement in your code if you need to repeatedly execute the same script over and over i.e. making a set of values for a graph.

vars
code : String;
m : JadeMethod;
err, pos, len: Integer;begin

code := "return 1 + 2 + 3;";

m := process.createTransientMethod (
"testMethod", // name of the method
JadeScript, // the class of the object it will execute on
currentSchema, // the schema it will execute in
code, // the code
true, // is it a workspace method? means the code syntax requirements are less strict.
Integer, // the return type
err, pos, len // compilation error info
);
if m <> null then
write process.executeTransientMethod (m, self).Integer;
else
write "Houston, we have a problem";
endif;
epilog
if m <> null then
process.deleteTransientMethod (m);
endif;
end;


Use executeTransientIOMethod if you want to pass parameters to your method.


Wilfred.

Re: Sample code - calculator

Posted: Fri Aug 07, 2009 2:30 pm
by ConvertFromOldNGs
by Craig Shearer >> Sun, 21 Jan 2001 21:15:00 GMT

Be aware that the code that Wilfred proposes uses an as-yet-undocumented and unpublished (!) feature. I have no idea where he got that information from :-) (But then, I don't think that the JadeCompiler class has ever been officially sanctioned either)

Craig.