0% found this document useful (0 votes)
39 views38 pages

IT Grade 10 - 12 Delphi Elements

The document outlines various Delphi methods and control structures for IT students in grades 10 to 12. It includes descriptions, functionalities, and examples for methods like ShowMessage, InputBox, and various control structures such as If-Then-Else and For-Do. Additionally, it covers string manipulation functions and file handling procedures, providing a comprehensive guide for programming in Delphi.

Uploaded by

jalia2800
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views38 pages

IT Grade 10 - 12 Delphi Elements

The document outlines various Delphi methods and control structures for IT students in grades 10 to 12. It includes descriptions, functionalities, and examples for methods like ShowMessage, InputBox, and various control structures such as If-Then-Else and For-Do. Additionally, it covers string manipulation functions and file handling procedures, providing a comprehensive guide for programming in Delphi.

Uploaded by

jalia2800
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

IT Grade 10 – 12 Delphi Elements

IT Grade 10 – 12 Delphi Elements

1. ShowMessage('Message') (Method)
o Description: Displays a simple dialog box with a specified message.
o How it Works: The ShowMessage method creates a modal dialog box that shows the
provided message and an OK button. The dialog must be dismissed before the program
continues.
o Example:

ShowMessage('Hello, World!');

o Result: A message box appears with the text "Hello, World!".

2. InputBox('Title', 'Prompt', 'Default') (Method)


o Description: Displays an input dialog box that prompts the user for input and returns the
input as a string.
o How it Works: The InputBox method shows a dialog with a title, a prompt, and a
default response. The user can type a response, which is returned as a string.
o Example:

var input: String;


input := InputBox('Enter Name', 'Please enter your name:', 'John Doe');

o Result: An input box appears with the title "Enter Name", a prompt "Please enter your
name:", and "John Doe" as the default text.

3. MessageDlg('Message', mtInformation, [mbOK], 0) (Method)


o Description: Displays a dialog box with a specified message, icon, and buttons.
o How it Works: The MessageDlg method shows a customizable dialog box with various
icons (e.g., information, warning) and buttons (e.g., OK, Cancel). The return value
indicates which button was clicked.
o Example:

MessageDlg('This is an information dialog.', mtInformation, [mbOK], 0);

o Result: An information dialog box appears with the message "This is an information
dialog." and an OK button.

Page 1 of 38
IT Grade 10 – 12 Delphi Elements

4. If-Then-Else (Control Structure)


o Description: Conditional structure used to execute a block of code if a specified
condition is true.
o How it Works: The If-Then-Else statement checks a condition. If the condition is true,
the code block following Then is executed. Otherwise, the code block following Else is
executed.
o Example:

var x: Integer;
x := 15;
if x > 10 then
ShowMessage('x is greater than 10')
else
ShowMessage('x is not greater than 10');

o Result: A message box appears with the text "x is greater than 10".

5. Case-Of (Control Structure)


o Description: Multi-way branching statement that executes different blocks of code
depending on the value of a variable.
o How it Works: The Case-Of structure evaluates an expression and matches its value to
one of several cases. The corresponding code block is executed.
o Example:

var DayOfWeek: Integer;


DayOfWeek := 3;
case DayOfWeek of
1: ShowMessage('Sunday');
2: ShowMessage('Monday');
3: ShowMessage('Tuesday');
else
ShowMessage('Another day');
end;

o Result: A message box appears with the text "Tuesday".

Page 2 of 38
IT Grade 10 – 12 Delphi Elements

6. For-Do (Control Structure)


o Description: Loop that iterates a specific number of times, executing a block of code on
each iteration.
o How it Works: The For-Do loop uses a counter variable that starts at an initial value and
increments or decrements until a specified limit is reached.
o Example:

var i: Integer;
for i := 1 to 5 do
ShowMessage('Count: ' + IntToStr(i));

o Result: Five message boxes appear in sequence, displaying "Count: 1", "Count: 2", and
so on up to "Count: 5".

7. While-Do (Control Structure)


o Description: Loop that executes a block of code as long as a specified condition is true.
o How it Works: The While-Do loop checks the condition before each iteration. If the
condition is true, the loop body is executed.
o Example:

var x: Integer;
x := 1;
while x <= 3 do
begin
ShowMessage('Value: ' + IntToStr(x));
Inc(x);
end;

o Result: Three message boxes appear in sequence, displaying "Value: 1", "Value: 2", and
"Value: 3".

Page 3 of 38
IT Grade 10 – 12 Delphi Elements

8. Repeat-Until (Control Structure)


o Description: Loop that executes a block of code repeatedly until a specified condition
becomes true.
o How it Works: The Repeat-Until loop executes the loop body at least once and
continues until the condition is true, checking the condition after each iteration.
o Example:

var x: Integer;
x := 1;
repeat
ShowMessage('Value: ' + IntToStr(x));
Inc(x);
until x > 3;

o Result: Three message boxes appear in sequence, displaying "Value: 1", "Value: 2", and
"Value: 3".

9. Length(Str) (Method)
o Description: Returns the length of a string.
o How it Works: The Length function counts the number of characters in a string and
returns this value as an integer.
o Example:

var len: Integer;


len := Length('Hello');
ShowMessage('Length of string: ' + IntToStr(len));

o Result: A message box appears with the text "Length of string: 5".

10. Copy(Str, Start, Length) (Method)


o Description: Copies a substring from a string, starting at a specified position and with a
specified length.
o How it Works: The Copy function extracts a portion of a string, starting from the Start
position and spanning the specified number of characters (Length).
o Example:

var subStr: String;

Page 4 of 38
IT Grade 10 – 12 Delphi Elements
subStr := Copy('Hello', 2, 3);
ShowMessage(subStr);

