Skip to content
Ivan Semenkov edited this page Jan 29, 2021 · 1 revision

Table of contents

About

TTuple is a class template that provides a way to store various different objects as a single unit.

TTuple3

uses
  utils.tuple;
  
type
  generic TTuple3<T1, T2, T3> = class
  type
    TSelfTuple3 = {$IFDEF FPC}specialize{$ENDIF} TTuple3<T1, T2, T3>;
  end;

TTuple4

uses
  utils.tuple;
  
type
  generic TTuple4<T1, T2, T3, T4> = class
  type
    TSelfTuple4 = {$IFDEF FPC}specialize{$ENDIF} TTuple4<T1, T2, T3, T4>;
  end;

TTuple5

uses
  utils.tuple;
  
type
  generic TTuple5<T1, T2, T3, T4, T5> = class
  type
    TSelfTuple5 = {$IFDEF FPC}specialize{$ENDIF} TTuple5<T1, T2, T3, T4, T5>;
  end;

TTuple6

uses
  utils.tuple;
  
type
  generic TTuple6<T1, T2, T3, T4, T5, T6> = class
  type
    TSelfTuple6 = {$IFDEF FPC}specialize{$ENDIF} TTuple6<T1, T2, T3, T4, T5, T6>;
  end;

TTuple7

uses
  utils.tuple;
  
type
  generic TTuple7<T1, T2, T3, T4, T5, T6, T7> = class
  type
    TSelfTuple7 = {$IFDEF FPC}specialize{$ENDIF} TTuple7<T1, T2, T3, T4, T5, T6, T7>;
  end;

TTuple8

uses
  utils.tuple;
  
type
  generic TTuple8<T1, T2, T3, T4, T5, T6, T7, T8> = class
  type
    TSelfTuple8 = {$IFDEF FPC}specialize{$ENDIF} TTuple8<T1, T2, T3, T4, T5, T6, T7, T8>;
  end;

TTuple9

uses
  utils.tuple;
  
type
  generic TTuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9> = class
  type
    TSelfTuple9 = {$IFDEF FPC}specialize{$ENDIF} TTuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9>;
  end;

TTuple10

uses
  utils.tuple;
  
type
  generic TTuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> = class
  type
    TSelfTuple10 = {$IFDEF FPC}specialize{$ENDIF} TTuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>;
  end;

Create

A new pair can be created by using one of constructors.

TTuple3

constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3);
constructor Create (ATuple : TSelfTuple3);
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple3<TValue1Type, TValue2Type, TValue3Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  
  FreeAndNil(tuple);
end;

TTuple4

constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4);
constructor Create (ATuple : TSelfTuple4);
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple4<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  
  FreeAndNil(tuple);
end;

TTuple5

constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4;
  AFifth : T5);
constructor Create (ATuple : TSelfTuple5);
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple5<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  
  FreeAndNil(tuple);
end;

TTuple6

constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4;
  AFifth : T5; ASixth : T6);
constructor Create (ATuple : TSelfTuple6);
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TValue6Type = type String;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple6<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type, TValue6Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  
  FreeAndNil(tuple);
end;

TTuple7

constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4;
  AFifth : T5; ASixth : T6; ASeventh : T7);
constructor Create (ATuple : TSelfTuple7);
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TValue6Type = type String;
  TValue7Type = type String;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple7<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type, TValue6Type, TValue7Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  
  FreeAndNil(tuple);
end;

TTuple8

constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4;
  AFifth : T5; ASixth : T6; ASeventh : T7; AEighth : T8);
constructor Create (ATuple : TSelfTuple8);
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TValue6Type = type String;
  TValue7Type = type String;
  TValue8Type = type Pointer;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple8<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type, TValue6Type, TValue7Type,
    TValue8Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  
  FreeAndNil(tuple);
end;

TTuple9

constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4;
  AFifth : T5; ASixth : T6; ASeventh : T7; AEighth : T8; ANineth : T9);
constructor Create (ATuple : TSelfTuple9);
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TValue6Type = type String;
  TValue7Type = type String;
  TValue8Type = type Pointer;
  TValue9Type = type Integer;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple9<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type, TValue6Type, TValue7Type,
    TValue8Type, TValue9Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  
  FreeAndNil(tuple);
