⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adstmach.pas

📁 Async Professional 4.04
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    procedure CreateParams(var Params: TCreateParams); override;
    procedure PaintWindow(DC : HDC); override;
    procedure Notification(AComponent : TComponent; Operation : TOperation); override;

    procedure DoActivate(NewState : TApdCustomState);
    procedure DoDeactivate;
    procedure DoStateChange(var M: TMessage); message apw_StateChange;
    function GetPaused : Boolean;                                        
    { internal OnPacket event for our Items' data packets }
    {procedure PacketEvent (Sender : TObject;                          } 
    {                       Data  : Pointer;                           } 
    {                       Size  : Integer);                          } 
    {procedure PacketTimeout(Sender: TObject);                         } 
    procedure RenderConnectoid (Connectoid : TApdStateConnectoid;
                                State, DestState : TApdCustomState);
    procedure SetData (NewData : Pointer; NewDataString : string;
                       NewDataSize : Integer);
    procedure SetDataSource (const v : TApdStateCustomDataSource);
    procedure MouseDown (Button : TMouseButton;
                         Shift  : TShiftState;
                         X, Y   : Integer); override;
    procedure WMEraseBackground (var Msg : TWMERASEBKGND);

    property LiveDataSource : TApdStateCustomDataSource
             read GetLiveDataSource write SetDataSource;
  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
    procedure StateMachinePaint;

    { Change state - Called by data source }                             
    procedure ChangeState (ConditionIndex : Integer);                    

    { Pause the state machine }                                          
    procedure Pause;                                                     
    procedure Resume;                                                    

    { starts the state machine }
    procedure Start;

    { cancels the state machine }
    procedure Cancel;

    {the data collected by our packets }
    property Data : Pointer
      read GetData;
    property DataSize : Integer
      read GetDataSize;
    property DataString : string
      read GetDataString;

    property Active : Boolean read FActive default False;                {!!.02}
    property BorderStyle: TBorderStyle
      read FBorderStyle write SetBorderStyle default bsSingle;
    property Canvas : TCanvas
      read FCanvas;

    property Caption : TCaption read FCaption write SetCaption;
    property ConnectoidClickStyle : TAdConnectoidClickStyles
             read FConnectoidClickStyle write SetConnectoidClickStyle
             default [];
    property ComPort : TApdCustomComPort
             read GetComPort write SetComPort;
    property CurrentState : TApdCustomState
      read FCurrentState;
    property DataSource : TApdStateCustomDataSource                      
             read GetDataSource write SetDataSource;                     
    property Paused : Boolean read GetPaused;                            
    property StateNames : TStringList
      read GetStateNames;
    property StartState : TApdCustomState
      read FStartState write SetStartState;
    property TerminalState : TApdCustomState
      read FTerminalState write SetTerminalState;

    property LastErrorCode : Integer
      read FLastErrorCode;
    property MovableStates : Boolean read FMovableStates write SetMovableStates
             default False;
    property OnStateChange : TApdStateMachineStateChangeEvent
      read FOnStateChange write FOnStateChange;
    property OnStateMachineFinish : TApdStateMachineFinishEvent
      read FOnStateMachineFinish write FOnStateMachineFinish;
    property OnConnectoidClick : TApdOnConnectoidClickEvent              
             read FConnectoidClickEvent write FConnectoidClickEvent;     
  end;

  TApdCustomState = class(TApdBaseGraphicControl)
  private
    { Private declarations }
    FActive: Boolean;
    FCompleted : Boolean;
    FGlyph: TBitmap;
    FOutputOnActivate: string;
    FConditions: TApdStateConditions;
    FGlyphCells: Integer;
    FActiveColor: TColor;
    FInactiveColor: TColor;
    FOnStateActivate: TApdStateNotifyEvent;
    FOnStateFinish: TApdStateFinishEvent;
    FCaption: TCaption;
    FMovable : Boolean;
    FOldX : Integer;
    FOldY : Integer;
    FMoving : Boolean;
    FActionState     : Boolean;

    FOnGetData : TApdOnStateGetData;
    FOnGetDataString : TApdOnStateGetDataString;

    procedure SetActiveColor(const NewColor : TColor);
    procedure SetActionState (const v : Boolean);
    procedure SetInactiveColor(const NewColor : TColor);
    procedure SetConditions(const Value: TApdStateConditions);
    procedure SetGlyph(const Value: TBitmap);
    procedure SetGlyphCells(const Value: Integer);
    procedure SetCaption(const Value: TCaption);
    procedure SetMovable (const v : Boolean);

  protected
    { Protected declarations }
    HaveGlyph : Boolean;
    FStateMachine : TApdCustomStateMachine;
    FUseLeftBorder : Boolean;                                            
    FLeftBorderWidth : Integer;                                          
    FLeftBorderFill : TColor;                                            

    procedure Activate; virtual;                                         
    procedure Deactivate; virtual;
    procedure MouseDown (Button : TMouseButton; Shift : TShiftState;
                         X, Y : Integer); override;
    procedure MouseMove (Shift : TShiftState; X, Y : Integer); override;
    procedure MouseUp (Button : TMouseButton; Shift : TShiftState;
                       X, Y : Integer); override;
    procedure Notification(AComponent : TComponent; Operation : TOperation); override;
    procedure SetParent(AParent : TWinControl); override;
    function FindStateMachine : TApdCustomStateMachine;
    procedure WMEraseBackground (var Msg : TWMERASEBKGND);

    property ActionState : Boolean read FActionState write SetActionState;
    property OnGetData : TApdOnStateGetData read FOnGetData write FOnGetData;
    property OnGetDataString : TApdOnStateGetDataString
             read FOnGetDataString write FOnGetDataString;

  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;

    function FindDefaultError : Integer;
    function FindDefaultNext : Integer;

    { other overriden methods }
    procedure Loaded; override;
    procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
    procedure Paint; override;

    { terminate the state }
    procedure Terminate(ErrorCode : Integer); virtual;

    property Caption : TCaption read FCaption write SetCaption;
    { True if we're waiting for a condition, False otherwise }
    property Active : Boolean read FActive;
    { True if we've already been activated and have met our conditions }
    property Completed : Boolean read FCompleted;
    property ActiveColor : TColor
      read FActiveColor write SetActiveColor;
    property InactiveColor : TColor
      read FInactiveColor write SetInactiveColor;

    property Conditions : TApdStateConditions
      read FConditions write SetConditions;

    property Glyph : TBitmap read FGlyph write SetGlyph;
    { GlyphCells is used to show a different 'cell' of the Glyph depending on }
    { the state of the state according to the following. All cells need to be }
    { the same dimensions. When rendering, the width of the rendered image is }
    { obtained by Glyph.Width div GlyphCells }
    {   Cell 1 is the inactive cell }
    {   Cell 2 is the active cell }
    {   Cell 3 is a state that has already been deactivated }
    property GlyphCells : Integer
      read FGlyphCells write SetGlyphCells;

    property Movable : Boolean read FMovable write SetMovable default False;

    property OutputOnActivate : string
      read FOutputOnActivate write FOutputOnActivate;

    property OnStateActivate : TApdStateNotifyEvent
      read FOnStateActivate write FOnStateActivate;
    property OnStateFinish : TApdStateFinishEvent
      read FOnStateFinish write FOnStateFinish;
  end;

  TApdStateMachine = class(TApdCustomStateMachine)
  published
    { our published declarations }
    property Caption;
    property ConnectoidClickStyle;
    property DataSource;
    property ComPort;
    property MovableStates;
    property StartState;
    property TerminalState;

    property OnConnectoidClick;                                          
    property OnStateChange;
    property OnStateMachineFinish;

    { publishing from TScrollingWinControl }
    property Align;
    {$IFDEF Delphi5}
    property Anchors;
    property AutoSize;
    property BevelEdges;
    property BevelInner;
    property BevelOuter;
    property BevelKind;
    property BevelWidth;
    property BiDiMode;
    property Constraints;
    property ParentBiDiMode;
    property OnContextPopup;
    property OnMouseWheel;
    property OnMouseWheelDown;
    property OnMouseWheelUp;
    property OnResize;
    {$ENDIF}
    property Color; 
    property AutoScroll;
    property Ctl3D;
    property Font;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property OnClick;
    property OnDblClick;
    property OnEnter;
    property OnExit;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;       
  end;

  TApdState = class(TApdCustomState)
  published
    { Published declarations }
    property ActiveColor;
    property Caption;
    property Conditions;
    property Font;
    property Glyph;
    property GlyphCells;
    property InactiveColor;
    property Movable;
    property OutputOnActivate;

    property OnGetData;
    property OnGetDataString;
    property OnStateActivate;
    property OnStateFinish;
  end;


implementation

{$IFDEF TRIALRUN}
  {$I TRIAL07.INC}
  {$I TRIAL03.INC}
  {$I TRIAL01.INC}
{$ENDIF}

function SearchDataSource (const C : TComponent) : TApdStateCustomDataSource;
  {-Search for a comport in the same form as TComponent}

  function FindDataSource (const C : TComponent) : TApdStateCustomDataSource;
  var
    I  : Integer;
  begin
    Result := nil;
    if not Assigned(C) then
      Exit;

    {Look through all of the owned components}
    for I := 0 to C.ComponentCount-1 do begin
      if C.Components[I] is TApdStateCustomDataSource then begin
        Result := TApdStateCustomDataSource (C.Components[I]);
        Exit;
      end;

      {If this isn't one, see if it owns other components}
      Result := FindDataSource (C.Components[I]);
    end;
  end;

begin
  {Search the entire form}
  Result := FindDataSource (C);
end;

{ TApdStateCustomDataSource }

constructor TApdStateCustomDataSource.Create (AOwner : TComponent);
begin
  inherited Create (AOwner);
end;

function TApdStateCustomDataSource.GetPaused : Boolean;
begin
  Result := FPauseDepth > 0;
end;

procedure TApdStateCustomDataSource.Notification (AComponent : TComponent;
                                                  Operation  : TOperation);
begin
  inherited Notification (AComponent, Operation);

  if (Operation = opRemove) then begin
    if (AComponent = FStateMachine ) then
      FStateMachine := nil;
  end else if (Operation = opInsert) then begin
    {Check for a com port being installed}
    if not Assigned(FStateMachine) and
       (AComponent is TApdCustomStateMachine) then
      FStateMachine := TApdCustomStateMachine (AComponent);
  end;
end;

procedure TApdStateCustomDataSource.Pause;                               
begin                                                                    
  Inc (FPauseDepth);                                                     
end;                                                                     

procedure TApdStateCustomDataSource.Resume;                              
begin                                                                    
  if FPauseDepth > 0 then                                                
    Dec (FPauseDepth);                                                   
end;                                                                     

function TApdStateCustomDataSource.SearchStateMachine (const C : TComponent) : TApdCustomStateMachine;
{ Search for a state machine in the same form as TComponent }

  function FindStateMachine (const C : TComponent) : TApdCustomStateMachine;
  var

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -