Saturday 8 February 2020

The importance of private

Hello, I was very very busy in the last months; so I restart to write posts now and this is a short post, but useful, post.

You know a  Livecode program is made of many object nested one inside another:
and livecode for every call, search that function or message from the stack to the nested element, so to avoid ambiguity in very big project, you can prefix the word private, so that function or message is visible only in that object (card, stack, button or else).
Example:
private function increase
      answer "Increase the volume"
end increase


Thursday 29 August 2019

SQLite

You asked for it, so here a guide to SQLite.
Livecode can work with any database. Livecode has integrated SQLite, but you can interface with any database that has an ODBC interface (almost all have it), here are the most popular:
  • SQLite
  • MySQL
  • Oracle
  • PostgreSQL
  • Valentina DB

Databases are usually files outside our program that can be on the same PC on which our program runs or on a remote server. The databases contain lots of cataloged information. Thanks to the databases we can search for information, insert or delete data, all according to specific criteria that we set ourselves.
The language used by almost all databases is SQL. Generally the valid commands for a database also apply to all others.
Summarizing in a few words a database, we can say that it is a collection of tables, within each table the data are organized by rows and by columns.
Databases have advantages:
  • quick to find the data you need among thousands of data
  • take up little space
  • they are optimized to do their job
  • they are very fast (very, very, very fast)
  • it is possible to cross the data of several tables easily

You could do the same things as a database with an array; but if you deal with a lot of data, I suggest you learn how to use databases.

Connection

A database can be an external running program, you talk with it and it answers you. Thisi is called client/server database. (MySQL, Oracle, PostgreSQL)
A database can be simply just a file (SQLite).
To use a database you must first connect to a database (server or file), using the revOpenDatabase () function and store the connection identifier. For example with SQLite we will write:
put revOpenDatabase("sqlite", "./myDB.sqlite", , , , ) into connID


