In Delphi script, when values are assigned to variables, the colon-equal operator is used; :=

Similar documents
DelphiScript Keywords

Quick Reference Guide

Quick Reference Guide

SECTION II: LANGUAGE BASICS

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Operators. Java operators are classified into three categories:

Flow Control. CSC215 Lecture

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

CSC 1214: Object-Oriented Programming

DEPARTMENT OF MATHS, MJ COLLEGE

JAVA OPERATORS GENERAL

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Statements and Operators

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Prof. Navrati Saxena TA: Rochak Sachan

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

Logical Operators and switch

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Department of Computer Science

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Java Basic Programming Constructs

CSC Web Programming. Introduction to JavaScript

CGS 3066: Spring 2015 JavaScript Reference

Information Science 1

Operators in java Operator operands.

Chap 6 - Introduction to HDL (b)

Variables and literals

Chapter 3: Operators, Expressions and Type Conversion

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Informatics Ingeniería en Electrónica y Automática Industrial

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators & Expressions

COMP Primitive and Class Types. Yi Hong May 14, 2015

Operators in C. Staff Incharge: S.Sasirekha

CS313D: ADVANCED PROGRAMMING LANGUAGE

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section :

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Basics of Java Programming

UNIT- 3 Introduction to C++

Here n is a variable name. The value of that variable is 176.

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

CSCE 110 PROGRAMMING FUNDAMENTALS

Language Reference Manual simplicity

Program Fundamentals

Chapter 2 Working with Data Types and Operators

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java

Data Types and Variables in C language

Type Conversion. and. Statements

Lecture 3. More About C

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Flow Control: Branches and loops

Fundamental of Programming (C)

Expressions and Precedence. Last updated 12/10/18

Introduction to Programming Using Java (98-388)

Object-Oriented Programming

Unit 3. Operators. School of Science and Technology INTRODUCTION

The PCAT Programming Language Reference Manual

PYTHON- AN INNOVATION

JScript Reference. Contents

Petros: A Multi-purpose Text File Manipulation Language

BASIC ELEMENTS OF A COMPUTER PROGRAM

The Java language has a wide variety of modifiers, including the following:

Full file at C How to Program, 6/e Multiple Choice Test Bank

Chapter 12 Variables and Operators

Chapter 2: Using Data

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Fundamentals of Programming

YOLOP Language Reference Manual

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

TED Language Reference Manual

Lexical Considerations

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

Constants and Variables

JAVA Programming Fundamentals

Java+- Language Reference Manual

Chapter 2 REXX STATEMENTS. SYS-ED/ Computer Education Techniques, Inc.

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

ECEN 468 Advanced Logic Design

Declaration and Memory

PHPoC vs PHP > Overview. Overview

UNIT 3 OPERATORS. [Marks- 12]

Transcription:

Statements and Operators Old Content - visit altium.com/documentation Modified by on 13-Sep-2017 Parent page: DelphiScript DelphiScript Statements A statement in DelphiScript is considered as simple when it does not contain any other statements. Examples of simple statements are assignment statements and procedure calls. Simple statements: X := Y + 10; // assignment ShowMessage( Hello World! ); // procedure call A compound statement consists of multiple statements. Compound statements: If A > B Then ShowMessage( A is bigger ); Else ShowMessage( B is bigger ); A := 0; B := 0; In Delphi script, when values are assigned to variables, the colon-equal operator is used; := When testing for equality, the equality operator is used; = Conditional statements DelphiScript has control statements that affect the flow of execution within a script. The most common control statement is the If..Then conditional statement. If Then statement The If..Then statement is used for conditional control. The syntax is:

If Condition Then // code here End Else // code here Case Of statement To avoid a complex set of If statements, these can often be replaced with Case statements. A case statement in an expression is used to select a value, a list of possible values, or a range of values. Any types can be used in a Case statement because DelphiScript is an untyped language. Case statements can have an Else statement that is executed if none of the labels correspond to the value of the selector (within the Case Of condition). Example 1: Case Char of '+' : Text := 'Plus sign'; '-' : Text := 'Minus sign'; '*', '/': Text := 'Multiplication or division'; '0'..'9': Text := 'Number'; a'..'z': Text := 'Lowercase character'; 'A'..'Z': Text := 'Uppercase character'; else Text := 'Unknown character'; Example 2: Case UserName of 'Jack', 'Joe' : IsAdministrator := true; Fred' : IsAdministrator := false; else Raise('Unknown User'); With statement The With statement is a DelphiScript shorthand. When referring to a record type variable (or an object), a with statement can be used instead of repeating its name each time. Normal version: Form.Canvas.Pen.Width := 2; Form.Canvas.Pen.Color := clsilver;