o Result: A message box appears with the text "ell".

11. Delete(Str, Start, Length) (Method)


o Description: Deletes a specified number of characters from a string, starting at a
specified position.
o How it Works: The Delete procedure removes a portion of a string, starting at the
Start position and extending for Length characters.
o Example:

var str: String;


str := 'Hello';
Delete(str, 2, 3);
ShowMessage(str);

o Result: A message box appears with the text "Ho".

12. Insert(Source, Target, Index) (Method)


o Description: Inserts a substring into another string at a specified position.
o How it Works: The Insert procedure adds the Source string into the Target string at
the Index position.
o Example:

var str: String;


str := 'Ho';
Insert('ell', str, 2);
ShowMessage(str);

o Result: A message box appears with the text "Hello".

13. Pos(SubStr, Str) (Method)


o Description: Returns the position of the first occurrence of a substring within a string.
o How it Works: The Pos function searches for the SubStr within the Str string and
returns the position of its first occurrence. If the substring is not found, it returns 0.
o Example:

var pos: Integer;


pos := Pos('l', 'Hello');
ShowMessage('Position of "l": ' + IntToStr(pos));

Page 5 of 38
IT Grade 10 – 12 Delphi Elements
o Result: A message box appears with the text "Position of 'l': 3".

14. UpperCase(Str) (Method)


o Description: Converts a string to uppercase.
o How it Works: The UpperCase function returns a new string with all lowercase letters in
the original string converted to uppercase.
o Example:

var upper: String;


upper := UpperCase('Hello');
ShowMessage(upper);

o Result: A message box appears with the text "HELLO".

15. LowerCase(Str) (Method)


o Description: Converts a string to lowercase.
o How it Works: The LowerCase function returns a new string with all uppercase letters in
the original string converted to lowercase.
o Example:

var lower: String;


lower := LowerCase('Hello');
ShowMessage(lower);

o Result: A message box appears with the text "hello".

16. StrToInt(Str) (Method)


o Description: Converts a string to an integer.
o How it Works: The StrToInt function attempts to convert the Str string to an integer. If
the string does not represent a valid integer, it raises an exception.
o Example:

var num: Integer;


num := StrToInt('123');
ShowMessage('Number: ' + IntToStr(num));

o Result: A message box appears with the text "Number: 123".

Page 6 of 38
IT Grade 10 – 12 Delphi Elements

17. IntToStr(Int) (Method)


o Description: Converts an integer to a string.
o How it Works: The IntToStr function converts the integer value Int into its string
representation.
o Example:

var str: String;


str := IntToStr(123);
ShowMessage('String: ' + str);

o Result: A message box appears with the text "String: 123".

18. StrToFloat(Str) (Method)


o Description: Converts a string to a floating-point number.
o How it Works: The StrToFloat function converts a string representing a floating-point
number into a Double. If the string is not a valid floating-point number, an exception is
raised.
o Example:

var floatNum: Double;


floatNum := StrToFloat('123.45');
ShowMessage('Float: ' + FloatToStr(floatNum));

o Result: A message box appears with the text "Float: 123.45".

19. FloatToStr(Float) (Method)


o Description: Converts a floating-point number to a string.
o How it Works: The FloatToStr function converts a floating-point number into its string
representation.
o Example:

var str: String;


str := FloatToStr(123.45);
ShowMessage('String: ' + str);

Page 7 of 38
IT Grade 10 – 12 Delphi Elements
o Result: A message box appears with the text "String: 123.45".

20. Sqr(Number) (Method)


o Description: Returns the square of a number.
o How it Works: The Sqr function multiplies the given number by itself and returns the
result.
o Example:

var squared: Integer;


squared := Sqr(5);
ShowMessage('Square: ' + IntToStr(squared));

o Result: A message box appears with the text "Square: 25".

21. Sqrt(Number) (Method)


o Description: Returns the square root of a number.
o How it Works: The Sqrt function calculates the square root of the given number and
returns the result as a floating-point number.
o Example:

var root: Double;


root := Sqrt(25);
ShowMessage('Square root: ' + FloatToStr(root));

o Result: A message box appears with the text "Square root: 5".

22. Abs(Number) (Method)


o Description: Returns the absolute value of a number.
o How it Works: The Abs function returns the positive value of the given number,
regardless of its original sign.
o Example:

var absVal: Integer;


absVal := Abs(-10);

Page 8 of 38
IT Grade 10 – 12 Delphi Elements
ShowMessage('Absolute value: ' + IntToStr(absVal));

o Result: A message box appears with the text "Absolute value: 10".

23. Randomize (Method)


o Description: Initializes the random number generator to produce a different sequence of
random numbers each time the program runs.
o How it Works: The Randomize procedure seeds the random number generator with the
current system time, ensuring that Random produces different sequences on each run.
o Example:

Randomize;

o Result: The random number generator is seeded.

24. Random(Range) (Method)


o Description: Generates a random number within the specified range.
o How it Works: The Random function returns a pseudo-random integer between 0 and
Range - 1.
o Example:

var rand: Integer;


rand := Random(100);
ShowMessage('Random number: ' + IntToStr(rand));

o Result: A message box appears with a random number between 0 and 99.

25. Round(X) (Method)


o Description: Rounds a real number to the nearest integer.
o How it Works: The Round function rounds the given real number to the nearest whole
number. If the fractional part is 0.5 or higher, the number is rounded up.
o Example:

var rounded: Integer;

Page 9 of 38
IT Grade 10 – 12 Delphi Elements
rounded := Round(5.5);
ShowMessage('Rounded: ' + IntToStr(rounded));

o Result: A message box appears with the text "Rounded: 6".

26. Trunc(X) (Method)


