I
explicitly explained that rtl-generics are only in trunk |(3.1.1).
I suggest to use the fgl example for now if you are a beginner, although it is possible to install an older sparta package separately. rtl-generics are based on that, but much more advanced due to new compiler features.
Just use fgl for now if you are a real beginner: the functionality and syntax are similar. As I showed.
The use of trunk is also possible and easiest to install using fpcupdeluxe. If you are adventurous and want the latest features.
ad 2: no, on the contrary:
for in do prevents you from making mistakes in code because it protects you from introducing range errors. If possible always use
for in do instead of
for i := x to y...
The reason is that you can make a mistake with x or y or both and it will crash your code.
For in do automatically prevents you from making such a mistake.
example:
program buggy;
{$mode delphi}
var
test:array of integer;
i:integer;
begin
Test:=Test.Create(1,2,3,4,5,6,7,8,9,10); //10 elements
for i := 1 to 10 do
writeln(Test[i]); // wrong! but do you know why?
end.
As opposed to
program lessbuggy;
{$mode delphi}
var
test:array of integer;
i:integer;
begin
Test:=Test.Create(1,2,3,4,5,6,7,8,9,10); //10 elements
for i in test do
writeln(i); // writes the array element !!
end.