Overview

Assoc Complex Keys

Using non-string keys in associative arrays

Source Code

// Using non-string keys in associative arrays
var idMap: array [Integer] of String;

idMap[101] := 'Product A';
idMap[202] := 'Product B';
idMap[303] := 'Product C';

PrintLn('ID 202 belongs to: ' + idMap[202]);

// Using Float as keys (be careful with precision!)
var floatMap: array [Float] of String;
floatMap[3.14] := 'Pi';
floatMap[2.71] := 'Euler';

PrintLn('3.14 is ' + floatMap[3.14]);

// Checking length
PrintLn('ID Map Length: ' + IntToStr(idMap.Length));

Result

ID 202 belongs to: Product B
3.14 is Pi
ID Map Length: 3
On this page