o Description: Truncates the decimal part of a real number, returning the integer part only.
o How it Works: The Trunc function discards the fractional part of the given number,
effectively rounding it towards zero.
o Example:

var truncated: Integer;


truncated := Trunc(5.9);
ShowMessage('Truncated: ' + IntToStr(truncated));

o Result: A message box appears with the text "Truncated: 5".

27. Inc(Variable) (Method)


o Description: Increments an integer variable by 1.
o How it Works: The Inc procedure increases the value of the given integer variable by 1.
o Example:

var x: Integer;
x := 10;
Inc(x);
ShowMessage('Incremented value: ' + IntToStr(x));

o Result: A message box appears with the text "Incremented value: 11".

28. Dec(Variable) (Method)


o Description: Decrements an integer variable by 1.
o How it Works: The Dec procedure decreases the value of the given integer variable by 1.
o Example:

var x: Integer;

Page 10 of 38
IT Grade 10 – 12 Delphi Elements
x := 10;
Dec(x);
ShowMessage('Decremented value: ' + IntToStr(x));

o Result: A message box appears with the text "Decremented value: 9".

29. InputQuery('Title', 'Prompt', varValue) (Method)


o Description: Displays a dialog box where the user can input text, and stores the result in
a variable.
o How it Works: The InputQuery method creates a dialog box with a title, a prompt, and
an input field. The user's input is stored in the variable varValue.
o Example:

var userInput: String;


if InputQuery('Enter Name', 'Please enter your name:', userInput) then
ShowMessage('Hello, ' + userInput);

o Result: An input dialog appears. If the user enters a name, a message box appears with
"Hello, [name]".

File Handling

30. AssignFile(File, Filename) (Method)


o Description: Associates a file variable with a file on disk.
o How it Works: The AssignFile procedure binds the File variable to the file specified
by Filename, preparing it for further file operations.
o Example:

var f: TextFile;
AssignFile(f, 'data.txt');

o Result: The file variable f is associated with the file 'data.txt'.

Page 11 of 38
IT Grade 10 – 12 Delphi Elements
31. Reset(File) (Method)
o Description: Opens a text file for reading.
o How it Works: The Reset procedure opens the file associated with File for reading. If
the file does not exist, an error occurs.
o Example:

var f: TextFile;
AssignFile(f, 'data.txt');
Reset(f);

o Result: The file 'data.txt' is opened for reading.

32. Rewrite(File) (Method)


o Description: Opens a text file for writing, clearing its contents.
o How it Works: The Rewrite procedure opens the file associated with File for writing.
If the file already exists, its contents are cleared.
o Example:

var f: TextFile;
AssignFile(f, 'data.txt');
Rewrite(f);

o Result: The file 'data.txt' is opened for writing, and its contents are cleared.

33. Append(File) (Method)


o Description: Opens a text file for writing, appending to the end.
o How it Works: The Append procedure opens the file associated with File for writing,
adding new content to the end without altering the existing content.
o Example:

var f: TextFile;
AssignFile(f, 'data.txt');
Append(f);

o Result: The file 'data.txt' is opened for writing, and new content will be added to the end
of the file.

34. CloseFile(File) (Method)


o Description: Closes an open file.

Page 12 of 38
IT Grade 10 – 12 Delphi Elements
o How it Works: The CloseFile procedure closes the file associated with File, finalizing
any operations and freeing system resources.
o Example:

var f: TextFile;
AssignFile(f, 'data.txt');
CloseFile(f);

o Result: The file 'data.txt' is closed.

35. ReadLn(File, Variable) (Method)


o Description: Reads a line from a text file into a variable.
o How it Works: The ReadLn procedure reads a single line from the text file into the
specified variable. If the end of the file is reached, an error occurs.
o Example:

var f: TextFile;
var line: String;
AssignFile(f, 'data.txt');
Reset(f);
ReadLn(f, line);
ShowMessage(line);
CloseFile(f);

o Result: The first line from 'data.txt' is displayed in a message box.

36. WriteLn(File, Text) (Method)


o Description: Writes a line of text to a file.
o How it Works: The WriteLn procedure writes the provided text to the file associated
with File, followed by a newline character.
o Example:

var f: TextFile;
AssignFile(f, 'data.txt');
Rewrite(f);

Page 13 of 38
IT Grade 10 – 12 Delphi Elements
WriteLn(f, 'Hello, World!');
CloseFile(f);

o Result: The text "Hello, World!" is written to 'data.txt'.

37. Eof(File) (Method)


o Description: Returns True if the end of a file has been reached.
o How it Works: The Eof function checks whether the file pointer has reached the end of
the file associated with File. It returns True if there are no more lines to read.
o Example:

var f: TextFile;
var line: String;
AssignFile(f, 'data.txt');
Reset(f);
while not Eof(f) do
begin
ReadLn(f, line);
ShowMessage(line);
end;
CloseFile(f);

o Result: Each line in 'data.txt' is displayed in a message box until the end of the file is
reached.

Operators

38. Div (Operator)


o Description: Integer division, discarding the remainder.

Page 14 of 38
IT Grade 10 – 12 Delphi Elements
o How it Works: The Div operator performs division between two integers and returns the
integer quotient, ignoring the remainder.
o Example:

var result: Integer;


result := 10 div 3;
ShowMessage('10 div 3 = ' + IntToStr(result));

o Result: A message box appears with the text "10 div 3 = 3".

39. Mod (Operator)


o Description: Returns the remainder of integer division.
o How it Works: The Mod operator divides one integer by another and returns the
remainder.
o Example:

var result: Integer;


result := 10 mod 3;
ShowMessage('10 mod 3 = ' + IntToStr(result));

o Result: A message box appears with the text "10 mod 3 = 1".

