Variables and types
Every variable in NeoObjectPascal has a declared type. The declaration uses the var keyword, followed by the name, a colon, and the type:
var idade: Integer;
var nome: String;Values are assigned with the := operator (don't confuse it with =, which is the equality operator):
begin
var idade: Integer;
idade := 30;
WriteLn("Idade: ", idade);
end.Idade: 30
Where to declare
You can declare variables in two places:
- At the top of the file, before the main block.
- Inside a block
begin ... end, as an ordinary statement.
var total: Integer; // top-level declaration
begin
total := 100;
var imposto: Integer; // declaration inside the block
imposto := total / 10;
WriteLn("Imposto: ", imposto);
end.Imposto: 10
The ten types
NeoObjectPascal has ten built-in types:
| Type | Description | Literal examples |
|---|---|---|
Integer | Whole numbers | 0, 42, -7 |
Real | Floating-point numbers (double precision) | 3.14159, 5.0, -0.5 |
String | Text | "olá", 'mundo' |
Boolean | Logical value | true, false |
Array | Ordered collection of values | [1, 2, 3], ["a", "b"] |
Object | Generic type (instances, JSON/CSV, assorted values) | new Pessoa("Ana") |
Date | Calendar date (ISO yyyy-MM-dd) | today(), date(2026,12,25) |
Time | Time of day (HH:mm:ss) | currentTime(), time(10,30,0) |
DateTime | Combined date and time | now() |
Currency | Exact decimal money (no floating-point error) | currency(199.90) |
On top of these, Double and Float are aliases of Real (64-bit floating point) — use whichever name you prefer. The Date, Time, DateTime and Currency types are covered in detail in Dates, times & currency.
Literals and details of each type
Integer and Real
Integers are written directly: 10, -3, 0. Real numbers require digits on both sides of the decimal point:
begin
var meio: Real;
meio := 0.5; // correct
WriteLn(meio);
end.0.5
Real requires complete digits
Write 5.0, never 5. — the second form is invalid. Likewise, use 0.5 and not .5.
When you mix Integer and Real in an expression, the integer is automatically promoted to Real. The same happens when assigning an integer to a Real variable:
begin
var x: Real;
x := 5; // 5 becomes 5.0
var y: Real;
y := 2 * 3.5; // Real result
WriteLn("x = ", x);
WriteLn("y = ", y);
end.x = 5.0 y = 7.0
String
Strings can use double quotes or single quotes — both work the same way:
begin
var a: String;
var b: String;
a := "aspas duplas";
b := 'aspas simples';
WriteLn(a);
WriteLn(b);
end.aspas duplas aspas simples
The + operator concatenates strings. If either side is a String, + joins the values instead of adding them:
begin
var nome: String;
nome := "Mundo";
WriteLn("Olá, " + nome + "!");
end.Olá, Mundo!
Boolean
A Boolean holds true or false (also accepted in uppercase, such as True or TRUE):
begin
var ativo: Boolean;
ativo := true;
WriteLn("Ativo: ", ativo);
end.Ativo: true
Object
Object is the language's generic type. It holds class instances, results of JSON.parse/CSV.parse, and any value whose specific type you don't need to name:
class Pessoa
var nome: String;
constructor Create(n: String)
begin
self.nome := n;
end;
public function saudar(): String
begin
return "Sou " + self.nome;
end;
end;
var p: Object;
begin
p := new Pessoa("Alice");
WriteLn(p.saudar());
end.Sou Alice
Choosing the type
Prefer the most specific type possible (Integer, String, etc.) and reserve Object for instances and dynamic data.
Now that you know how to declare variables, see how to combine them in Operators.