HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to DelphiVariablesData Types & ConversionOperatorsStringsConditions (if)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔄 Data Types & Conversion
✍️ String
🔁 Condition & Loop
🧩 Function & Procedure
functionprocedure
Delphi›REFERENCE›Function & Procedure
🧩

Function & Procedure

function and procedure.

CommandDescription
functionSubroutine that returns a value.
procedureSubroutine that does not return a value.

function

Try it yourself →

Subroutine that returns a value.

Syntax

function name(x: Type): Type; begin name := ...; end;

Description

The return value is assigned to the function name (or Result). It is defined before begin. div is integer division, mod is remainder.

Example

program H;
{$MODE DELPHI}
function square(x: Integer): Integer;
begin
  square := x * x;
end;
begin
  writeln(square(5));
end.

Expected output

25

When to use?

Preventing code repetition.

Common mistakes

  • ⚠️ The return value is assigned to the function name: square := x*x; (no return keyword).

procedure

Try it yourself →

Subroutine that does not return a value.

Syntax

procedure name(x: Type); begin ... end;

Description

Does not return a result, just performs an action; called by its name.

Example

program H;
{$MODE DELPHI}
procedure greet(name: String);
begin
  writeln('Hello ' + name);
end;
begin
  greet('Alex');
end.

Expected output

Hello Alex

When to use?

Operations with side effects.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code