40. + (Operator)
o Description: Adds two numbers.
o How it Works: The + operator adds two numerical values and returns the sum.
o Example:

var result: Integer;


result := 5 + 3;
ShowMessage('5 + 3 = ' + IntToStr(result));

o Result: A message box appears with the text "5 + 3 = 8".

Page 15 of 38
IT Grade 10 – 12 Delphi Elements

41. - (Operator)
o Description: Subtracts one number from another.
o How it Works: The - operator subtracts the second number from the first and returns the
result.
o Example:

var result: Integer;


result := 5 - 3;
ShowMessage('5 - 3 = ' + IntToStr(result));

o Result: A message box appears with the text "5 - 3 = 2".

42. * (Operator)
o Description: Multiplies two numbers.
o How it Works: The * operator multiplies two numerical values and returns the product.
o Example:

var result: Integer;


result := 5 * 3;
ShowMessage('5 * 3 = ' + IntToStr(result));

o Result: A message box appears with the text "5 * 3 = 15".

43. / (Operator)
o Description: Divides one number by another.
o How it Works: The / operator divides the first number by the second and returns the
result as a floating-point number.
o Example:

var result: Double;


result := 5 / 3;
ShowMessage('5 / 3 = ' + FloatToStr(result));

Page 16 of 38
IT Grade 10 – 12 Delphi Elements
o Result: A message box appears with the text "5 / 3 = 1.66666666666667".

44. := (Operator)
o Description: Assigns a value to a variable.
o How it Works: The := operator assigns the value on the right side to the variable on the
left side.
o Example:

var x: Integer;
x := 10;
ShowMessage('x = ' + IntToStr(x));

o Result: A message box appears with the text "x = 10".

45. = (Operator)
o Description: Checks if two values are equal.
o How it Works: The = operator compares two values and returns True if they are equal,
False otherwise.
o Example:

var isEqual: Boolean;


isEqual := (5 = 5);
if isEqual then
ShowMessage('5 equals 5');

o Result: A message box appears with the text "5 equals 5".

46. <> (Operator)


o Description: Checks if two values are not equal.
o How it Works: The <> operator compares two values and returns True if they are not
equal, False otherwise.
o Example:

var isNotEqual: Boolean;

Page 17 of 38
IT Grade 10 – 12 Delphi Elements
isNotEqual := (5 <> 3);
if isNotEqual then
ShowMessage('5 does not equal 3');

o Result: A message box appears with the text "5 does not equal 3".

47. < (Operator)


o Description: Checks if one value is less than another.
o How it Works: The < operator compares two values and returns True if the first is less
than the second.
o Example:

var isLess: Boolean;


isLess := (3 < 5);
if isLess then
ShowMessage('3 is less than 5');

o Result: A message box appears with the text "3 is less than 5".

48. > (Operator)


o Description: Checks if one value is greater than another.
o How it Works: The > operator compares two values and returns True if the first is
greater than the second.
o Example:

var isGreater: Boolean;


isGreater := (5 > 3);
if isGreater then
ShowMessage('5 is greater than 3');

o Result: A message box appears with the text "5 is greater than 3".

49. <= (Operator)


o Description: Checks if one value is less than or equal to another.
o How it Works: The <= operator compares two values and returns True if the first is less
than or equal to the second.
o Example:

Page 18 of 38
IT Grade 10 – 12 Delphi Elements
var isLessOrEqual: Boolean;
isLessOrEqual := (3 <= 5);
if isLessOrEqual then
ShowMessage('3 is less than or equal to 5');

o Result: A message box appears with the text "3 is less than or equal to 5".

50. >= (Operator)


o Description: Checks if one value is greater than or equal to another.
o How it Works: The >= operator compares two values and returns True if the first is
greater than or equal to the second.
o Example:

var isGreaterOrEqual: Boolean;


isGreaterOrEqual := (5 >= 3);
if isGreaterOrEqual then
ShowMessage('5 is greater than or equal to 3');

o Result: A message box appears with the text "5 is greater than or equal to 3".

Events

51. OnClick (Event)


o Description: Triggered when a user clicks a component like a button.
o How it Works: The OnClick event is executed when a user clicks on a component, such
as a button. It is commonly used to execute specific actions in response to user
interaction.
o Example:

procedure TForm1.Button1Click(Sender: TObject);


begin
ShowMessage('Button clicked!');
end;

o Result: When the button is clicked, a message box appears with the text "Button
clicked!".

Page 19 of 38
IT Grade 10 – 12 Delphi Elements
52. OnCreate (Event)
o Description: Triggered when a form is created, often used to initialize variables or
components.
o How it Works: The OnCreate event is triggered as soon as the form is created, allowing
you to set initial values or perform startup tasks.
o Example:

procedure TForm1.FormCreate(Sender: TObject);


begin
ShowMessage('Form created!');
end;

o Result: When the form is created, a message box appears with the text "Form created!".

53. OnShow (Event)


o Description: Triggered when a form becomes visible.
o How it Works: The OnShow event is fired when the form is shown to the user. It is useful
for actions that need to occur as soon as the form is displayed.
o Example:

procedure TForm1.FormShow(Sender: TObject);


begin
ShowMessage('Form shown!');
end;

o Result: When the form is shown, a message box appears with the text "Form shown!".

54. OnClose (Event)


o Description: Triggered when a form is about to close.
o How it Works: The OnClose event occurs just before the form closes, allowing you to
perform cleanup tasks or prompt the user to save changes.
o Example:

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);


begin
ShowMessage('Form closing!');
end;

o Result: When the form is about to close, a message box appears with the text "Form
closing!".

Page 20 of 38
IT Grade 10 – 12 Delphi Elements
55. OnResize (Event)
o Description: Triggered when a form or component is resized.
o How it Works: The OnResize event occurs whenever the form or a component within it
is resized. This can be used to adjust the layout dynamically.
o Example:

