Bilingual post · Post bilíngue
Jump to: English · Português
English {#english}
Generics in CrabPascal: TList and TDictionary (v2.15.0)
Generic collections are the backbone of modern Delphi — caches, registries, JSON maps. Sprint 7 ( v2.15.0 ) shipped System.Generics.Collections with working TDictionary<K,V> and TList<T> , including the all-important TryGetValue with var parameters.
Dictionary basics
program DictDemo ; uses System . SysUtils , System . Generics . Collections ;
var D : TDictionary < string , Integer >; V : Integer ; begin D := TDictionary < string , Integer >. Create ; try D . Add ( 'apples' , 3 ); D . Add ( 'oranges' , 5 );
if D . TryGetValue ( 'apples' , V ) then WriteLn ( 'apples = ' , V ) else WriteLn ( 'not found' ); finally D . Free ; end ; end .
Enter fullscreen mode
Exit fullscreen mode
TryGetValue writes into V only when the key exists — the Delphi pattern you expect in production code.
Why var mattered in Sprint 7
Before v2.15.0, var parameters were incomplete.…