From Clomosy Docs

No edit summary
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 7: Line 7:
</div>
</div>


<h2> <b>Begin</b> </h2>
The Begin keyword is used in the Clomosy platform within the BASE Syntax to start expression blocks. This type of block is used at the beginning of the main block in your code and within conditions, loops, procedures, and function structures.<br>
<b>Example:</b><br>
<pre>
var
valueStr : String;
Begin
  for i := 1 to 10 do
  Begin
    ShowMessage('Number: '+IntToStr(i));
  end;
end;
</pre>
<h2> <b>End</b> </h2>
The End keyword is used in the Clomosy platform within the BASE Syntax to terminate expression blocks. This type of block is used at the end of the main block in your code and within conditions, loops, procedures, and function structures.<br>
<b>Example:</b><br>
<pre>
var
  i : Integer;
begin
  i := 2;
  case i of
    0 : Showmessage('i = 0');
    1 : Showmessage('i = 1');
    2 : Showmessage('i = 2');
  End;
End;
</pre>


<h2> <b>var</b> </h2>
<h2> <b>var</b> </h2>
Line 45: Line 12:


<b>Example:</b><br>
<b>Example:</b><br>
<b>TRObject Syntax</b><br>
 
<pre>
<pre>
Var
Var
Line 57: Line 24:
   ShowMessage('Year = '+IntToStr(year));
   ShowMessage('Year = '+IntToStr(year));
}
}
</pre>
<b>Base Syntax</b><br>
<pre>
Var
  appName  : String;
  year : Integer;
begin
  appName    := 'Clomosy';
  year := 2023;
  ShowMessage('appName = '+appName  );
  ShowMessage('Year = '+IntToStr(year));
end;
</pre>
<h2> <b>And</b> </h2>
The and keyword is used as a logical operator in the BASE syntax structure of the Clomosy platform. It is used to combine two or more conditions and returns a true value only when all conditions are true. In other words, if all expressions combined with and are true, the result is true; otherwise, it is false.<br>
The And keyword is used in two different ways:<br>
1. To perform a logical or boolean 'and' of two logical values. If both are true, then the result is true, otherwise, the result is false.<br>
2. To perform a mathematical 'and' of two integers. The result is a bitwise 'and' of the two numbers. For example:<br>
10110001 '''And''' 01100110 = 00100000
<b>Example</b><br>
<pre>
var
  num1, num2, num3 : Integer;
  letter          : Char;
begin
  num1  := $25;   
  num2  := $10;   
  letter := 'G';
  if (num1 > 0) And (letter = 'G')
  then ShowMessage('Both values are true')
  else ShowMessage('None or only one true value');
  num3 := num1 And num2;
  ShowMessage('25 And 32 = '+ IntToStr(num3));
end;
</pre>
<h2> <b>Or</b> </h2>
It is used as a logical operator. It combines two or more conditions to check if at least one of them is true. If at least one of the conditions combined with or is true, the result is true; otherwise, the result is false.<br>
<b>Example</b><br>
<b>TRObject Syntax</b><br>
<pre>
var
  num1, num2, num3 : Integer;
  letter          : Char;
begin
  num1  := $25;   
  num2  := $10;   
  letter := 'G';
  if (num1 > 0) Or (letter = 'G')
  then ShowMessage('Both values are true')
  else ShowMessage('None or only one true value');
  num3 := num1 Or num2;
  ShowMessage('25 And 32 = '+ IntToStr(num3));
end;
</pre>
</pre>


Line 138: Line 35:
   letter          : Char;
   letter          : Char;


begin
{
   num1  := $25;     
   num1  = $25;     
   num2  := $10;     
   num2  = $10;     
   letter := 'G';
   letter = 'G';


   if (num1 > 0) Xor (letter = 'G')
   if ((num1 > 0) Xor (letter == 'G'))
  then ShowMessage('Both values are true')
    ShowMessage('Both values are true')
   else ShowMessage('None or only one true value');
   else ShowMessage('None or only one true value');


   num3 := num1 Xor num2;
   num3 = num1 Xor num2;


   ShowMessage('25 And 32 = '+ IntToStr(num3));
   ShowMessage('25 And 32 = '+ IntToStr(num3));
end;
}
</pre>
</pre>