procedure TForm1.FormResize(Sender: TObject);


begin
ShowMessage('Form resized!');
end;

o Result: When the form is resized, a message box appears with the text "Form resized!".

56. StrToDate('DateStr') (Method)


o Description: Converts a string representing a date into a TDateTime value.
o How it Works: The StrToDate function interprets the given string as a date and converts
it into a TDateTime format. If the string is not a valid date, an exception is raised.
o Example:

var dateValue: TDateTime;


dateValue := StrToDate('12/31/2023');
ShowMessage('Date: ' + DateToStr(dateValue));

o Result: A message box appears with the text "Date: 12/31/2023".

57. FormatDateTime('Format', Date) (Method)


o Description: Returns a formatted string representing a date/time value.
o How it Works: The FormatDateTime function formats the given TDateTime value into a
string according to the specified format string.
o Example:

var formattedDate: String;


formattedDate := FormatDateTime('dd/mm/yyyy', Now);
ShowMessage('Formatted Date: ' + formattedDate);

o Result: A message box appears with the date formatted as "dd/mm/yyyy".

58. IsLeapYear(Year) (Method)


o Description: Determines whether a specified year is a leap year.

Page 21 of 38
IT Grade 10 – 12 Delphi Elements
o How it Works: The IsLeapYear function checks if the given year meets the criteria for a
leap year (divisible by 4, but not by 100 unless also divisible by 400).
o Example:

var isLeap: Boolean;


isLeap := IsLeapYear(2024);
if isLeap then
ShowMessage('2024 is a leap year')
else
ShowMessage('2024 is not a leap year');

o Result: A message box appears with the text "2024 is a leap year".

59. DaysInMonth(Date) (Method)


o Description: Returns the number of days in the month of a specified date.
o How it Works: The DaysInMonth function calculates the number of days in the month of
the provided TDateTime value.
o Example:

var days: Integer;


days := DaysInMonth(StrToDate('02/01/2024'));
ShowMessage('Days in February 2024: ' + IntToStr(days));

o Result: A message box appears with the text "Days in February 2024: 29".

60. EncodeDate(Year, Month, Day) (Method)


o Description: Encodes a date from individual year, month, and day components into a
TDateTime value.
o How it Works: The EncodeDate function combines the year, month, and day into a
TDateTime value.
o Example:

var dateValue: TDateTime;


dateValue := EncodeDate(2024, 2, 29);
ShowMessage('Encoded Date: ' + DateToStr(dateValue));

o Result: A message box appears with the text "Encoded Date: 29/02/2024".

Page 22 of 38
IT Grade 10 – 12 Delphi Elements
61. DecodeDate(Date, Year, Month, Day) (Method)
o Description: Decodes a TDateTime value into individual year, month, and day
components.
o How it Works: The DecodeDate procedure extracts the year, month, and day from a
TDateTime value and stores them in the respective variables.
o Example:

var year, month, day: Word;


DecodeDate(StrToDate('12/31/2023'), year, month, day);
ShowMessage('Year: ' + IntToStr(year) + ', Month: ' + IntToStr(month) +
', Day: ' + IntToStr(day));

o Result: A message box appears with the text "Year: 2023, Month: 12, Day: 31".

62. TryStrToInt(Str, Variable) (Method)


o Description: Attempts to convert a string to an integer. Returns True if successful, False
otherwise.
o How it Works: The TryStrToInt function attempts to convert the string Str into an
integer. If successful, it stores the value in Variable and returns True; otherwise, it
returns False.
o Example:

var num: Integer;


if TryStrToInt('123', num) then
ShowMessage('Number: ' + IntToStr(num))
else
ShowMessage('Conversion failed');

o Result: A message box appears with the text "Number: 123" if the conversion is
successful.

63. RoundTo(Value, Digits) (Method)


o Description: Rounds a floating-point value to a specified number of decimal places.
o How it Works: The RoundTo function rounds the floating-point Value to the number of
decimal places specified by Digits.
o Example:

var rounded: Double;


rounded := RoundTo(123.456789, -2);
ShowMessage('Rounded to 2 decimal places: ' + FloatToStr(rounded));

o Result: A message box appears with the text "Rounded to 2 decimal places: 123.46".

Page 23 of 38
IT Grade 10 – 12 Delphi Elements

64. In (Operator)
o Description: Checks if a value is within a specific set.
o How it Works: The In operator is used to determine if a value is included within a
specified set. It returns True if the value is found in the set, otherwise False.
o Example:

var grade: Char;


grade := 'B';
if grade in ['A', 'B', 'C'] then
ShowMessage('Pass')
else
ShowMessage('Fail');

o Result: A message box appears with the text "Pass".

65. Break (Control Structure)


o Description: Exits a loop prematurely.
o How it Works: The Break statement immediately exits the loop in which it is used,
bypassing the remainder of the loop code.
o Example:

var i: Integer;
for i := 1 to 10 do
begin
if i = 5 then
Break;
ShowMessage('Count: ' + IntToStr(i));
end;

Result: Message boxes appear with "Count: 1", "Count: 2", "Count: 3", "Count: 4", then
o
the loop exits.
66. Continue (Control Structure)
o Description: Skips the current iteration of a loop and continues with the next iteration.
o How it Works: The Continue statement skips the remaining code in the current iteration
of the loop and jumps to the next iteration.
o Example:

var i: Integer;
for i := 1 to 5 do
begin
if i = 3 then
Continue;
ShowMessage('Count: ' + IntToStr(i));
end;

Page 24 of 38
IT Grade 10 – 12 Delphi Elements
o Result: Message boxes appear with "Count: 1", "Count: 2", "Count: 4", "Count: 5". The
message for "Count: 3" is skipped.

