Menu

1 / 2

Generics in CrabPascal: TList and TDictionary (v2.15.0) | Generics no CrabPascal: TList e TDictionary (v2.15.0)

DEV Community·CrabPascal·6 months ago
#iQwCnUG5
#dev#portugus#string#tdictionary#generics
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.