If livecode doesn't find the file, Livecode will create it.
In this example the connID variable contains the connection identifier (it's just a number). You can establish multiple connections simultaneously.

Query

To retrieve information from the database, in jargon it is said to query, just use the command the revDataFromQuery function, specifying how to separate rows and columns:

put "SELECT * FROM users ; " into tSQL
put revDataFromQuery(tab,return,connID,tSQL) into tRecords


in this case we have that tRecords contains all the data where each column is separated from the other by the TAB character and each row by a line. You can change this form, but it is very convenient because it allows you to view the data in a text field like a real table (field, label).

Execution

To execute commands that change in the database, or make more complex actions, just use the revExecuteSQL command, for example:

put "INSERT into users (name,surname) VALUES ('Jack','Sparrow')" into tSQL
revExecuteSQL connID,tSQL

Speeding execution

Sometime you need to send many commands one after another, like inserting a lot of data, or updating a lot of data. In this case is much better to use transactions. Transaction is a list of task, the database reads them all and then decide the best strategy to do all task in the shortest time possible.
For example:

put "BEGIN TRANSACTION;" into myQuery
put "INSERT INTO myTable (name, surname) VALUES ('Mark', 'Red') ;" after myQuery
put "INSERT INTO myTable (name, surname) VALUES ('John', 'Green') ;" after myQuery
--..... a lot of data more
put "INSERT INTO myTable (name, surname) VALUES ('Elvis', 'Yellow') ;" after myQuery
put "COMMIT;" after myQuery
revExecuteSQL connID,myQuery

Check  column existence

SQLite is simple fast, portable and compact, but it misses some complex function like how to know if a table column exists. You can do it, but it needs to call PRAGMA.
Here the example code:
put "PRAGMA table_info(myTable);" into tSQL
put revDataFromQuery(comma,return,connID,tSQL) into tRecords
if "muyColumn" is not among the items of tRecords then   
   answer "Column myColumn doesn't exist"
else
   answer "Column myColumn exists!"
end if

Close the connection

When working on databases installed on client/server type, it is advisable to close the connection when you no longer work with the database, here is the code:
revCloseDatabase connID


Friday 23 August 2019

Livecode 9.5 stable

This version brings you a raft of new exciting features and benefits.
  1. New Android Architectures (32/64 bit) + support for the latest Google Play
  2. Store requirements. Create your app for the latest and greatest Android OS's, with fast simulators to help you preview and test.
  3. Windows 64 bit IDE & deployment support. Write code on and for 64bit Window's operating systems, ensuring your app is fast and smooth wherever it runs. LiveCode 9 has supported 64 bit on Mac, iOS and Linux for a while, now Windows can join the party.
  4. PDF Widget (Business Edition). A powerful full featured drag and drop widget to view and edit PDF files on desktop and mobile.
  5. Android Barcode Scanner Widget (Indy + Business Edition). Your Android apps can now scan barcodes just like your iOS apps.
  6. New Container Layer Mode. Build beautiful tables and grids that scroll fast and smoothly.
  7. New mobileSetKeyboardDisplay and
  8. mobileGetKeyboardDisplay handlers. Pan your screen view up to ensure your controls remain in view above the keyboard when needed.
  9. Progress, isSecure and allowUserInteraction features added to the browser widget. Need we say more? The beauty of the LiveCode language is that it is self explanatory.
  10. Several enhancements to Tree View Widget. You can now auto expand to reveal a row when selected and get and set the fold state of a specific row.
  11. Mac status menu library added. Use the new library to create, delete and set properties on a status menu.
  12. Improved sort international to support lots of additional locales. Useful if you are creating an app in several languages.
Additionally between version 9.0 and 9.5, Livecode squished over 400 bugs, giving you a noticeable boost in performance and stability.

Wednesday 3 July 2019

Assembler emulator

Here it is an assembler x86 emulator wrote in Livecode by Andre Garcia:
You can download from here:: http://tinyurl.com/p48nhwd
There are 4 registers: ax, bx, cx, dx.
These are the commands;
  • GET - ask a number
  • PUT - shows ax register
  • MOV - copy the target register
    • MOV <target>, <register>
    • MOV <target>, <number>
  • CMP - compare registers
  • JA - jump if greater than
  • JB - jump if less than
  • JAE - jump if greater or equal
  • JBE - jump if less or equal
  • JNA - jump if not greater
  • JNB -jump if not less
  • JE -jump if equal
  • JNE -jump if not equal
  • JMP - jump!
  • XCHG - exchange 2 registers
  • ADD - add
  • SUB - subtract
  • AND - bitwise and
  • OR - bitwise or
  • XOR - exclusive or
  • CALL - call a  subroutine
  • RET - return from a  subroutine
  • HALT - stop the software
  • SETE - set 1/0 if equal
  • SETNE - set 1/0 if not equal
  • SETLE - set 1/0 if lower or equal
  • SETL - set 1/0 if lower
  • SETG - set 1/0 if greater
  • SETGE - set 1/0 if greater or equal
  • SETNLE - set 1/0 if not lower or equal
  • SETNL - set 1/0 if not lower
  • SETNGE - set 1/0 if not greater or equal
  • SETNG - set 1/0 if not greater


Tuesday 2 July 2019

Menu builder


Menu builder is a tool in Livecode to create cool top menu:

Please not that on Mac it appears externally of the program:

Normal

On a Mac

The too in in the menu Tool -> Menu Builder:
On the left there are the main menu items, on the right the submenu of each item.
Dal menu builder potete aggiungere tutta una serie di effetti semplicemente usando il mouse, e le modifiche appariranno nel nome con un codice. This is the list of special chars and their meanings:
  • -   simple dash is a line divider
  • !c  this put a check before the menu item
  • !n this remove a check before the menu item
  • !r this put a list point before the item
  • !u this remove a list point before the item
  • & special char to call the item
  • / shortcat chara
  • ( rende il menu disabilitato
  • TAB to creat esubmenus
Fo examle this text
produce this:

You can use tags to change just what you see, but not the command; for example wiht multiple languages, you change only the tag. Example

Paste/V|Incolla





Monday 1 July 2019

Creating PDF with links

Livecode permits you to print any part of your programs as a PDF (or on a real printer).
If you want, you can create a PDF with links. The command to use is print link.
For example on a window create a text (http://www.paypal.com) and the use Text-> Link menu. Like this:




For example the button code is:

on mouseUp
   set the printPaperSize to (item 3 to 4 of the rect of this stack)
   put the rect of field "example" into temp
   ask file "Save PDF as:" with "Example.pdf"   
   if it is empty then
      exit mouseUp
   end if
   open printing to PDF it   
   print card 1 of this stack   
   print link to URL "http://www.paypal.com/" with rect temp
   close printing
end mouseUp

This is the result in a PDF reader:


Thursday 27 June 2019

Different types of rounding numbers

Rounding number is useful in so many applications, that I need to mention how i works in Livecode.
We have the following function:  round(), trunc(),  ceil(), floor().Let's see how they works with examplse.
Let's tart with round(), it can round to the nearest integer or to the number o decimal indicated by the second item:

put round(2.4) # it returns 2
put round(2.6) # it returns 3 
put round(2.712, 1) # it returns 2.7
put round(2.765, 1) # it returns 2.8

The function trubc() returns onl the integer part of the number:

put trunc(2.712) # it returns 2

If we need the the nearest integer more or equal the given number, you need ceil():

put ceil(2.2321) # it returns 3

If we need the the nearest integer less or equal the given number, you need floor():

put floor(2.712) # it returns 2