67. Try-Finally (Control Structure)


o Description: Ensures that the finally block is executed after the try block, regardless
of whether an exception is raised.
o How it Works: The Try-Finally structure is used to guarantee that the code within the
finally block runs, even if an exception occurs within the try block.
o Example:

try
ShowMessage('Trying...');
finally
ShowMessage('Finally executed');
end;

o Result: Two message boxes appear in sequence: "Trying..." followed by "Finally


executed".

68. Try-Except (Control Structure)


o Description: Handles exceptions by executing alternative code if an error occurs within
the try block.
o How it Works: The Try-Except block is used for error handling. If an error occurs in
the try block, control is passed to the except block where corrective or alternative
actions can be taken.
o Example:

try
var result := 10 div 0;
ShowMessage('Result: ' + IntToStr(result));
except

Page 25 of 38
IT Grade 10 – 12 Delphi Elements
on E: EDivByZero do
ShowMessage('Error: Division by zero!');
end;

o Result: A division by zero error triggers the except block, displaying a message box
with the text "Error: Division by zero!".

69. StrToCurr (Method)


o Description: Converts a string to a currency value.
o How it Works: The StrToCurr function converts a string representation of a currency
amount into a currency data type, which is specifically designed to handle monetary
values with high precision.
o Example:

var currencyValue: Currency;


currencyValue := StrToCurr('1234.56');
ShowMessage('Currency: ' + CurrToStr(currencyValue));

o Result: A message box appears with the text "Currency: 1234.56".

70. CurrToStr (Method)


o Description: Converts a currency value to a string.
o How it Works: The CurrToStr function converts a currency data type into its string
representation, suitable for displaying or further string manipulation.
o Example:

var currencyStr: String;


currencyStr := CurrToStr(1234.56);
ShowMessage('Currency as string: ' + currencyStr);

o Result: A message box appears with the text "Currency as string: 1234.56".

Components

71. TLabel (Component)


o Description: A component used to display text on a form.
o How it Works: TLabel is a non-editable text display component used to provide
descriptions or information on forms.
o Example:

Label1.Caption := 'Enter your name:';

Page 26 of 38
IT Grade 10 – 12 Delphi Elements
o Result: The label on the form displays the text "Enter your name:".

72. TButton (Component)


o Description: A button component that can be clicked by the user to trigger actions.
o How it Works: TButton is a clickable button component that generates an OnClick
event when pressed by the user.
o Example:

Button1.Caption := 'Submit';
Button1.OnClick := Button1Click;

o Result: The button displays the text "Submit" and triggers the Button1Click event when
clicked.

73. TEdit (Component)


o Description: A single-line text input component.
o How it Works: TEdit allows users to enter and edit text on a single line. The entered text
is accessible through the Text property.
o Example:

Edit1.Text := 'Enter your text here';

o Result: The edit box displays the default text "Enter your text here", which the user can
modify.

74. TMemo (Component)


o Description: A multi-line text input component.
o How it Works: TMemo allows users to input and edit multiple lines of text. It is useful for
larger text inputs, like comments or notes.
o Example:

Memo1.Lines.Add('This is a memo component.');

o Result: The memo box displays the line "This is a memo component."

Page 27 of 38
IT Grade 10 – 12 Delphi Elements

75. TComboBox (Component)


o Description: A dropdown list allowing users to select from a list of options.
o How it Works: TComboBox presents a list of items from which the user can select one.
The selected item is accessible through the Text property.
o Example:

ComboBox1.Items.Add('Option 1');
ComboBox1.Items.Add('Option 2');
ComboBox1.ItemIndex := 0;

o Result: Adds two options to the combo box and selects the first option by default.

76. TListBox (Component)


o Description: A list box component for displaying a list of items, where one or more
items can be selected.
o How it Works: TListBox displays a list of items from which the user can select one or
more. Selected items are accessed through the Items property.
o Example:

ListBox1.Items.Add('Item 1');
ListBox1.Items.Add('Item 2');

o Result: The list box displays "Item 1" and "Item 2".

77. TCheckBox (Component)


o Description: A component that allows users to make a binary choice, typically
represented as checked or unchecked.
o How it Works: TCheckBox can be checked or unchecked by the user. Its state is accessed
through the Checked property.
o Example:

CheckBox1.Caption := 'I agree to the terms';


CheckBox1.Checked := True;

Page 28 of 38
IT Grade 10 – 12 Delphi Elements
o Result: The checkbox displays with the text "I agree to the terms" and is checked by
default.

78. TRadioButton (Component)


o Description: A radio button component used for mutually exclusive options within a
group.
o How it Works: TRadioButton allows users to select one option from a set of mutually
exclusive choices. It is typically used in groups where only one option can be selected.
o Example:

RadioButton1.Caption := 'Option 1';


RadioButton2.Caption := 'Option 2';
RadioButton1.Checked := True;

o Result: Displays two radio buttons with "Option 1" selected by default.

79. TPanel (Component)


o Description: A container component used to group other components.
o How it Works: TPanel is a container that can hold other components, making it easier to
manage them as a group and control layout.
o Example:

Panel1.Caption := 'Settings Panel';

o Result: A panel displays with the text "Settings Panel".

80. TTimer (Component)


o Description: Generates recurring events at specified intervals.
o How it Works: TTimer triggers an event at regular intervals specified by the Interval
property. This is useful for periodic actions, such as updating a clock display.
o Example:

Timer1.Interval := 1000; // 1 second


Timer1.Enabled := True;

Page 29 of 38
IT Grade 10 – 12 Delphi Elements
o Result: The timer triggers every 1 second when enabled.

81. TBitBtn (Component)