end;

TTuple10

constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4;
  AFifth : T5; ASixth : T6; ASeventh : T7; AEighth : T8; ANineth : T9;
  ATenth : T10);
constructor Create (ATuple : TSelfTuple9);
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TValue6Type = type String;
  TValue7Type = type String;
  TValue8Type = type Pointer;
  TValue9Type = type Integer;
  TValue10Type = type Integer;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple10<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type, TValue6Type, TValue7Type,
    TValue8Type, TValue9Type, TValue10Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  
  FreeAndNil(tuple);
end;

First

Get/set first tuple value.

property First : T1;
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple3<TValue1Type, TValue2Type, TValue3Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  tuple.First := TValue1Type(12);
  writeln(tuple.First);
  
  FreeAndNil(tuple);
end;

Second

Get/set second tuple value.

property Second : T2;
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple3<TValue1Type, TValue2Type, TValue3Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  tuple.Second := TValue2Type('value');
  writeln(tuple.Second);
  
  FreeAndNil(tuple);
end;

Third

Get/set third tuple value.

property Third : T3;
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple3<TValue1Type, TValue2Type, TValue3Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  tuple.Third := TValue3Type(42);
  writeln(tuple.Third);
  
  FreeAndNil(tuple);
end;

Fourth

Get/set fourth tuple value.

property Fourth : T4;
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple4<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  tuple.Fourth := TValue4Type(42);
  writeln(tuple.Fourth);
  
  FreeAndNil(tuple);
end;

Fifth

Get/set fifth tuple value.

property Fifth : T5;
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple5<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  tuple.Fifth := TValue5Type(nil);
  
  FreeAndNil(tuple);
end;

Sixth

Get/set sixth tuple value.

property Sixth : T6;
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TValue6Type = type String;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple6<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type, TValue6Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  tuple.Sixth := TValue6Type('some value');
  writeln(tuple.Sixth);
  
  FreeAndNil(tuple);
end;

Seventh

Get/set seventh tuple value.

property Seventh : T7;
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TValue6Type = type String;
  TValue7Type = type String;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple7<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type, TValue6Type, TValue7Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  tuple.Seventh := TValue7Type('some value');
  writeln(tuple.Seventh);
  
  FreeAndNil(tuple);
end;

Eighth

Get/set eighth tuple value.

property Eighth : T8;
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TValue6Type = type String;
  TValue7Type = type String;
  TValue8Type = type Pointer;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple8<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type, TValue6Type, TValue7Type,
    TValue8Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  tuple.Eighth := TValue8Type(nil);
  
  FreeAndNil(tuple);
end;

Ninth

Get/set ninth tuple value.

property Ninth : T9;
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TValue6Type = type String;
  TValue7Type = type String;
  TValue8Type = type Pointer;
  TValue9Type = type Integer;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple9<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type, TValue6Type, TValue7Type,
    TValue8Type, TValue9Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  tuple.Nineth := TValue9Type(-5);
  writeln(tuple.Nineth);
  
  FreeAndNil(tuple);
end;

Tenth

Get/set tenth tuple value.

property Tenth : T10;
Example
uses
  utils.tuple;
  
type
  TValue1Type = type Integer;
  TValue2Type = type String;
  TValue3Type = type Byte;
  TValue4Type = type Integer;
  TValue5Type = type Pointer;
  TValue6Type = type String;
  TValue7Type = type String;
  TValue8Type = type Pointer;
  TValue9Type = type Integer;
  TValue10Type = type Integer;
  TTupleValue = {$IFDEF FPC}specialize{$ENDIF} TTuple10<TValue1Type, TValue2Type, 
    TValue3Type, TValue4Type, TValue5Type, TValue6Type, TValue7Type,
    TValue8Type, TValue9Type, TValue10Type>;
  
var
  tuple : TTupleValue;
  
begin
  tuple := TTupleValue.Create;
  tuple.Tenth := TValue10Type(254);
  writeln(tuple.Tenth);
  
  FreeAndNil(tuple);
end;