|
|||||
|
Language / APIThe OrbC language is similar in style to C - using the same control constructs, expressions, and function style. The language supports four basic types (int, char, float, string), arrays, pointers, structs, objects, and interfaces. Although based on C, there are many differences that make the OrbC language easier to learn and use, and more efficient to work with. Features
If you are familiar with classic PocketC, the enhanced OrbC language will be refreshingly similar but much more powerful - with the addition of structs, objects, interfaces, and new features such as compound assignment. Handlers Rather than creating a "main" function as with traditional C (and classic PocketC), using the OrbC language you define event handlers. For example, if you wanted to create an application to calculate tips for a meal, you might create a field, a button, and a label (using the development environment), and write a handler for the button like this: handler calcButton.onselect() { float price; // get the meal's price price = fieldPrice.text; // do the math and set the label's text labelTip.text = price * 0.15; } Object-oriented API Much of the API exposed by the OrbC runtime is in the form of objects. For example, all the user interface elements (e.g. buttons, forms) are objects with methods (such as domodal(), and load()) and properties (such as x, y, visible). To demonstrate a small portion of the API usage, the following method below writes a record to a database. A database object is first created and opened, a record is retrieved from it, and some data (an "entry") is written: void RecordManager.writeRecord() { // write the current record to the database Database db; DBRecord rec; // open the database if (db.open("Data", false)) { if (db.getrec(recIndex, rec, false)) { rec.write(&entry, typeof(entry), 1); rec.close(); } db.close(); } } Classic PocketC Compatibility To ease the transition from PocketC to PocketC Architect, applications can be written using the classic PocketC model with a main() function and event loops. With the inclusion of compatibility headers, your classic PocketC application can be compiled by PocketC Architect with little modification: // Triangle @app myApp { creator = "TriA"; name = "Triangle"; dbname = "Triangle"; } #include "pc_most.oc" // compat header int tx[3], ty[3], x, y; main() { int i, r; tx[0] = 80; ty[0] = 24; tx[1] = 10; ty[1] = 150; tx[2] = 150; ty[2] = 150; r = random(3); x = tx[r]; y = ty[r]; graph_on(); title("Sierpinsky's Triangle"); while (true) { r = random(3); x = (x + tx[r])/2; y = (y + ty[r])/2; line(1, x, y, x, y); } } |
Copyright (c) 1997-2023 OrbWorks |