Line 157: Line 54:


<b>Example</b><br>
<b>Example</b><br>
<b>TRObject Syntax</b><br>
 
<pre>
<pre>
var
var
Line 179: Line 76:
</pre>
</pre>


<b>Base Syntax</b><br>
<pre>
var
  num1, num2 : Word;
begin
  num1  := $2C;    // Binary value : 0000 0000 0010 1100
                  // Not'ed value : 1111 1111 1101 0011 = $FFD3
  // And used to return a Boolean value
  if Not (num1 > 0)
  then ShowMessage('num1 <= 0')
  else ShowMessage('num1 > 0');
  // And used to perform a mathematical NOT operation
  num2 := Not num1;
  // Display the result
  ShowMessage('Not $2C = $'+IntToHex(num2,2));
end;
</pre>


<h2> <b>Array</b> </h2>
<h2> <b>Array</b> </h2>
Line 212: Line 87:


<b>Example</b><br>
<b>Example</b><br>
<b>TRObject Syntax</b><br>
 
<pre>
<pre>
var
var
Line 235: Line 110:
   ShowMessage('Day: ' + dayName);
   ShowMessage('Day: ' + dayName);
}
}
</pre>
<b>Base Syntax</b><br>
<pre>
var
  day: Integer;
  dayName: String;
begin
  day := 3; // Example day number
  case day of
    1: dayName := 'Monday';
    2: dayName := 'Tuesday';
    3: dayName := 'Wednesday';
    4: dayName := 'Thursday';
    5: dayName := 'Friday';
    6: dayName := 'Saturday';
    7: dayName := 'Sunday';
  else
    dayName := 'Invalid day'; // If the given day number is not between 1-7
  end;
 
  ShowMessage('Day: ' + dayName);
end;
</pre>
</pre>


Line 274: Line 125:


For detailed information, see the [[Div |page]].
For detailed information, see the [[Div |page]].
<h2> <b>Do</b> </h2>
The do keyword is always part of one of the three commonly shown control types (with, for, while). It is used in the BASE syntax structure on the Clomosy platform.<br>
<b>Example</b><br>
with for;
<pre>
With AddImg do begin
      Height := 70;
      Align := alRight;
      Margins.Right:=50;
end;
</pre>
for for loop;
<pre>
for j := beginning to finish do
begin
      //lines of code
end;
</pre>
while for;
<pre>
while first<=end do //if the situation is true
begin
    //lines of code
end;
</pre>


<h2> <b>downto</b> </h2>
<h2> <b>downto</b> </h2>
Line 313: Line 131:


<b>Example</b><br>
<b>Example</b><br>
<b>TRObject Syntax</b><br>
 
<pre>
<pre>
var
var
Line 325: Line 143:
}
}
</pre>
</pre>
<b>Base Syntax</b><br>
 
<pre>
var
  i: Integer;
begin
  // Counting down from 5 to 1
  for i := 5 downto 1 do
  begin
    ShowMessage('i = ' + IntToStr(i));
  end;
end;
</pre>


<h2> <b>Else</b> </h2>
<h2> <b>Else</b> </h2>
Line 376: Line 183:


<b>Example</b><br>
<b>Example</b><br>
<b>TRObject Syntax</b><br>
 
<pre>
<pre>
var
var
Line 390: Line 197:
   }
   }
}
}
</pre>
<b>Base Syntax</b><br>
<pre>
var
  number, zero : Integer;
begin
  number := -1;
  Try
    zero  := 0;
    number := 1 div zero;
    ShowMessage('number / zero = '+IntToStr(number));
  finally
      ShowMessage('Number was not assigned a value - using default');
  end;
