-
Notifications
You must be signed in to change notification settings - Fork 7
TTuple
Ivan Semenkov edited this page Jan 29, 2021
·
1 revision
TTuple is a class template that provides a way to store various different objects as a single unit.
uses
utils.tuple;
type
generic TTuple3<T1, T2, T3> = class
type
TSelfTuple3 = {$IFDEF FPC}specialize{$ENDIF} TTuple3<T1, T2, T3>;
end;
uses
utils.tuple;
type
generic TTuple4<T1, T2, T3, T4> = class
type
TSelfTuple4 = {$IFDEF FPC}specialize{$ENDIF} TTuple4<T1, T2, T3, T4>;
end;
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;
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;
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;
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;
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;
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;
A new pair can be created by using one of constructors.
constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3);
constructor Create (ATuple : TSelfTuple3);
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;
constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4);
constructor Create (ATuple : TSelfTuple4);
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;
constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4;
AFifth : T5);
constructor Create (ATuple : TSelfTuple5);
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;
constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4;
AFifth : T5; ASixth : T6);
constructor Create (ATuple : TSelfTuple6);
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;
constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4;
AFifth : T5; ASixth : T6; ASeventh : T7);
constructor Create (ATuple : TSelfTuple7);
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;
constructor Create;
constructor Create (AFirst : T1; ASecond : T2; AThird : T3; AFourth : T4;
AFifth : T5; ASixth : T6; ASeventh : T7; AEighth : T8);
constructor Create (ATuple : TSelfTuple8);
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;
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);
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;
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);
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;
Get/set first tuple value.
property First : T1;
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;
Get/set second tuple value.
property Second : T2;
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;
Get/set third tuple value.
property Third : T3;
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;
Get/set fourth tuple value.
property Fourth : T4;
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;
Get/set fifth tuple value.
property Fifth : T5;
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;
Get/set sixth tuple value.
property Sixth : T6;
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;
Get/set seventh tuple value.
property Seventh : T7;
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;
Get/set eighth tuple value.
property Eighth : T8;
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;
Get/set ninth tuple value.
property Ninth : T9;
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;
Get/set tenth tuple value.
property Tenth : T10;
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;