1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
program Project43;
{$APPTYPE CONSOLE}
uses
Windows, SysUtils, Classes, Contnrs;
// creation d'un liste pour les valeurs entières
type
TIntegerList = class(TList)
private
FLast: integer;
FFirst: integer;
function GetInt(index: integer): integer;
procedure SetInt(index: integer; const Value: integer);
published
public
property Items[index: integer]: integer read GetInt write SetInt;
function First: integer;
function Last: integer;
function Add(const Value: integer): integer;
function IndexOf(const Value: integer): integer;
end;
{ TIntegerList }
function TIntegerList.Add(const Value: integer): integer;
begin
result := inherited Add(pointer(Value));
end;
function TIntegerList.First: integer;
begin
result := integer(inherited First);
end;
function TIntegerList.GetInt(index: integer): integer;
begin
result := integer(inherited Items[index]);
end;
function TIntegerList.IndexOf(const Value: integer): integer;
begin
result := inherited IndexOf(pointer(Value));
end;
function TIntegerList.Last: integer;
begin
result := integer(inherited Last);
end;
procedure TIntegerList.SetInt(index: integer; const Value: integer);
begin
inherited items[index] := pointer(Value);
end;
// ----------------------------------------------------------------------- //
var
// Liste A et B
ListA, ListB: TIntegerList;
// Nom du fichier des données
FileName : string;
// Borne des données pour liste A et B
IFLA, ITLA,
IFLB, ITLB : integer;
// compteur pour les boucles
N : integer;
begin
// creation des listes
ListA := TIntegerList.Create;
ListB := TIntegerList.Create;
try
// récupération du fichier de données
FileName := ExtractFilePath(ParamStr(0))+'Data.txt';
// utilisation d'une TStringList
with TStringList.Create do
try
// chargement des données
LoadFromFile(FileName);
// séléction du délimiteur de données, ici un espace
Delimiter := ' ';
// découpage
DelimitedText := Text;
// si on as au moins 3 lignes : "1 | 2" par exemple
if count > 3 then
begin
// borne min liste A
IFLA := 0;
// borne max liste A
ITLA := IndexOf('|')-1;
// borne min liste B
IFLB := ITLA+2;
// borne max liste B
ITLB := Count-1;
// affichage
Write('List A : ');
for N := IFLA to ITLA do
begin
// récupération et listage
ListA.Add( StrToIntDef(Strings[N], -1) );
// affichage
if N < ITLA then
write(Strings[N],', ')
else
writeln(Strings[N]);
end;
// affichage
write('List B : ');
for N := IFLB to ITLB do
begin
// récupération et listage
ListB.Add( StrToIntDef(Strings[N], -1) );
// affichage
if N < ITLB then
write(Strings[N], ', ')
else
writeln(Strings[N]);
end;
end;
finally
// libération de la stringlist
Free;
end;
finally
// libération des listes.
ListB.Free;
ListA.Free;
end;
// attente d'appuis sur une touche
readln;
end. |
Partager