-
Notifications
You must be signed in to change notification settings - Fork 7
TPair
Ivan Semenkov edited this page Jan 29, 2021
·
1 revision
TPair is a class template that provides a way to store two different objects as a single unit. A pair is a specific case of a TTuple with two elements.
uses
utils.pair;
type
generic TPair<T1, T2> = class
type
TSelfPair = {$IFDEF FPC}specialize{$ENDIF} TPair<T1, T2>;
end;
A new pair can be created by using one of constructors.
constructor Create;
constructor Create (AFirst : T1; ASecond : T2);
constructor Create (APair : TSelfPair);
uses
utils.pair;
type
TIntStrPair = {$IFDEF FPC}specialize{$ENDIF} TPair<Integer, String>;
var
pair : TIntStrPair;
begin
pair := TIntStrPair.Create;
FreeAndNil(pair);
end;
Get/set first pair value.
property First : T1;
uses
utils.pair;
type
TIntStrPair = {$IFDEF FPC}specialize{$ENDIF} TPair<Integer, String>;
var
pair : TIntStrPair;
begin
pair := TIntStrPair.Create;
pair.First := 5;
writeln(pair.First);
FreeAndNil(pair);
end;
Get/set second pair value.
property Second : T2;
uses
utils.pair;
type
TIntStrPair = {$IFDEF FPC}specialize{$ENDIF} TPair<Integer, String>;
var
pair : TIntStrPair;
begin
pair := TIntStrPair.Create;
pair.Second := 'some value';
writeln(pair.Second);
FreeAndNil(pair);
end;