Display method & example

Forums for specific tips, techniques and example code
Front
Posts: 2
Joined: Mon Oct 25, 2010 8:16 pm

Display method & example

Postby Front » Mon Oct 25, 2010 8:38 pm

Hi, there
I created a method in JadeScript to display the information of product and brand together.
Now I have two classes, product and brand.
I want to have a display method to show me the price and weight from product class, trademark and grade from brand class.
What code I should use?????
I can't find any example from the internet!
Thanks for helping!!! ^^

User avatar
Jade Support
Posts: 103
Joined: Mon Aug 17, 2009 10:27 am
Location: Jade Software Corporation, Christchurch

Re: Display method & example

Postby Jade Support » Tue Oct 26, 2010 7:46 am

Hello Front,

Thanks for your question. I've put together a very simple example schema (attached to this forum posting) that should allow you to see how this is achieved. Download both the ProductExampleSchema.scm and ProductExampleSchema.ddb files and together load them in to the JADE system you're using. They'll create a new schema called "ProductExampleSchema".

There are two JadeScript methods within the schema; createTestData() and getData(). The latter of which is shown below:

Code: Select all

getData() protected; vars root : Root; product : Product; brand : Brand; begin // Setup the Root object so we can access it's local collection // of Brands... root := Root.firstInstance; if root = null then write "Error: Root object is null, aborting."; return; endif; // Iterate each Brand object and then each Product within that // Brand's collection of Products... foreach brand in root.allBrands do foreach product in brand.allProducts do // Display the Product information... write "Name: " & product.name; write "Price: $" & product.price.String; write "Weight: " & product.weight.String & "g"; write "Brand Name: " & brand.name; write "Brand Trademark: " & brand.trademark; write "Brand Grade: " & brand.grade.String; write Cr; endforeach; endforeach; end;
If you first execute createTestData(), then getData() the following information will be output:
Name: Sliced Peaches
Price: $2.99
Weight: 300g
Brand Name: Store Brand
Brand Trademark: Store Brand Limited
Brand Grade: C


Name: Sliced Peaches
Price: $3.69
Weight: 300g
Brand Name: Watties
Brand Trademark: Watties Limited
Brand Grade: A
It's a very simple example but should show you how to store and retrieve persistent data in a JADE database using MemberKeyDictionary collections and a singleton 'Root' object.

Regards,
Attachments
ProductExampleSchema.ddb
(3.09 KiB) Downloaded 274 times
ProductExampleSchema.scm
(7.71 KiB) Downloaded 247 times
Jade Support
Jade Software Corporation Ltd

Email: jadesupport@jadeworld.com
Web: http://www.jadeworld.com

Jade Software – complex business problems solved beautifully.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 1 guest