o Description: A button control that can display both text and an image.
o How it Works: TBitBtn is similar to TButton but allows for an image (glyph) to be
displayed along with the button text.
o Example:

BitBtn1.Caption := 'Click Me';


BitBtn1.Glyph.LoadFromFile('icon.bmp');

o Result: The button displays the caption "Click Me" along with an image loaded from
"icon.bmp".

Events

82. OnChange (Event)


o Description: Triggered when the value of a component changes, such as in a TEdit or
TMemo control.
o How it Works: The OnChange event is executed whenever the text in a control like
TEdit or TMemo is altered by the user or programmatically.
o Example:

procedure TForm1.Edit1Change(Sender: TObject);


begin
ShowMessage('Text changed!');
end;

o Result: When the text in the edit box changes, a message box appears with the text "Text
changed!".

83. OnTimer (Event)


o Description: Triggered by a TTimer component at specified intervals.
o How it Works: The OnTimer event is executed whenever the timer interval elapses,
allowing for periodic actions to be performed.
o Example:

procedure TForm1.Timer1Timer(Sender: TObject);

Page 30 of 38
IT Grade 10 – 12 Delphi Elements
begin
ShowMessage('Timer tick!');
end;

o Result: A message box appears with the text "Timer tick!" at regular intervals based on
the TTimer component settings.

84. TADOQuery (Component)


o Description: Executes SQL queries against a database.
o How it Works: TADOQuery is used to run SQL queries on a connected database. It
supports SELECT, INSERT, UPDATE, and DELETE commands.
o Example:

ADOQuery1.SQL.Text := 'SELECT * FROM Students';


ADOQuery1.Open;

o Result: The query retrieves all records from the "Students" table in the connected
database.

85. TADOConnection (Component)


o Description: Manages the connection to a database.
o How it Works: TADOConnection handles the connection to a database, using a
connection string that specifies the database type, location, and login credentials.
o Example:

ADOConnection1.ConnectionString := 'Provider=SQLOLEDB;Data
Source=MyServer;Initial Catalog=MyDatabase;User
Id=myUsername;Password=myPassword;';
ADOConnection1.Open;

o Result: Establishes a connection to the specified database using the provided connection
string.

86. TDataSource (Component)


o Description: Links data-aware components to a dataset, such as a TADOQuery.
o How it Works: TDataSource acts as an intermediary between a dataset (like TADOQuery)
and data-aware components (like TDBGrid), allowing them to display and interact with
data.

Page 31 of 38
IT Grade 10 – 12 Delphi Elements
o Example:

DataSource1.DataSet := ADOQuery1;

o Result: Links the ADOQuery1 dataset to the DataSource1 component, allowing data-
aware controls to access the query results.

87. TDBGrid (Component)


o Description: Displays data from a dataset in a grid format.
o How it Works: TDBGrid is used to present data from a dataset in a tabular format,
allowing for the display and, optionally, editing of data.
o Example:

DBGrid1.DataSource := DataSource1;

o Result: The data from DataSource1 (and therefore ADOQuery1) is displayed in DBGrid1.

88. Eof() (Method)


o Description: Returns True if the end of a dataset or file has been reached.
o How it Works: The Eof function is used within loops to determine if the end of a dataset
or file has been reached, which prevents further reading.
o Example:

while not ADOQuery1.Eof do


begin
ShowMessage(ADOQuery1.FieldByName('StudentName').AsString);
ADOQuery1.Next;
end;

o Result: Iterates through the records in the ADOQuery1 dataset, displaying the
"StudentName" field for each record until the end of the dataset is reached.

89. TClientDataSet (Component)


o Description: Provides in-memory data storage and manipulation, allowing for
disconnected datasets.

Page 32 of 38
IT Grade 10 – 12 Delphi Elements
o How it Works: TClientDataSet is an in-memory dataset that can store data locally and
manipulate it without a persistent connection to the database.
o Example:

ClientDataSet1.LoadFromFile('Students.xml');
ClientDataSet1.Open;

o Result: Loads data from an XML file into the ClientDataSet1 component and opens
the dataset for use.

90. SaveToFile() (Method)


o Description: Saves the contents of a dataset to a file.
o How it Works: The SaveToFile method saves the current state of a dataset to a file,
typically in XML format, for later retrieval or backup.
o Example:

ClientDataSet1.SaveToFile('Backup.xml');

o Result: Saves the current data in ClientDataSet1 to an XML file named "Backup.xml".

91. TField (Component)


o Description: Represents a field in a dataset, allowing access to data within a record.
o How it Works: TField components represent individual columns in a dataset. They
provide access to the data stored in each field of a dataset record.
o Example:

var fieldValue: String;


fieldValue := ADOQuery1.FieldByName('StudentName').AsString;
ShowMessage(fieldValue);

o Result: Retrieves the value of the "StudentName" field from the current record and
displays it in a message box.

92. Locate() (Method)

Page 33 of 38
IT Grade 10 – 12 Delphi Elements
o Description: Searches for a record in a dataset that matches a specified condition.
o How it Works: The Locate method searches the dataset for a record that matches the
specified criteria. If found, the record pointer is moved to that record.
o Example:

if ADOQuery1.Locate('StudentID', 12345, []) then


ShowMessage('Student found: ' +
ADOQuery1.FieldByName('StudentName').AsString);

o Result: If a record with StudentID = 12345 is found, the student's name is displayed in
a message box.

93. TListView (Component)


o Description: Displays a list of items with optional icons, commonly used for displaying
lists with additional details.
o How it Works: TListView allows for the display of items in various views (e.g., report,
list) and can include sub-items for additional information.
o Example:

var listItem: TListItem;


listItem := ListView1.Items.Add;
listItem.Caption := 'Student 1';
listItem.SubItems.Add('Grade 10');

