unit GlobalForm;
 
interface
 
uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 StdCtrls, GlobalHdr;
 
type
 
 TReadInfoProc = procedure(var GlobalInfo: TGlobalInfo; var LocalThreads: integer); stdcall;
 TSetProc = procedure(NewValue: integer); stdcall;
 TIncDecProc = procedure; stdcall;
 
 TProcs = record
 ReadProc: TReadInfoProc;
 SetProc: TSetProc;
 IncProc, DecProc: TIncDecProc;
 end;
 
 TGlobalFrm = class(TForm)
 GlobalProcessEdit: TEdit;
 GlobalThreadEdit: TEdit;
 LocalThreadEdit: TEdit;
 SharedDataEdit: TEdit;
 ReadBtn: TButton;
 IncBtn: TButton;
 DecBtn: TButton;
 SetBtn: TButton;
 CreateThread: TButton;
 LoadDLLBtn: TButton;
 procedure ReadBtnClick(Sender: TObject);
 procedure IncBtnClick(Sender: TObject);
 procedure DecBtnClick(Sender: TObject);
 procedure SetBtnClick(Sender: TObject);
 procedure CreateThreadClick(Sender: TObject);
 procedure LoadDLLBtnClick(Sender: TObject);
 procedure FormCreate(Sender: TObject);
 procedure FormDestroy(Sender: TObject);
 private
 { Private declarations }
 Procs: TProcs;
 Loaded: boolean;
 LibHandle: THandle;
 public
 { Public declarations }
 end;
 
var
 GlobalFrm: TGlobalFrm;
 
implementation
 
uses DelayThread;
 
{$R *.DFM}
 
procedure TGlobalFrm.ReadBtnClick(Sender: TObject);
 
var
 GlobalInfo: TGlobalInfo;
 LocalThreads: integer;
 
begin
 if Loaded then
 begin
 Procs.ReadProc(GlobalInfo, LocalThreads);
 GlobalProcessEdit.Text := IntToStr(GlobalInfo.GlobalProcesses);
 GlobalThreadEdit.Text := IntToStr(GlobalInfo.GlobalThreads);
 SharedDataEdit.Text := IntToStr(GlobalInfo.SharedNumber);
 LocalThreadEdit.Text := IntToStr(LocalThreads);
 end;
end;
 
procedure TGlobalFrm.IncBtnClick(Sender: TObject);
begin
 if Loaded then
 begin
 Procs.IncProc;
 ReadBtnClick(Sender);
 end;
end;
 
procedure TGlobalFrm.DecBtnClick(Sender: TObject);
begin
 if Loaded then
 begin
 Procs.DecProc;
 ReadBtnClick(Sender);
 end;
end;
 
procedure TGlobalFrm.SetBtnClick(Sender: TObject);
 
var
 NewInt: integer;
 
begin
 if Loaded then
 begin
 NewInt := StrToInt(SharedDataEdit.Text);
 Procs.SetProc(NewInt);
 end;
end;
 
procedure TGlobalFrm.CreateThreadClick(Sender: TObject);
 
var
 NewThread: TDelayThread;
 
begin
 NewThread := TDelayThread.Create(true);
 NewThread.FreeOnTerminate := true;
 NewThread.Resume;
end;
 
procedure TGlobalFrm.LoadDLLBtnClick(Sender: TObject);
begin
 if not Loaded then
 begin
 LibHandle := LoadLibrary('GlobalData.dll');
 if LibHandle = INVALID_HANDLE_VALUE then exit;
 with Procs do
 begin
 ReadProc := GetProcAddress(LibHandle, 'ReadInfo');
 IncProc := GetProcAddress(LibHandle, 'IncSharedInteger');
 DecProc := GetProcAddress(LibHandle, 'DecSharedInteger');
 SetProc := GetProcAddress(LibHandle, 'SetSharedInteger');
 if not (Assigned(ReadProc) and Assigned(IncProc) and Assigned(DecProc)
 and Assigned(SetProc)) then
 begin
 FreeLibrary(LibHandle);
 LibHandle := INVALID_HANDLE_VALUE;
 exit;
 end;
 Loaded := true;
 end;
 end;
end;
 
procedure TGlobalFrm.FormCreate(Sender: TObject);
begin
 LibHandle := INVALID_HANDLE_VALUE;
end;
 
procedure TGlobalFrm.FormDestroy(Sender: TObject);
begin
 if LibHandle <> INVALID_HANDLE_VALUE then
 FreeLibrary(LibHandle);
end;
 
end.