
21.10.2008, 21:40
|
Модератор
|
|
Регистрация: 17.04.2008
Сообщения: 8,087
Версия Delphi: 7, XE3, 10.2
Репутация: 49089
|
|
1.
Код:
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
procedure Proc2; forward;
procedure Proc3; forward;
procedure Proc1;
begin
WriteLn('Proc1 begin');
Proc2;
WriteLn('Proc1 end');
end;
procedure Proc2;
begin
WriteLn('Proc2 begin');
Proc3;
WriteLn('Proc2 end');
end;
procedure Proc3;
begin
WriteLn('Proc3 begin');
Raise Exception.Create('My exception');
WriteLn('Proc3 end');
end;
begin
WriteLn('Program begin');
Try
Proc1;
Except
On E : Exception Do
WriteLn('Excetion: '+E.Message);
End;
WriteLn('Program end');
ReadLn;
end.
TList:
Код:
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils, Classes;
type
PInt = ^Integer;
var
MyList : TList;
lptInt : PInt;
I : Integer;
procedure PrintList(AList : TList);
var
I : Integer;
begin
WriteLn('My list:');
For I := 0 To AList.Count-1 Do
WriteLn(Format('MyList[%d] = %d',[I,(PInt(AList.Items[i]))^]));
end;
procedure SortList(AList : TList);
var
I, J : Integer;
begin
For I := 0 To AList.Count-2 Do
For J := I+1 To AList.Count-1 Do
If PInt(AList[i])^ > PInt(AList[J])^ Then AList.Exchange(I,J);
end;
begin
Randomize;
lptInt := Nil;
MyList := TList.Create;
Try
WriteLn(Format('Capacity = %d; Count = %d',[MyList.Capacity,MyList.Count]));
New(lptInt);
lptInt^ := Random(100);
MyList.Add(lptInt);
For I := 1 To 10 Do
Begin
New(lptInt);
lptInt^ := Random(100);
MyList.Add(lptInt);
End;
PrintList(MyList);
lptInt := MyList[2];
MyList.Delete(2);
Dispose(lptInt);
PrintList(MyList);
New(lptInt);
lptInt^ := Random(100);
MyList.Insert(4,lptInt);
PrintList(MyList);
SortList(MyList);
PrintList(MyList);
Finally
MyList.Free;
End;
ReadLn;
end.
|