end;
</pre>
</pre>


<h2> <b>Except</b> </h2>
<h2> <b>Except</b> </h2>
Line 424: Line 215:


<b>Example</b><br>
<b>Example</b><br>
<b>TRObject Syntax</b><br>
 
<pre>
<pre>
var
var
Line 435: Line 226:
   until counter > 5;
   until counter > 5;
}
}
</pre>
<b>Base Syntax</b><br>
<pre>
var
  counter: Integer;
begin
  counter := 1;
  repeat
    ShowMessage('Counter: ' + IntToStr(counter));
    counter := counter + 1;
  until counter > 5;
end;
</pre>
</pre>


Line 453: Line 232:


<b>Example</b><br>
<b>Example</b><br>
<b>TRObject Syntax</b><br>
 
<pre>
<pre>
var
var
Line 463: Line 242:
</pre>
</pre>


<b>Base Syntax</b><br>
<pre>
var
  i : Integer;
begin
  For i := 1 to 6 do
    ShowMessage('i = '+IntToStr(i));
end;
</pre>


<h2> <b>While</b> </h2>
<h2> <b>While</b> </h2>
Line 477: Line 247:


<b>Example</b><br>
<b>Example</b><br>
<b>TRObject Syntax</b><br>
 
<pre>
<pre>
var
var
Line 491: Line 261:
</pre>
</pre>


<b>Base Syntax</b><br>
<pre>
var
  count: Integer;
begin
  count := 0;
  while count < 5 do
  begin
    ShowMessage('Count: ' + IntToStr(count));
    count := count + 1;
  end;
end;
</pre>


