unit Testclass;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Forms, Dialogs,
StdCtrls, WinSock,
ActiveX, ComObj, ExtCtrls;
type
TOnChange_Proc =
procedure()
of object;
TMyClass =
class(TObject)
private
FTimer : TTimer;
FStatus, OldStatus : Boolean;
FOnChange : TOnChange_Proc;
// procedure OnChange;
function getAvailable: Boolean;
procedure testTimer(Sender : TObject);
procedure setStatus(value: Boolean);
public
constructor Create;
destructor destroy;
override;
property OnChange_Func : TOnChange_Proc
read FOnChange
write FOnChange;
property Status : Boolean
read FStatus
write setStatus;
property Timer : TTimer
read FTimer
write FTimer;
end;
implementation
constructor TMyClass.Create;
begin
inherited;
FTimer := TTimer.Create(
nil);
FTimer.enabled := false;
FTimer.Interval := 1000;
FTimer.OnTimer := testTimer;
FOnChange :=
nil;
FStatus := true;
OldStatus := true;
end;
destructor TMyClass.Destroy;
begin
FTimer.Free;
inherited;
end;
{procedure TMyClass.OnChange;
begin
if Assigned(FOnChange) then
FOnChange;
end; }
procedure TMyClass.setStatus(value: Boolean);
begin
FStatus := value;
if Assigned(FOnChange)
then
FOnChange;
end;
procedure TMyClass.testTimer(Sender:TObject);
begin
GetAvailable;
// onchange;
end;
function TMyClass.GetAvailable: Boolean;
begin
if FStatus <> OldStatus
then
begin
OldStatus := FStatus;
if Assigned(FOnChange)
then
FOnChange;
end;
end;
end.