Version using With: With Form.Canvas.Pen do Width := 2; Color := clsilver; For To Do loop The For..To..Do statement provides a method for repeatedly looping through a block of code (one or more lines of code). The basic syntax is: For counter := start To end Do // code here For loops are often used to initialize an array. The counter direction in a For..To..Do loop can be controlled by alternatively using the DownTo keyword to decrement the loop. DelphiScript provides the Break/Exit statement to exit a For..To..Do loop prematurely. Repeat Until loop The Repeat statement is executed repeatedly until the Boolean expression is true. The Repeat statement is always executed at least once. Repeat Write('Enter a value (0..9): '); ShowMessage(IntToStr(I)); Until (I >= 0) and (I <= 9); While Do loop 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. Randomize; I := 0; While I < 1000 do I := I + Random (100); Add ('Random Number: ' + IntToStr (I));

Continue statement The Continue statement jumps over the body of a loop, similar to the Goto statement. The continue statement causes the executing script to pass to the next iteration in the current For, While or Repeat loop. var F: File; i: Integer; For i := 0 to (FileListBox1.Items.Count - 1) do Try If FileListBox1.Selected[i] Then If not FileExists(FileListBox1.Items.Strings[i]) then MessageDlg('File: ' + FileListBox1.Items.Strings[i] + 'not found', mterror, [mbok], 0); Continue; AssignFile(F, FileListBox1.Items.Strings[i]); Reset(F, 1); ListBox1.Items.Add(IntToStr(FileSize(F))); CloseFile(F); Finally { do something here } Goto Label statement The Goto statement has the form Goto label which transfers the script execution to the statement marked by the specified label. To mark a statement, the label must be declared first and then the target statement preceded with the label and a colon: label: statement A Label can be any valid identifier. The Label declaration and Goto statement must belong to the same code block within a script. Therefore it's not possible to jump into, or out of, a procedure or function. Label StartHere; // code StartHere: Beep; Goto StartHere;

Exit statement The Exit statement immediately returns from a function or procedure. If you call Exit from within a Try..Finally block, the Finally part gets executed before the subroutine returns. If the Exit procedure is called from within the main body of the script, then execution of the script will terminate. Server := SchServer; If Server = Nil Then ShowError('No SchServer started'); Exit; Break Statement The Break statement causes the executing script to exit out of the current For, While or Repeat loop. Script execution continues from the subsequent executable line after the current loop. Var S: string; While True do ReadLn(S); Try if S = '' then Break; WriteLn(S); Finally { do something for all cases } DelphiScript Expression Operators In general, an expression is a valid combination of constants, variables, literal values, operators and function results. Expressions are used to determine the value to assign to a variable, to compute the parameter of a function or to test for a condition. Expressions can include function calls. DelphiScript has a number of logical, arithmetic, Boolean and relational operators. These operators are grouped by the order of precedence (see below), which is different to the precedence orders used by Basic, C etc. For example, the AND and OR operators have precedence compared to the relational one. If you write a<b and c<d, DelphiScript will do the AND operation first, resulting in an error. To

prevent this problem and define the priority, each < expression needs to be enclosed in parentheses: (a<b) and (c<d); The supported DelphiScript operators listed below are shown by their order of precedence. Operators grouped by Precedence Note that Unary operators have the highest precedence. Not Boolean or bitwise NOT. Multiplicative and Bitwise Operators * Arithmetic multiplication. / Floating point division. div mod and shl shr Integer division. modulus (reminder of integer division). Boolean or bitwise AND. Bitwise left shift. Bitwise right shift. Additive Operators + Arithmetic addition, string concatenation. - Arithmetic subtraction. or xor Boolean or bitwise OR Boolean or bitwise EXCLUSIVE OR. Relational and Comparison Operators (lowest precedence) = Test whether equal or not. <> Test whether not equal or not. < Test whether less than or not. > Test whether greater than or not. <= Test whether less than or equal to or not. >= Test whether greater than or equal to or not. Also note that the ^ and @ operators are not supported by DelphiScript. Source URL: https://techdocs.altium.com/display/scrt/delphiscript((statements+and+operators))