o Result: Adds a new item to ListView1 with the caption "Student 1" and a subitem
"Grade 10".

94. TComboBox (Component)


o Description: Allows users to select an option from a dropdown list.
o How it Works: TComboBox provides a list of items that users can select from. The
selected item is displayed as the control's text.
o Example:

ComboBox1.Items.Add('Option 1');
ComboBox1.Items.Add('Option 2');
ComboBox1.ItemIndex := 0;

o Result: Adds two options to ComboBox1 and selects the first option by default.

Page 34 of 38
IT Grade 10 – 12 Delphi Elements

95. TStringGrid (Component)


o Description: A grid control for displaying strings in cells, similar to a spreadsheet.
o How it Works: TStringGrid is used to display tabular data, allowing for the editing of
individual cells if needed.
o Example:

StringGrid1.Cells[0, 0] := 'Name';
StringGrid1.Cells[1, 0] := 'Grade';
StringGrid1.Cells[0, 1] := 'John Doe';
StringGrid1.Cells[1, 1] := 'A';

o Result: Populates StringGrid1 with headers "Name" and "Grade" in the first row, and
the student "John Doe" with a grade of "A" in the second row.

96. FindFirst, FindNext, FindClose (Methods)


o Description: Used to search for files or directories that match a specified pattern.
o How it Works: These methods are used together to locate files or directories. FindFirst
initiates the search, FindNext continues it, and FindClose terminates the search.
o Example:

var sr: TSearchRec;


if FindFirst('*.txt', faAnyFile, sr) = 0 then
begin
repeat
ShowMessage('File found: ' + sr.Name);
until FindNext(sr) <> 0;
FindClose(sr);
end;

o Result: Finds all .txt files in the current directory and displays each file name in a
message box.

97. TTimer (Component)


o Description: Generates recurring events at specified intervals.
o How it Works: TTimer is used to trigger events at regular intervals, which is useful for
tasks like updating a UI or processing data periodically.
o Example:

Timer1.Interval := 1000; // 1 second


Timer1.Enabled := True;

Page 35 of 38
IT Grade 10 – 12 Delphi Elements
o Result: The timer triggers every 1 second when enabled.

98. TBitBtn (Component)


o Description: A button control that can display both text and an image.
o How it Works: TBitBtn is similar to TButton but includes an image (glyph) that can be
displayed alongside the button text.
o Example:

BitBtn1.Caption := 'Click Me';


BitBtn1.Glyph.LoadFromFile('icon.bmp');

o Result: The button displays the caption "Click Me" along with an image loaded from
"icon.bmp".

99. TCheckBox (Component)


o Description: A checkbox control that allows the user to make binary choices.
o How it Works: TCheckBox can be checked or unchecked by the user. The state is stored
in the Checked property.
o Example:

CheckBox1.Caption := 'I agree';


CheckBox1.Checked := True;

o Result: The checkbox displays with the text "I agree" and is checked by default.

100. TPageControl and TTabSheet (Components)


o Description: Used together to create tabbed interfaces.
o How it Works: TPageControl manages multiple TTabSheet components, allowing users
to switch between different tabs in a form.
o Example:

TabSheet1.Caption := 'Tab 1';


TabSheet2.Caption := 'Tab 2';
PageControl1.ActivePage := TabSheet1;

o Result: Creates a tabbed interface with two tabs, "Tab 1" and "Tab 2", and makes "Tab
1" the active tab.

Page 36 of 38
IT Grade 10 – 12 Delphi Elements

Events

101. OnDrawCell (Event - TStringGrid)


o Description: Triggered when a cell in a TStringGrid is drawn, allowing custom
drawing.
o How it Works: The OnDrawCell event is used to customize the appearance of individual
cells in a TStringGrid, such as changing colors or adding graphics.
o Example:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:


Integer; Rect: TRect; State: TGridDrawState);
begin
StringGrid1.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2,
StringGrid1.Cells[ACol, ARow]);
end;

o Result: Customizes the way each cell in StringGrid1 is drawn.

102. OnFilterRecord (Event - TClientDataSet)


o Description: Triggered when filtering records in a TClientDataSet.
o How it Works: The OnFilterRecord event is used to define criteria for filtering records
in a TClientDataSet, allowing only records that meet the criteria to be visible.
o Example:

procedure TForm1.ClientDataSet1FilterRecord(DataSet: TDataSet; var


Accept: Boolean);
begin
Accept := DataSet.FieldByName('Grade').AsString = 'A';
end;

o Result: Filters the dataset to only include records where the "Grade" field is "A".

103. OnBeforeOpen (Event - TADOQuery)


o Description: Triggered before a query is opened, allowing for last-minute adjustments.
o How it Works: The OnBeforeOpen event is used to modify the SQL query or set up
necessary conditions right before a query is executed.
o Example:

procedure TForm1.ADOQuery1BeforeOpen(DataSet: TDataSet);

Page 37 of 38
IT Grade 10 – 12 Delphi Elements
begin
ADOQuery1.SQL.Text := 'SELECT * FROM Students WHERE Grade = ''A''';
end;

o Result: Modifies the SQL query to only select students with a grade of "A" before the
query is executed.
104. OnAfterPost (Event - TClientDataSet)
o Description: Triggered after changes are posted to a dataset, allowing for further
processing.
o How it Works: The OnAfterPost event is used to perform actions after a record has
been posted to the dataset, such as displaying a confirmation message or updating related
data.
o Example:

procedure TForm1.ClientDataSet1AfterPost(DataSet: TDataSet);


begin
ShowMessage('Record saved successfully.');
end;

o Result: Displays a confirmation message after a record is successfully saved in


ClientDataSet1.

Page 38 of 38

You might also like