From Clomosy Docs

No edit summary
 
(45 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Aside from the uses clause (and reserved words like implementation, which demarcate parts of a unit), a program consists entirely of declarations and statements, that are organized into blocks.<br>
<span style="font-size:16px; font-weight:bold;">Overview</span>


This topic covers the following items:
TRObject is a programming language designed for developing mobile applications on the Clomosy platform. It can be run on various operating systems such as Android, Windows, iOS, macOS, and Linux via the Clomosy Learn application. This document is intended to help you understand the TRObject language and assist you in progressing with the related frameworks.
* Declarations
<br><br>
* Simple statements such as assignment
<span style="font-size:16px; font-weight:bold;">Audience</span>
* Structured statements such as conditional tests (for example, if-then, and case), iteration (for example, for, and while).<br>


== Declarations ==
This document is designed for beginners and software professionals who wish to learn the TRObject programming language through simple and easy-to-follow steps. The aim is to provide a foundational understanding of TRObject programming concepts. Upon completing this document, you are expected to reach an intermediate level of knowledge and advance towards higher expertise in mobile application development.
The names of variables, constants, types, fields, properties, procedures, functions, programs, units, libraries, and packages are called identifiers. Identifiers must be declared before you can use them; the only exceptions are a few predefined types, routines, and constants that the compiler understands automatically, the variable Result when it occurs inside a function block, and the variable Self when it occurs inside a method implementation.<br>
<br><br>
<span style="font-size:16px; font-weight:bold;">Prerequisites</span>


A declaration defines an identifier and, where appropriate, allocates memory for it.<br>
Before starting this course, you should have a basic understanding of the Clomosy mobile application development platform and fundamental software concepts. If you already have knowledge of another mobile application development platform or a computer programming language, it will provide you with an additional advantage.
''var''
<br><br>
A_Variable, B_Variable ... : Variable_Type;
<span style="font-size:16px; font-weight:bold;">Why Use TRObject?</span>
'''For example:'''<br>
<ul>
''Var''
  <li><strong>Modern Syntax:</strong> TRObject features a readable and modern syntax, making the software development process more efficient.</li>
MyForm:TclForm;
  <li><strong>Object-Oriented Programming:</strong> By supporting the object-oriented programming paradigm, it makes complex software projects more manageable.</li>
CloudQ:TClJSONQuery;    
   <li><strong>Ease of Learning:</strong> TRObject is designed to be easily learned by beginners, allowing them to quickly grasp coding concepts.</li>
ztEdt:TTMSFMXEdit;
  <li><strong>Extensive Library Support:</strong> Offers extensive library support for various tasks and functions, accelerating the mobile app development process.</li>
ztLbl:TLabel;
  <li><strong>High Performance:</strong> Optimized for developing high-performance mobile applications.</li>
ztPnl:TPanel;
  <li><strong>IoT and Integration Support:</strong> Seamlessly integrates with Raspberry Pi, MQTT protocol, SQL databases, and IoT projects, offering compatibility with next-generation software languages.</li>
sonucLbl:string;
</ul>


Clomosy variables are declared outside the code-body of the function which means they are not declared within the begin and end pairs, but they are declared after the definition of the procedure/function and before the begin keyword. For global variables, they are defined after the program header.
<br><br>
=== Block Creation ===
<div class="alert alert-LightSkyBlue-1 role="alert" data-bs-theme="light"style=background-color: ">
-------
<h2 class="alert-heading">
begin ... end or { ... } (curly braces) are keywords in the TRObject program that allow a group of code to form a block. This block represents a specific function or operation. For example, inside a procedure or function, within a loop, or within an if statement, they are used to delimit a particular operation.
Program Structure</h2>
<p>Every Clomosy program follows a specific execution order. This section explains how to structure your code and build the program structure using TRObject syntax on the Clomosy platform. Key rules and building blocks for organizing code in a modular and understandable way are discussed under this heading.</p>
<hr>
<br>
<div class ="green-learn-more" >
[[Program_Structure|Learn More]]
</div>
</div>
</div>


These keywords are used to group and delimit a set of operations. They are widely used to structure the flow of code in procedures, functions, loops, conditional statements, and more.
<div class="alert alert-LightSkyBlue-2 role="alert" data-bs-theme="light">
<h2 class="alert-heading">Syntax</h2>
<p> The rules that define how to correctly write code in your language. This includes variable declarations, function calls, operator usage, and other grammatical rules specific to the language.</p>
<hr>
<br>
<div class ="green-learn-more" >
[[Syntax|Learn More]]
</div>
</div>
</div>
<div class="alert alert-LightSkyBlue-3 role="alert" data-bs-theme="light">
<h2 class="alert-heading">Data Types</h2>
<p> A description of the data types supported by your programming language (e.g., integers, floating-point numbers, strings, etc.) and how they are declared and used within the program.</p>
<hr>
<br>
<div class ="green-learn-more" >
[[Data_Types|Learn More]]
</div>
</div>
</div>
<div class="alert alert-LightSkyBlue-4" role="alert" data-bs-theme="light">
<h2 class="alert-heading">Operators</h2>
<p>The operators used to perform mathematical, logical, and comparison operations in the language. This section explains how addition, subtraction, logical operators (AND, OR), and other operations work.</p>
<hr>
<br>
<div class ="green-learn-more">
[[Operators|Learn More]]
</div>
</div>
<div class="alert alert-LightSkyBlue-5"  role="alert" data-bs-theme="light">
<h2 class="alert-heading">Conditional statements</h2>
<p> Explains how to control the flow of the program using conditional statements like "if" and "else." This section covers how the program behaves based on different conditions.</p>
<hr>
<br>
<div class=" green-learn-more">
[[Conditional_Statements|Learn More]]
</div>
</div>
<div class="alert alert-LightSkyBlue-6"  role="alert" data-bs-theme="light">
<h2 class="alert-heading">Loops</h2>
<p>A guide to repetitive task structures like "for" and "while" loops. It explains how to iterate over a set of instructions and when to use each loop type.
</p>
<hr>
<br>
<div class="green-learn-more">
[[Loops|Learn More]]
</div>
</div>
<div class="alert alert-LightSkyBlue-7"  role="alert" data-bs-theme="light">
<h2 class="alert-heading">Functions</h2>
<p>This section covers how to define and use reusable blocks of code that perform specific tasks. It explains function definitions, how to pass parameters, and return values.</p>
<hr>
<br>
<div class ="green-learn-more" >
[[Functions|Learn More]]
</div>
</div>
</div>
<div class="alert alert-LightSkyBlue-8"  role="alert" data-bs-theme="light">
<h2 class="alert-heading">Procedures</h2>
<p>Similar to functions but without returning a value. This section explains how procedures are used for performing specific tasks and when to use them instead of functions.</p>
<hr>
<br>
<div class ="green-learn-more" >
[[Procedures|Learn More]]
</div>
</div>
</div><div class="alert alert-LightSkyBlue-9"  role="alert" data-bs-theme="light">
<h2 class="alert-heading">System Library</h2>
<p>SystemLibrary is a library that is included by default in all script components. It adds frequently used procedures and functions such as ShowMessage and IntToStr.</p>
<hr>
<br>
<div class ="green-learn-more" >
[[System_Library|Learn More]]
</div>
</div>
</div>


:'''Basic Syntax'''
<div class="alert alert-LightSkyBlue-10" role="alert" data-bs-theme="light">
begin
<h2 class="alert-heading">Clomosy Class</h2>
  ...
<p>The structure of the Clomosy class includes properties used to obtain information related to the user account, parameter usage, unit creation, and system functions within the project. These properties bring together data and behaviors, enabling the design of complex projects in a more understandable way.</p>
end;
<hr>
<div class="green-learn-more">
[[Clomosy_Class|Learn More]]
</div>
</div>


:'''TRObject Syntax'''
<div class="alert alert-LightSkyBlue-11"  role="alert" data-bs-theme="light">
{
<h2 class="alert-heading">Error Trapping</h2>
  ...
<p>Explains how errors are handled in the language. This section describes error-catching mechanisms (e.g., "try-catch" blocks) and how to manage errors to prevent program crashes.</p>
}
<hr>
=== Data Types ===
<br>
-------
<div class ="green-learn-more" >
==== Var Type ====
[[Error_Trapping|Learn More]]
------
</div>
The type declaration is used to declare the data type of an identifier. For example, the following day and age variables can be defined as integer, yes and true Boolean.<br>
</div>
When defining the type, "Exist" should be added to the beginning of the field to be defined. After it is written in this way, variable definitions can be made under it.<br>
</div>
''Var''
days, age : integer;
yes, true : boolean;
name, city : string;
numberValue : double;
fltNumber : float;
fees, expenses : real;
myFile : TextFile;


'''For Example:'''<br>
<div class="alert alert-LightSkyBlue-12"  role="alert" data-bs-theme="light">
'''Var'''
<h2 class="alert-heading">File Handling</h2>
  fltnumber : float;
<p>In Clomosy, text files are used for defining, storing text-based data, or performing read/write operations.</p>
  dateValue: integer;
<hr>
  control : boolean;
<br>
  nameValue : string;<br>
<div class ="green-learn-more" >
'''begin'''
[[File_Handling|Learn More]]
  fltnumber := 3.12;
</div>
  control := True;
</div>
  dateValue := 2022;
</div>
  nameValue := 'Clomosy';<br>
  if control then
  begin
    ShowMessage('Name: '+nameValue);
    ShowMessage('Date: '+IntToStr(dateValue));
    ShowMessage('fltnumber: '+ FloatToStr(fltnumber));
  end;<br>
'''end;'''


==== Const Type ====
<div class="alert alert-LightSkyBlue-13"  role="alert" data-bs-theme="light">
------
<h2 class="alert-heading">Arrays</h2>
The use of constant variables makes a program more readable and helps to keep custom quantities somewhere at the beginning of the program. When defining these variables, "const" should be added to the beginning.<br>
<p>An array is a data structure that can store multiple values of the same type. It can have a fixed size or be dynamically resized. Arrays allow access to elements via indexes and are typically used to organize and manage groups of data efficiently.<br>
''const''
In the Clomosy platform, there are two types of array usage:<br>
pi = 3.14;
<div class ="green-learn-more" >
* [[Arrays| Array]]: Standard array usage
* [[TclArray| TclArray]]: Customized array usage
</div></p>
</div>
</div>


'''For Example:'''<br>
<div class="alert alert-LightSkyBlue-14"  role="alert" data-bs-theme="light">
'''const'''
<h2 class="alert-heading">Units</h2>
  pi = 3.14;<br>
<p>In Clomosy projects, the Unit structure is used to organize code into functional and manageable parts. A Unit is a package of code that represents various components and modules within a project.</p>
Var
<hr>
  control : boolean;<br>
<br>
'''begin'''
<div class ="green-learn-more" >
  control := True;
[[Units|Learn More]]
  if control then
</div>
  begin
</div>
    ShowMessage(FloattoStr(pi));
</div>
  end;
'''end;'''


=== Variable Types ===
<div class="alert alert-LightSkyBlue-15 role="alert" data-bs-theme="light"style=background-color: ">
-------
<h2 class="alert-heading">
A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in TRObject has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.<br>
Responsive Designing</h2>
<p>In Clomosy, responsive design is achieved not through flexible structures like in the web world, but by dynamically adjusting the size and position of visual components.<br>
Especially in desktop applications, a responsive layout can be created using properties like Align, which adjusts the size of components based on the width and height values of their container.<br>
After reviewing the Forms and Components section, you can explore how to create a design.</p>
<hr>
<br>
<div class ="green-learn-more" >
[[Responsive_Designing|Learn More]]
</div>
</div>
</div>


{| class="wikitable"
<div class="alert alert-LightSkyBlue-15"  role="alert" data-bs-theme="light">
<h2 class="alert-heading">Forms</h2>
<p>Forms are fundamental building blocks for creating user interfaces in Clomosy applications. Forms contain visual objects (controls) and their associated events.</p>
<hr>
<br>
<div class ="green-learn-more" >
[[TclForm|Learn More]]
</div>
</div>
</div>


! Sr.No !! Type & Description
<div class="alert alert-LightSkyBlue-16"  role="alert" data-bs-theme="light">
|-
<h2 class="alert-heading">Components</h2>
| 1 || '''Character'''<br>Typically a single octet (one byte). This is an integer type.
<p>In software development, components are reusable objects used to perform specific functions. Components can serve a wide range of tasks, from user interface elements to more technical functions like data access or network communication.</p>
|-
<hr>
| 2 || '''Integer'''<br> The most natural size of integer for the machine.
<br>
|-
<div class ="green-learn-more" >
| 3 || '''Real'''<br> A single-precision floating point value.
[[Components|Learn More]]
|-
</div>
| 4 || '''Boolean'''<br> Specifies true or false logical values. This is also an integer type.
</div>
|-
</div>
| 5 || '''Enumerated'''<br> Specifies a user-defined list.
|-
| 6 || '''Subrange'''<br> Represents variables, whose values lie within a range.
|-
| 7 || '''String'''<br> Stores an array of characters.
|}
 
=== Operators ===
-------
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Clomosy allows the following types of operators: <br>
* Arithmetic operators
* Relational operators
* Boolean operators
Let us discuss the arithmetic, relational and Boolean operators one by one.<br>
 
==== Arithmetic Operators ====
Following table shows all the arithmetic operators supported by Clomosy. Assume variable A holds 10 and variable B holds 20, then:<br>
{| class="wikitable"
! Operator !! Description !! Example
|-
| + || Adds two operands || A + B will give 30
|-
| - || Subtracts second operand from the first || A - B will give -10
|-
| * || Multiplies both operands || A * B will give 200
|-
| / || Divides numerator by denominator || B / A will give 2
|}


'''Example:'''<br>
<div class="alert alert-LightSkyBlue-17" role="alert" data-bs-theme="light">
 
<h2 class="alert-heading">Sensor Structures</h2>
'''var'''
<p>Sensor structures allow devices to detect and analyze environmental data. Many sensors are present on smart devices. Sensors are of great importance in making tasks easier for end users. </p>
  number1,number2,resultValue : Integer;<br>
<hr>
'''begin'''<br>
  number1 := 20;
  number2 := 12;
  resultValue := number1 + number2;
  ShowMessage(IntToStr(number1)+' + '+IntToStr(number2)+' ='+IntToStr(resultValue));<br>
'''end;'''
 
===== Other arithmetic operations =====
*[[Mod]] : Modulus Operator and remainder of after an integer division
*[[SQRT]] : It is used to find the square root of a positive value
*[[Sqr]] : Used to find the square of a number
*[[Abs]] : It finds the absolute value of a number.
 
<blockquote style="background-color:#CBEDD5">Visit the [https://www.docs.clomosy.com/index.php/SystemLibrary#Math_Operations page] for other functions in the math library.</blockquote>
 
==== Relational Operators ====
Following table shows all the relational operators supported by Clomosy. Assume variable A holds 10 and variable B holds 20, then:<br>
 
:'''Basic Syntax'''
{| class="wikitable"
! Operator !! Description!! Example
|-
| = || Checks if the values of two operands are equal or not, if yes, then condition becomes true. || (A = B) is not true.
|-
| <> || Checks if the values of two operands are equal or not, if values are not equal, then condition becomes true. || (A <> B) is true.
|-
| > || Checks if the value of left operand is greater than the value of right operand, if yes, then condition becomes true. || (A > B) is not true.
|-
| < || Checks if the value of left operand is less than the value of right operand, if yes, then condition becomes true. || (A < B) is true.
|-
| >= || Checks if the value of left operand is greater than or equal to the value of right operand, if yes, then condition becomes true. || (A >= B) is not true.
|-
| <= || Checks if the value of left operand is less than or equal to the value of right operand, if yes, then condition becomes true. || (A <= B) is true.
|}
 
:'''TRObject Syntax'''
{| class="wikitable"
! Operator !! Description!! Example
|-
| == || Checks if the values of two operands are equal or not, if yes, then condition becomes true. || (A == B) is not true.
|-
| not || Checks if the values of two operands are equal or not, if values are not equal, then condition becomes true. || (not A == B) is true.
|-
| > || Checks if the value of left operand is greater than the value of right operand, if yes, then condition becomes true. || (A > B) is not true.
|-
| < || Checks if the value of left operand is less than the value of right operand, if yes, then condition becomes true. || (A < B) is true.
|-
| >= || Checks if the value of left operand is greater than or equal to the value of right operand, if yes, then condition becomes true. || (A >= B) is not true.
|-
| <= || Checks if the value of left operand is less than or equal to the value of right operand, if yes, then condition becomes true. || (A <= B) is true.
|}
 
==== Boolean Operators ====
Following table shows all the Boolean operators supported by Clomosy language. All these operators work on Boolean operands and produce Boolean results. Assume variable A holds true and variable B holds false, then:<br>
{| class="wikitable"
! Operator !! Description !! Example
|-
| and || Called Boolean AND operator. If both the operands are true, then condition becomes true. || (A and B) is false.
|-
| and then || It is similar to the AND operator, however, it guarantees the order in which the compiler evaluates the logical expression. Left to right and the right operands are evaluated only when necessary. || (A and then B) is false.
|-
| or || Called Boolean OR Operator. If any of the two operands is true, then condition becomes true. || (A or B) is true.
|-
| or else || It is similar to Boolean OR, however, it guarantees the order in which the compiler evaluates the logical expression. Left to right and the right operands are evaluated only when necessary. || (A or else B) is true.
|-
| not || Called Boolean NOT Operator. Used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. || not (A and B) is true.
|}
 
=== Comments ===
-------
For multi-line comments, curly brackets { ... } are enclosed. Allows 2 slash // ... comments for a single line.
{ This is a multi-line comments
  and it will span multiple lines. }<br>
// This is a single line comment in clomosy
 
 
== Simple Statements ==
A simple statement does not contain any other statements. Simple statements include assignments, calls to procedures and functions, and goto jumps.<br>
An assignment statement has the form:<br>
variable := expression
where variable is any variable reference, including a variable, variable typecast, dereferenced pointer, or component of a structured variable. The expression is any assignment-compatible expression.The := symbol is sometimes called the assignment operator. An assignment statement replaces the current value of the variable with the value of the expression.<br>
'''For example:'''<br>
age := 26;
 
== QuotedStr ==
Returns the quoted version of a string. For example, when you want to quote with ShowMessage, you can define it as follows.<br>
ShowMessage('This is a '+'''QuotedStr('Attention!')'''+' warning.');
 
As another example, let's convert the string S to a quoted string. Use QuotedStr for this. A single quotation mark (') is added to the beginning and end of the S, and each single quotation mark in the string is repeated.<br>
'''var'''
S : String;<br>
'''begin'''
S := 'This is a <nowiki>''Attention!''</nowiki> warning.';
ShowMessage(QuotedStr(S));
'''end;'''
'''Output:'''<br>
[[File:QuotedStrOutput.png|frameless|400px]]
 
It is also used in cases where string expressions need to be added while writing sql code blocks in Clomosy application. An example code snippet is shown below.<br>
'''Example:'''<br>
LocalQ := Clomosy.DBSQLServerQueryWith(' SELECT '+ '''QuotedStr('Product Name: ')''' +'+productName  AS MAINVIEW_TEXT ,'+ '''QuotedStr('Product Price: ')''' +'+ CAST(CAST(productPrice AS int)AS varchar(10)) AS MAINVİEW_CENTERTEXT FROM Products ');
 
== Array Identification ==
Array means many variables of the same data type. Array variables are like a list with a sequence number. Items belonging to this list are also accessed by their sequence number. You can access the structure in which we use Array on [[Arrays | page]].
 
== Structured Statements ==
Structured statements are built from other statements. Use a structured statement when you want to execute other statements sequentially, conditionally, or repeatedly.<br>
* A compound or with statement simply executes a sequence of constituent statements.
* A conditional statement that is an if or case statement executes at most one of its constituents, depending on specified criteria.
* Loop statements including repeat, while, and for loops execute a sequence of constituent statements repeatedly.
<br>
<br>
<div class ="green-learn-more" >
[[Sensor Structures |Learn More]]
</div>
</div>
</div>


=== Compound Statements ===
<div class="alert alert-LightSkyBlue-17"  role="alert" data-bs-theme="light">
------
<h2 class="alert-heading">Animation Usage</h2>
A compound statement is a sequence of other (simple or structured) statements to be executed in the order in which they are written. The compound statement is bracketed by the reserved words begin and end, and its constituent statements are separated by semicolons. For example:<br>
<p>To create animations, bitmap sequences to be played at a specific speed can be defined using TclBitmapListAnimation, and the start and end times of the animation can be controlled.</p>
 
<hr>
''begin''
    Z := X;
    X := Y;
    Y := Z;
''end;''
Compound statements are essential in contexts where Clomosy syntax requires a single statement. In addition to program, function, and procedure blocks, they occur within other structured statements, such as conditionals or loops.<br>
 
=== With Statements ===
------
A with statement is a shorthand for referencing the fields of a record or the fields, properties, and methods of an object. The syntax of a with statement is:<br>
''with'' obj ''do'' statement
or
''with'' obj1, ..., objn ''do'' statement
''begin''
  ....
''end;''
Since a with statement requires a variable or a field to operate upon, using it with properties can be tricky at times. A with statement expects variables it operates on to be available by reference.<br>
 
The most important things to note when you are using with:<br>
* You can use with on read-only properties only for reading. Trying to modify a field in the exposed record or object results in a compile-time error.
* Even though the property allows write access to the field, you still cannot use with to modify its fields.
<br>
<br>
'''Example:'''<br>
<div class ="green-learn-more" >
var
[[TclBitmapListAnimation |Learn More]]
MyForm:TclForm;
</div>
ztLbl:TclLabel;
</div>
I:Integer;
</div>
testAddBtn:TCLButton;<br>
begin
  Clomosy.ResumeLocalEvent := False;
  MyForm:=TclForm.Create(self);
  for I := 0 to 2 do
  begin
    testAddBtn := MyForm.AddNewButton(MyForm,'testAddBtn'+IntToStr(I),'send');
    '''With''' testAddBtn '''do begin'''
      Height := 70;
      Align := alRight;
      Margins.Right:=50;
    '''end;'''<br>
  end;
  MyForm.Run;
end;


=== If Statements ===
<div class="alert alert-LightSkyBlue-17"  role="alert" data-bs-theme="light">
------
<h2 class="alert-heading">Database Operations</h2>
 
<p>Database operations on the Clomosy platform enable users to manage data efficiently. Database connections can be established, queries can be executed between tables, and data can be read and updated. Clomosy supports SQL queries, providing developers with flexible data management capabilities.</p>
There are two forms of the if statement: if...then and the if...then...else. The syntax of an if...then statement is:<br>
<hr>
''if'' expression ''then'' statement
or
''if'' expression ''then'' statement1 ''else'' statement2
 
You can place a semicolon after an entire if statement to separate it from the next statement in its block, but the then and else clauses require nothing more than a space or carriage return between them. Placing a semicolon immediately before else (in an if statement) is a common programming error.<br>
 
A special difficulty arises in connection with nested if statements. This happens because some if statements have else clauses while others do not, but the syntax for the two kinds of statement is otherwise the same. In a series of nested conditionals where there are fewer else clauses than if statements, it may not seem clear which else clauses are bound to which ifs. Consider a statement of the form:<br>
''if'' expression1 ''then if'' expression2 ''then'' statement1 ''else'' statement2;
 
It appears that there are two ways to parse this:<br>
if expression1 then [ if expression2 then statement1 else statement2 ];
 
if expression1 then [ if expression2 then statement1 ] else statement2;
However, the compiler always parses in the first way.<br>
 
'''Example:'''<br>
var
  MyForm:TclForm;
  ztLbl:TclLabel;
  I:Integer;
begin<br>
  Clomosy.ResumeLocalEvent := False;
  MyForm:=TclForm.Create(self);
  I:=0;
  while (I>=0) do
  begin
    ztLbl:=MyForm.AddNewLabel(MyForm,'ztLbl'+IntToStr(I),IntToStr(I)+'. LoremIpsum');
    ztLbl.StyledSettings:=ssFamily;
    ztLbl.SetFontSize(70);
    ztLbl.Align:=alTop;
    ztLbl.Margins.Left:=70;
    ztLbl.Margins.Top:=20+IntToStr(I+10);
    ztLbl.Height:=100;
    ztLbl.Width:=70;
    '''if''' I=2 '''then'''
    '''begin'''
      break;
    '''end;'''
    I:=I+1;
  end;
end;
 
=== Case Statements ===
------
 
The case statement may provide a readable alternative to deeply nested if conditionals. A case statement has the form:<br>
 
''case'' selectorExpression ''of''
  caseList1: statement1;
    ...
  caseListn: statementn;
''end''
where selectorExpression is any expression of an ordinal type smaller than 32 bits (string types and ordinals larger than 32 bits are invalid) and each caseList is one of the following:<br>
 
* A numeral, declared constant, or other expression that the compiler can evaluate without executing your program. It must be of an ordinal type compatible with selectorExpression. Thus, 7, True, 4 + 5 * 3, 'A', and Integer('A') can all be used as caseLists, but variables and most function calls cannot. (A few built-in functions like Hi and Lo can occur in a caseList. See Declared Constants.)
* A subrange having the form First..Last, where First and Last both satisfy the criterion above and First is less than or equal to Last.
* A list having the form item1, ..., itemn, where each item satisfies one of the criteria above.
<br>
<br>
'''Example:'''<br>
<div class ="green-learn-more" >
 
[[Clomosy_Class#Database_Connectivity |Learn More]]
var
</div>
  MyForm:TclForm;
</div>
  ztLbl:TclLabel;
</div>
  I:Integer;
  testAddBtn:TclButton;
  procedure ztNewProcedure;
  begin
    ShowMessage('Deneme');
  end;<br>
begin
Clomosy.ResumeLocalEvent := False;
MyForm:=TclForm.Create(self);
  for I := 0 to 2 do
  begin
    testAddBtn := MyForm.AddNewButton(MyForm,'testAddBtn'+IntToStr(I),'send');
    With testAddBtn do begin
      Height := 70;
      Align := alTop;
      Margins.Top:=20;
    end;
    '''case''' I '''of'''
      '''0:'''
      begin
        testAddBtn.Caption := 'send0';
      MyForm.AddNewEvent(testAddBtn,tbeOnClick, 'ztNewProcedure' );
      end;
      '''1:'''testAddBtn.Caption := 'send1';
      '''2:'''testAddBtn.Caption := 'send2';
    end;
  end;<br>
  MyForm.Run;
end;
 
=== Control Loops ===
------
Loops allow you to execute a sequence of statements repeatedly, using a control condition or variable to determine when the execution stops. Clomosy has three kinds of control loops: repeat statements, while statements, and for statements.<br>
You can use the standard Break and Continue procedures to control the flow of a repeat, while, or for statement. Break terminates the statement in which it occurs, while Continue begins executing the next iteration of the sequence.
 
==== Repeat Statements ====
The syntax of a repeat statement is:<br>
''repeat'' statement1; ...; statementn; ''until'' expression
where expression returns a Boolean value. (The last semicolon before until is optional.) The repeat statement executes its sequence of constituent statements continually, testing expression after each iteration. When expression returns True, the repeat statement terminates. The sequence is always executed at least once, because expression is not evaluated until after the first iteration.
 
'''Example:'''<br>
var
  num, sqrNum  : Integer;
begin
  num:= 1;
  sqrNum  := num* num;
  '''Repeat'''
    ShowMessage(IntToStr(num)+' squared = '+IntToStr(sqrNum));
    Inc(num);
    sqrNum := num * num;
  '''until''' sqrNum > 100;
end;
 
==== While Statements ====
A while statement is similar to a repeat statement, except that the control condition is evaluated before the first execution of the statement sequence. Hence, if the condition is false, the statement sequence is never executed.<br>
 
The syntax of a while statement is:<br>
''while'' expression ''do'' statement
where expression returns a Boolean value and statement can be a compound statement. The while statement executes its constituent statement repeatedly, testing expression before each iteration. As long as expression returns True, execution continues.<br>
'''Example:'''<br>
 
var
  MyForm:TclForm;
  ztLbl:TclLabel;
  I:Integer;<br>
begin
  Clomosy.ResumeLocalEvent := False;
  MyForm:=TclForm.Create(self);
  I:=0;
  '''while''' (I>=0) '''do'''
  '''begin'''
    ztLbl:=MyForm.AddNewLabel(MyForm,'ztLbl'+IntToStr(I),IntToStr(I)+'. LoremIpsum');
    ztLbl.StyledSettings:=ssFamily;
    ztLbl.SetFontSize(70);
    ztLbl.Align:=alTop;
    ztLbl.Margins.Left:=70;
    ztLbl.Margins.Top:=20+IntToStr(I+10);
    ztLbl.Height:=100;
    ztLbl.Width:=70;
    if I=2 then
    begin
      break;
    end;
    I:=I+1;
  '''end;'''<br>
  MyForm.Run;
end;
 
==== For Statements ====
A for statement, unlike a repeat or while statement, requires you to specify explicitly the number of iterations you want the loop to go through. The syntax of a for statement is:<br>
''for'' counter := initialValue ''to'' finalValue ''do'' statement
or:<br>
''for'' counter := initialValue ''downto'' finalValue ''do'' statement
 
where:<br>
* counter is a local variable (declared in the block containing the for statement) of ordinal type, without any qualifiers.
* initialValue and finalValue are expressions that are assignment-compatible with counter.
* statement is a simple or structured statement that does not change the value of counter.
The for statement assigns the value of initialValue to counter, then executes statement repeatedly, incrementing or decrementing counter after each iteration. (The for...to syntax increments counter, while the for...downto syntax decrements it.) When counter returns the same value as finalValue, statement is executed once more and the for statement terminates. In other words, statement is executed once for every value in the range from initialValue to finalValue. If initialValue is equal to finalValue, statement is executed exactly once. If initialValue is greater than finalValue in a for...to statement, or less than finalValue in a for...downto statement, then statement is never executed. After the for statement terminates (provided this was not forced by a Break or an Exit procedure), the value of counter is undefined.<br>
'''Example:'''<br>
var
  MyForm:TclForm;
  ztLbl:TclLabel;
  I:Integer;
  ztAddImg:TclImage;
  procedure ztNewProcedure;
  begin
    ShowMessage('Test');
  end;<br>
begin
  Clomosy.ResumeLocalEvent := False;
  MyForm:=TclForm.Create(self);<br>
  '''for''' I := 0 '''to''' 2 '''do'''
  '''begin'''
    ztAddImg := MyForm.AddNewImage(MyForm,'ztAddImg'+IntToStr(I));
  With ztAddImg do begin
      Height := 70;
      Align := alRight;
      Margins.Right:=50;
    end;
    case I of
      0:
      begin
        MyForm.SetImage(ztAddImg,'https://media1.cucuvi.com/Dic17/B22D785A-5E77-414C-B7E5-50D7F38FD59E.jpg');
        MyForm.AddNewEvent(ztAddImg,tbeOnClick, 'ztNewProcedure' );
      end;
      1:MyForm.SetImage(ztAddImg,'https://media1.cucuvi.com/Dic17/4ACD4A34-35DC-4A0C-85CB-74F2CBABEC3C.jpg');
      2:MyForm.SetImage(ztAddImg,'https://media1.cucuvi.com/Dic17/129C1C15-F01E-4048-A6B5-E41CEE58DAB8.jpg');
    end;
  '''end;'''<br>
  MyForm.Run;<br>
end;
 
== Procedures and Functions ==
Procedures and functions, referred to collectively as routines, are self-contained statement blocks that can be called from different locations in a program. A function is a routine that returns a value when it executes. A procedure is a routine that does not return a value.<br>
 
Function calls, because they return a value, can be used as expressions in assignments and operations. For example:<br>
  I := SomeFunction(X);
When you declare a procedure or function, you specify its name, the number and type of parameters it takes, and, in the case of a function, the type of its return value; this part of the declaration is sometimes called the prototype, heading, or header. Then you write a block of code that executes whenever the procedure or function is called; this part is sometimes called the body of the routine or block.<br>
 
=== Procedure Declarations ===
------
A procedure declaration has the form:<br>
 
'''procedure''' procedureName(parameterList); directives;
  localDeclarations;
'''begin'''
  statements
'''end;'''
where procedureName is any valid identifier, statements is a sequence of statements that execute when the procedure is called, and (parameterList), directives;, and localDeclarations; are optional.<br>
Within a statement block of a procedure, you can use variables and other identifiers declared in the localDeclarations part of the procedure. You can also use the parameter names from the parameter list, the parameter list defines a set of local variables, so do not try to redeclare the parameter names in the localDeclarations section. Finally, you can use any identifiers within whose scope the procedure declaration falls.<br>
 
'''Example:'''<br>
 
var
  MyForm:TclForm;
  titleLbl:TclLabel;
  addImg :TclImage;
  procedure paramProcedure(title : String);
  begin
  titleLbl.Caption := title;
  end;
 
  procedure parameterlessProcedure;
  begin
   
  addImg.Visible := false;
  ShowMessage('I came from within the procedure.');
  paramProcedure('Hello');
  end;
begin
  Clomosy.ResumeLocalEvent := False;
  MyForm:=TclForm.Create(self);
  addImg := MyForm.AddNewImage(MyForm,'addImg'+IntToStr(0));
  addImg.Height := 200;
  addImg.Width := 200;
  addImg.Align := alCenter;
  MyForm.SetImage(addImg,'https://www.stylecraze.com/wp-content/uploads/2013/07/25-Most-Beautiful-Blue-Flowers.jpg');
  MyForm.AddNewEvent(addImg,tbeOnClick, 'parameterlessProcedure');
 
  titleLbl := MyForm.AddNewLabel(MyForm, 'titleLbl','Test');
  titleLbl.Align := alCenter;
  MyForm.Run;
end;
 
=== Function Declarations ===
------
A function declaration is like a procedure declaration except that it specifies a return type and a return value. Function declarations have the form:<br>
 
function functionName(parameterList): returnType; directives;
  localDeclarations;
begin
  statements
end;
 
where functionName is any valid identifier, returnType is a type identifier, statements is a sequence of statements that execute when the function is called, and (parameterList), directives;, and localDeclarations; are optional.<br>
 
The statement block of the function is governed by the same rules that apply to procedures. Within the statement block, you can use variables and other identifiers declared in the localDeclarations part of the function, parameter names from the parameter list, and any identifiers within whose scope the function declaration falls. In addition, the function name itself acts as a special variable that holds the return value of the function, as does the predefined variable Result.<br>
 
'''Sample:'''<br>
 
'''var''' 
MyForm : TclForm;
mainRow, mainCol1 :TCLPanel;
mainCol1TitleSection,notifTextSection : TCLLayout;
mainCol1TitleLbl,notifTextLbl : TCLLabel;<br>
total : Integer;<br>
  '''Function''' getSum(a,b: Integer):Integer;
  '''begin'''
      Result := a + b;
  '''end;'''<br>
'''begin'''
Clomosy.ResumeLocalEvent := False;
total :=getSum(5,10);
MyForm:=TclForm.Create(self);<br>
mainRow:=MyForm.AddNewPanel(MyForm,'mainRow',<nowiki>''</nowiki>);
mainRow.Align:=ALCenter;
mainRow.Height:=275;
mainRow.StyleLookup:='pushpanel';<br>
mainCol1:=MyForm.AddNewPanel(mainRow,'mainCol1',<nowiki>''</nowiki>);
mainCol1.Align:=ALCenter;
mainCol1.Width:=300;
mainCol1.Height:=175;<br>
mainCol1TitleSection:=MyForm.AddNewLayout(mainCol1,'mainCol1TitleSection');
With mainCol1TitleSection Do Begin
  Align:=ALMostTop;
  Width:=300;
  Height:=100;
end;<br>
mainCol1TitleLbl:=MyForm.AddNewLabel(mainCol1TitleSection,'mainCol1TitleLbl','FUNCTİON SAMPLE');
With mainCol1TitleLbl Do Begin
  StyledSettings := ssFamily;
  TextSettings.Font.Size:=30;
  Align:=ALCenter;
  AutoSize:=True;
  TextSettings.WordWrap:=True;
  Margins.Left:=20;
  Width:=300;
  end;<br>
notifTextSection:=MyForm.AddNewLayout(mainCol1,'notifTextSection');
With notifTextSection Do Begin
  Align:=ALMostTop;
  Width:=400;
  Height:=10;
end;<br>
notifTextLbl:=MyForm.AddNewLabel(notifTextSection,'notifTextLbl','Total = '+IntToStr(total));
With notifTextLbl Do Begin
  StyledSettings := ssFamily;
  TextSettings.Font.Size:=15;
  Align:=ALCenter;
  AutoSize:=True;
  TextSettings.WordWrap:=True;
  Margins.Left:=10;
end;<br>
MyForm.Run;<br>
'''end;'''
 
== Date and Time ==
We can pull the date and time data on the Clomosy application and use it in the area we want.<br>
=== Date ===
------
Date data is taken as "day.month.year".
ShowMessage(Date);
'''Output:'''<br>
[[File:DateOutput.png|frameless|200px]]<br>
 
=== DeCodeDate ===
-------
If you want to get the date information separately by day, month, year, you can use the "DeCodeDate" parameter.<br>
  '''DeCodeDate(Date,YY,MM,DD);'''
  ShowMessage(DD); //day
  ShowMessage(MM); //month
  ShowMessage(YY); //year
 
You can use the "DateTimeToStr" parameter when you want to get detailed date and time data at the same time.<br>
ShowMessage('Date and Time at the time of : '+ DateTimeToStr(Now));
'''Output:'''<br>
[[File:DateTimeToStrOutput.png|frameless|400px]]<br>
=== Time ===
-------
You can get the time information as "hour-minute-second".<br>
ShowMessage(Time);
'''Output:'''<br>
[[File:TimeOutput2.png|frameless|300px]]<br>


== Console Applications ==
<br><br>
Console applications are 32-bit programs that run in a console window without a graphical interface. These applications generally do not require much user input and perform a limited number of functions. Its use is shown below.<br>
//Fetch date and time data
'''console.text'''('Hello World');
'''Example:'''<br>
'''Var'''
  i := Integer;<br>
'''begin'''
  for i:=0 to 5 do
    console.text('Counter: '+IntToStr(i));<br> 
    console.text('Time:'+DateTimeToStr(Now));
'''end;'''


'''Output:'''<br>
<div class="alert alert-success" role="alert" data-bs-theme="light">
[[File:ConsoleExample.png|400px|frameless]]<br><br>
<h2 class="alert-heading">Related Links (Follow the Steps to Proceed)</h2>
<ul>
<li>[[Clomosy_Installation|Download]] to use the Clomosy platform. </li>
<li>To become a developer, go to [[Developer| Developer page]]. </li>
<li>Go to [[Project Creation|Project Creation]] to create a project</li>
<li>Go to [[Users|Users page]] for testing</li>
</ul>
</div>
{{#seo:|description=Learn about TRObject Language in Clomosy. A guide to understanding and using this language for effective app development and data handling.}}

Latest revision as of 14:48, 25 April 2025

Overview

TRObject is a programming language designed for developing mobile applications on the Clomosy platform. It can be run on various operating systems such as Android, Windows, iOS, macOS, and Linux via the Clomosy Learn application. This document is intended to help you understand the TRObject language and assist you in progressing with the related frameworks.

Audience

This document is designed for beginners and software professionals who wish to learn the TRObject programming language through simple and easy-to-follow steps. The aim is to provide a foundational understanding of TRObject programming concepts. Upon completing this document, you are expected to reach an intermediate level of knowledge and advance towards higher expertise in mobile application development.

Prerequisites

Before starting this course, you should have a basic understanding of the Clomosy mobile application development platform and fundamental software concepts. If you already have knowledge of another mobile application development platform or a computer programming language, it will provide you with an additional advantage.

Why Use TRObject?

  • Modern Syntax: TRObject features a readable and modern syntax, making the software development process more efficient.
  • Object-Oriented Programming: By supporting the object-oriented programming paradigm, it makes complex software projects more manageable.
  • Ease of Learning: TRObject is designed to be easily learned by beginners, allowing them to quickly grasp coding concepts.
  • Extensive Library Support: Offers extensive library support for various tasks and functions, accelerating the mobile app development process.
  • High Performance: Optimized for developing high-performance mobile applications.
  • IoT and Integration Support: Seamlessly integrates with Raspberry Pi, MQTT protocol, SQL databases, and IoT projects, offering compatibility with next-generation software languages.



Program Structure

Every Clomosy program follows a specific execution order. This section explains how to structure your code and build the program structure using TRObject syntax on the Clomosy platform. Key rules and building blocks for organizing code in a modular and understandable way are discussed under this heading.



Syntax

The rules that define how to correctly write code in your language. This includes variable declarations, function calls, operator usage, and other grammatical rules specific to the language.



Data Types

A description of the data types supported by your programming language (e.g., integers, floating-point numbers, strings, etc.) and how they are declared and used within the program.



Responsive Designing

In Clomosy, responsive design is achieved not through flexible structures like in the web world, but by dynamically adjusting the size and position of visual components.
Especially in desktop applications, a responsive layout can be created using properties like Align, which adjusts the size of components based on the width and height values of their container.
After reviewing the Forms and Components section, you can explore how to create a design.