<h2> <b>With</b> </h2>
<h2> <b>With</b> </h2>
Line 510: Line 267:
It simplifies the code by removing the need to prefix each referenced element with the complex variable name.
It simplifies the code by removing the need to prefix each referenced element with the complex variable name.
See the [[TRObject_Language#With_Statements | With]] keyword for full details.
See the [[TRObject_Language#With_Statements | With]] keyword for full details.
<h2> <b>To</b> </h2>
The to keyword is used within a for loop to indicate that a number should progress within a specific range. This keyword specifies how the loop variable will advance between the starting value and the ending value.


<h2> <b>Function</b> </h2>
<h2> <b>Function</b> </h2>
Line 518: Line 272:
The Function keyword is used to define a function that performs a specific operation and returns a value in a programming language. Functions allow code to be modular, providing the ability to reuse the same operation in different places. See [[TRObject_Language#Function_Declarations | page]] for detailed information.
The Function keyword is used to define a function that performs a specific operation and returns a value in a programming language. Functions allow code to be modular, providing the ability to reuse the same operation in different places. See [[TRObject_Language#Function_Declarations | page]] for detailed information.


<h2> <b>Procedure</b> </h2>
<h2> <b>Void</b> </h2>
It is used to define a procedure in a programming language that performs a specific task and does not return a value. See the [[TRObject_Language#Procedure_Declarations | Procedure]] tutorial for details on using procedures.
It is used to define a procedure in a programming language that performs a specific task and does not return a value. See the [[TRObject_Language#Procedures]] tutorial for details on using void.


<h2> <b>If</b> </h2>
<h2> <b>If</b> </h2>
The If keyword is used to control the flow of code depending on the logical result of the given condition. See [[TRObject_Language#If_Statements | page]] for detailed information.
The If keyword is used to control the flow of code depending on the logical result of the given condition. See [[TRObject_Language#If_Statements | page]] for detailed information.


<h2> <b>Then</b> </h2>
The then keyword is part of the if statement. It is used to initiate the block of code that executes when the if condition is true. It is used in the BASE syntax of the Clomosy platform. See the [[TRObject_Language#If_Statements | if]] keyword for full details.


<h2> <b>Mod</b> </h2>
<h2> <b>Mod</b> </h2>
Line 534: Line 286:
For more detailed information, please refer to the [[TRObject Language | TRObject Language]] page.
For more detailed information, please refer to the [[TRObject Language | TRObject Language]] page.
</div>
</div>
{{#seo:|title=Keywords Found in Clomosy - Clomosy Docs}}
{{#seo:|description=Explore essential keywords in Clomosy to manage control flow, data structures, and operations, ensuring efficient and error-free application development.}}

Latest revision as of 15:04, 24 December 2024

This page contains commonly used keywords and directives in the programming language. Keywords form the fundamental building blocks of a programming language and are used to perform specific tasks. Acting as commands, these words manage the control flow, data structures, and other essential operations within a program. The correct use of keywords during programming is crucial for building error-free and efficient code.

Below is a list of the main keywords used in the programming language. Understanding these keywords will help you grasp the structure of the language and use the correct syntax when developing software.


var

The var keyword is used for defining variables. To create a variable, var is used to specify the name and type of the variable. This keyword allocates memory in the program to store a specific data type.

Example:

Var
  appName   : String;
  year : Integer;
{
  appName = 'Clomosy';
  year = 2023; 

  ShowMessage('appName = '+appName  );
  ShowMessage('Year = '+IntToStr(year));
}

Xor

As a logical operator, xor combines two or more conditions and checks whether only one of them is true. If only one of the conditions combined with xor is true, the result will be true; however, if both conditions are true or both are false, the result will be false. This operator is useful for expressing the logic of "either one or the other" between conditions.

Example

var
  num1, num2, num3 : Integer;
  letter           : Char;

{
  num1   = $25;    
  num2   = $10;    
  letter = 'G';

  if ((num1 > 0) Xor (letter == 'G'))
    ShowMessage('Both values are true')
  else ShowMessage('None or only one true value');

  num3 = num1 Xor num2;

  ShowMessage('25 And 32 = '+ IntToStr(num3));
}

Not

It is used as a logical operator to negate a condition; that is, the not operator evaluates a condition as false if it is true, and as true if it is false. This way, it is useful for altering the logical states of conditions.

Example

var
  num1, num2 : Word;

{
  num1   = $2C;    // Binary value : 0000 0000 0010 1100
                   // Not'ed value : 1111 1111 1101 0011 = $FFD3

  // And used to return a Boolean value
  if Not (num1 > 0)
    ShowMessage('num1 <= 0')
  else ShowMessage('num1 > 0');

  // And used to perform a mathematical NOT operation
  num2 = Not num1;

  // Display the result
  ShowMessage('Not $2C = $'+IntToHex(num2,2));
}


Array

The Array provides single and multi dimensional arrays (indexable sequences) of data. Dynamic arrays have no preallocated storage. When defined, only a pointer is created. For detailed information, visit the page.

As

The as keyword is used for type casting. It is particularly useful in object-oriented programming when a object needs to be converted from one type to another. This operation should only be performed between compatible types; otherwise, an error will occur.

Case

The Case keyword provides a structured equivalent to a sequence of if statements on the same variable. The case statement is more elegant, more efficient, and easier to maintain than multiple if nestings.The brief definition is as follows.

Example

var
  day: Integer;
  dayName: String;
{
  day = 3; // Example day number

  case day of
  {
    1: dayName = 'Monday';
    2: dayName = 'Tuesday';
    3: dayName = 'Wednesday';
    4: dayName = 'Thursday';
    5: dayName = 'Friday';
    6: dayName = 'Saturday';
    7: dayName = 'Sunday';
  else
    dayName = 'Invalid day'; // If the given day number is not between 1-7
  }
  
  ShowMessage('Day: ' + dayName);
}

Const

The const keyword is used to define constant values. Constants are values that remain unchanged during the execution of the program. A constant defined with const takes a value of a specific type, and this value cannot be altered after its declaration. This feature enhances the reliability and readability of the code.

const
    pi = 3.14;

Div

The Div keyword gives the whole number result of dividing the Dividend by the Divisor. Any remainder is discarded.

Dividend div divisor

For detailed information, see the page.

downto

It is used to indicate that the count in a loop should be done in decreasing order. The loop variable progresses from a specified starting value to an end value by decreasing.

Example

var
  i: Integer;
{
  // Counting down from 5 to 1
  for (i = 5 downto 1)
  {
    ShowMessage('i = ' + IntToStr(i));
  }
}


Else

The Else keyword is part of the If and Case statements. It is used to start the section of code executed when earlier conditions are not satisfied.

If for;

var
  score: Integer;
{
  score = 75;
  
  if (score >= 50)
    ShowMessage('Passed')
  else
    ShowMessage('Failed');  
}

Case for;

var
  choice: Integer;
{
  choice = 1;

  case choice of
  {
    0: ShowMessage('Choice 0');
  else
    ShowMessage('Invalid choice');
  }
}

Try

It is used for error handling and management. The try block ensures the safe execution of a specific piece of code. If an error occurs within the try block, the error can be caught and handled by the except or finally blocks.

Example

var
  number, zero : Integer;
{
  number = -1;
  Try
    zero   = 0;
    number = 1 div zero;
    ShowMessage('number / zero = '+IntToStr(number));
  finally
      ShowMessage('Number was not assigned a value - using default');
  }
}

Except

The Except keyword is used to mark the start of a block of statements that handle an exception in a Try clause. If the Except block can handle the exception, then the program is not terminated.
For more detailed information, see the page.

Finally

Regardless of whether an error occurs in the try block, the code in the finally block always executes. This is useful to ensure that important tasks, such as resource deallocation or cleanup operations, are always carried out.
For more detailed information, see the page.

Repeat

The repeat keyword allows a block of code to be repeated until a specific condition is met. It is used in conjunction with the until keyword to check the loop condition. This structure ensures that the code within the loop is executed at least once.

Until

The until keyword is used in conjunction with the repeat statement to define the condition that terminates the loop. The loop continues to execute until the specified condition evaluates to true. This means that the block of code will keep running until the condition becomes true, making it useful for scenarios where you want the code to execute at least once before checking the condition.

Example

var
  counter: Integer;
{
  counter = 1;
  repeat
    ShowMessage('Counter: ' + IntToStr(counter));
    counter = counter + 1;
  until counter > 5;
}

For

The for structure is a control structure used to create a loop under a specific condition. It is ideal for performing a certain number of repetitions or iterating over an array. A for loop typically starts with a variable at a beginning value and progresses to an end value, with a specific increment or decrement on each iteration.

Example

var
  i : Integer;
{
  For (i = 1 to 6)
    ShowMessage('i = '+IntToStr(i));
}


While

The while keyword is a control structure used to repeatedly execute a block of code as long as a specific condition is met. This loop continues to run as long as the condition evaluates to true. Due to the fact that the condition is evaluated before entering the loop, it guarantees that the code within the loop may not execute at all if the condition is not satisfied. This is useful for avoiding infinite loops and ensuring a specific state is achieved.

Example

var
  count: Integer;
{
  count = 0;
  while (count < 5)
  {
    ShowMessage('Count: ' + IntToStr(count));
    count = count + 1;
  }
}


With

The With keyword is a convenience provided by Clomosy for referencing elements of a complex variable, such as a record or object.

It simplifies the code by removing the need to prefix each referenced element with the complex variable name. See the With keyword for full details.

Function

The Function keyword is used to define a function that performs a specific operation and returns a value in a programming language. Functions allow code to be modular, providing the ability to reuse the same operation in different places. See page for detailed information.

Void

It is used to define a procedure in a programming language that performs a specific task and does not return a value. See the TRObject_Language#Procedures tutorial for details on using void.

If

The If keyword is used to control the flow of code depending on the logical result of the given condition. See page for detailed information.


Mod

The Mod keyword gives the remainder from dividing the Dividend by the Divisor. The whole number result of the division is ignored. See page for detailed information.