Sample code - calculator

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Sample code - calculator

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:30 pm

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.
Attachments
1833_2.zip
(13.38 KiB) Downloaded 222 times
Last edited by ConvertFromOldNGs on Fri Aug 07, 2009 3:56 pm, edited 1 time in total.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Sample code - calculator

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:30 pm

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.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Sample code - calculator

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:30 pm

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.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 29 guests