Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Collections/Delphi/collections-1.delphi
Normal file
30
Task/Collections/Delphi/collections-1.delphi
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Creates and initializes a new integer Array
|
||||
var
|
||||
// Dynamics arrays can be initialized, if it's global variable in declaration scope
|
||||
intArray: TArray<Integer> = [1, 2, 3, 4, 5];
|
||||
intArray2: array of Integer = [1, 2, 3, 4, 5];
|
||||
|
||||
//Cann't initialize statics arrays in declaration scope
|
||||
intArray3: array [0..4]of Integer;
|
||||
intArray4: array [10..14]of Integer;
|
||||
|
||||
procedure
|
||||
var
|
||||
// Any arrays can't be initialized, if it's local variable in declaration scope
|
||||
intArray5: TArray<Integer>;
|
||||
begin
|
||||
// Dynamics arrays can be full assigned in routine scope
|
||||
intArray := [1,2,3];
|
||||
intArray2 := [1,2,3];
|
||||
|
||||
// Dynamics arrays zero-based
|
||||
intArray[0] := 1;
|
||||
|
||||
// Dynamics arrays must set size, if it not was initialized before
|
||||
SetLength(intArray,5);
|
||||
|
||||
// Inline dynamics arrays can be created and initialized routine scope
|
||||
// only for version after 10.3 Tokyo
|
||||
var intArray6 := [1, 2, 3];
|
||||
var intArray7: TArray<Integer> := [1, 2, 3];
|
||||
end;
|
||||
28
Task/Collections/Delphi/collections-2.delphi
Normal file
28
Task/Collections/Delphi/collections-2.delphi
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
var
|
||||
// TLists can't be initialized or created in declaration scope
|
||||
List1, List2:TList<Integer>;
|
||||
begin
|
||||
List1 := TList<Integer>.Create;
|
||||
List1.Add(1);
|
||||
list1.AddRange([2, 3]);
|
||||
List1.free;
|
||||
|
||||
// TList can be initialized using a class derivative from TEnumerable, like it self
|
||||
List1 := TList<Integer>.Create;
|
||||
list1.AddRange([1,2, 3]);
|
||||
|
||||
List2 := TList<Integer>.Create(list1);
|
||||
Writeln(List2[2]); // 3
|
||||
List1.free;
|
||||
List2.free;
|
||||
|
||||
|
||||
// Inline TList can be created in routine scope
|
||||
// only for version after 10.3 Tokyo
|
||||
var List3:= TList<Integer>.Create;
|
||||
List3.Add(2);
|
||||
List3.free;
|
||||
|
||||
var List4: TList<Integer>:= TList<Integer>.Create;
|
||||
List4.free;
|
||||
end;
|
||||
18
Task/Collections/Delphi/collections-3.delphi
Normal file
18
Task/Collections/Delphi/collections-3.delphi
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
var
|
||||
// TDictionary can't be initialized or created in declaration scope
|
||||
Dic1: TDictionary<string, Integer>;
|
||||
begin
|
||||
Dic1 := TDictionary<string, Integer>.Create;
|
||||
Dic1.Add('one',1);
|
||||
Dic1.free;
|
||||
|
||||
// Inline TDictionary can be created in routine scope
|
||||
// only for version after 10.3 Tokyo
|
||||
var Dic2:= TDictionary<string, Integer>.Create;
|
||||
Dic2.Add('one',1);
|
||||
Dic2.free;
|
||||
|
||||
var Dic3: TDictionary<string, Integer>:= TDictionary<string, Integer>.Create.Create;
|
||||
Dic3.Add('one',1);
|
||||
Dic3.free;
|
||||
end;
|
||||
24
Task/Collections/Delphi/collections-4.delphi
Normal file
24
Task/Collections/Delphi/collections-4.delphi
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
var
|
||||
Queue1, Queue2: TQueue<Integer>;
|
||||
List1:TList<Integer>;
|
||||
begin
|
||||
Queue1 := TQueue<Integer>.Create;
|
||||
Queue1.Enqueue(1);
|
||||
Queue1.Enqueue(2);
|
||||
Writeln(Queue1.Dequeue); // 1
|
||||
Writeln(Queue1.Dequeue); // 2
|
||||
Queue1.free;
|
||||
|
||||
// TQueue can be initialized using a class derivative from TEnumerable, like TList<T>
|
||||
List1 := TList<Integer>.Create;
|
||||
List1.Add(3);
|
||||
Queue2:= TQueue<Integer>.Create(List1);
|
||||
Writeln(Queue2.Dequeue); // 3
|
||||
List1.free;
|
||||
Queue2.free;
|
||||
|
||||
// Inline TQueue can be created in routine scope
|
||||
// only for version after 10.3 Tokyo
|
||||
var Queue3 := TQueue<Integer>.Create;
|
||||
Queue3.free;
|
||||
end;
|
||||
24
Task/Collections/Delphi/collections-5.delphi
Normal file
24
Task/Collections/Delphi/collections-5.delphi
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
var
|
||||
Stack1, Stack2: TStack<Integer>;
|
||||
List1:TList<Integer>;
|
||||
begin
|
||||
Stack1:= TStack<Integer>.Create;
|
||||
Stack1.Push(1);
|
||||
Stack1.Push(2);
|
||||
Writeln(Stack1.Pop); // 2
|
||||
Writeln(Stack1.Pop); // 1
|
||||
Stack1.free;
|
||||
|
||||
// TStack can be initialized using a class derivative from TEnumerable, like TList<T>
|
||||
List1 := TList<Integer>.Create;
|
||||
List1.Add(3);
|
||||
Stack2:= TStack<Integer>.Create(List1);
|
||||
Writeln(Stack2.Pop); // 3
|
||||
List1.free;
|
||||
Stack2.free;
|
||||
|
||||
// Inline TStack can be created in routine scope
|
||||
// only for version after 10.3 Tokyo
|
||||
var Stack3:= TStack<Integer>.Create;
|
||||
Stack3.free;
|
||||
end;
|
||||
27
Task/Collections/Delphi/collections-6.delphi
Normal file
27
Task/Collections/Delphi/collections-6.delphi
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
var
|
||||
Str1:String; // default WideString
|
||||
Str2:WideString;
|
||||
Str3:UnicodeString;
|
||||
Str4:AnsiString;
|
||||
Str5: PChar; //PWideChar is the same
|
||||
Str6: PAnsiChar;
|
||||
|
||||
// Strings can be initialized, if it's global variable in declaration scope
|
||||
Str4: string = 'orange';
|
||||
begin
|
||||
Str1 := 'apple';
|
||||
|
||||
// WideString and AnsiString can be converted implicitly, but in some times can lost information about char
|
||||
Str4 := Str1;
|
||||
|
||||
// PChar is a poiter to string (WideString), must be converted using type cast
|
||||
Str5 := Pchar(Str1);
|
||||
|
||||
// PChar not must type cast to convert back string
|
||||
Str2 := Str5;
|
||||
|
||||
//In any string, index start in 1 and end on length of string
|
||||
Writeln(Str1[1]); // 'a'
|
||||
Writeln(Str1[5]); // 'e'
|
||||
Writeln(Str1[length(str1)]); // the same above
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue