
21.03.2011, 13:32
|
 |
Let Me Show You
|
|
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
|
|
Critical Section Objects
Код:
unit Unit1;
interface
uses
SyncObjs,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CriticalSection: TCriticalSection;
ArrID: array [0..6] of Integer = (1, 2, 7, 9, 10, 21, 23);
CurrentID: Integer;
implementation
{$R *.dfm}
function GetNextArrID: Integer;
begin
CriticalSection.Enter;
try
if CurrentID<Length(ArrID) then Result:=ArrID[CurrentID] else Result:=-1;
Inc(CurrentID);
finally
CriticalSection.Leave;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text:=IntToStr(GetNextArrID);
end;
initialization
CriticalSection:=TCriticalSection.Create;
CurrentID:=0;
finalization
CriticalSection.Free;
end.
__________________
Пишу программы за еду.
__________________
|