Difference between revisions of "TTnScript"

From Overbyte
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Overview ==
 
== Overview ==
 
*'''unit''' OverbyteIcsTnScript.pas
 
*'''unit''' OverbyteIcsTnScript.pas
*'''inheritance''' TTnEmulVT - TComponent
+
*'''inheritance''' TCustomControl -> TCustomEmulVT -> TEmulVT -> TTnEmulVT -> TTnScript
  
The TTnScript is a descendant of TTnEmulVT that encapsulates searching through received data for a search strings, automatically replying a given string (optional) and triggering an event handler (optional) when a search string is encountered. It links into TTnEmulVT via the TriggerDataAvailable virtual method to get data received and if it has search strings to test for, calls processinputdata.
+
The TTnScript is a descendant of TTnEmulVT that encapsulates searching through received data for a search strings, automatically replying a given string (optional) and triggering an event handler (optional) when a search string is encountered.
  
 
== Properties ==
 
== Properties ==
  
 
{|  
 
{|  
| width="90" valign="top" | [[TTnScript.InputBufferSize| InputBufferSize]] |||| Size of buffer to use for internal scanning, must be twice as long as longest search string.
+
| valign="top" | [[TTnScript.InputBufferSize| InputBufferSize: Integer]] |||| Size of buffer to use for internal scanning, must be twice as long as longest search string.
 
|-  
 
|-  
| valign="top" | [[TTnScript.OnDisplay| OnDisplay]] |||| When a search string is found, this event handler is triggered. Parameter is displayable text string.
+
| valign="top" | [[TTnScript.OnDisplay| OnDisplay: TDisplayEvent]] |||| When a search string is found, this event handler is triggered.
 
|-  
 
|-  
| valign="top" | [[TTnScript.OnStringMatch| OnStringMatch]] |||| When a search string is found, this event handler is triggered. Parameter is ID of search string.
+
| valign="top" | [[TTnScript.OnStringMatch| OnStringMatch: TStringMatch]] |||| When a search string is found, this event handler is triggered.
 
|}
 
|}
  
Line 25: Line 25:
  
 
== Support Types ==
 
== Support Types ==
 +
TEventFlag    = (efIgnoreCase, efPersistent); { Ignore case in comparisons / Do not delete event when found }
 
  TEventHandler = procedure (Sender : TObject; ID : Integer) of object;
 
  TEventHandler = procedure (Sender : TObject; ID : Integer) of object;
TEventFlag    = (efIgnoreCase, efPersistent); { Ignore case in comparisons / Do not delete event when found }
 
 
  TDisplayEvent = procedure (Sender : TObject; Msg : String) of object;
 
  TDisplayEvent = procedure (Sender : TObject; Msg : String) of object;
 
  TStringMatch  = procedure (Sender : TObject; ID : Integer) of object;
 
  TStringMatch  = procedure (Sender : TObject; ID : Integer) of object;

Latest revision as of 20:30, 17 January 2016

Overview

  • unit OverbyteIcsTnScript.pas
  • inheritance TCustomControl -> TCustomEmulVT -> TEmulVT -> TTnEmulVT -> TTnScript

The TTnScript is a descendant of TTnEmulVT that encapsulates searching through received data for a search strings, automatically replying a given string (optional) and triggering an event handler (optional) when a search string is encountered.

Properties

InputBufferSize: Integer Size of buffer to use for internal scanning, must be twice as long as longest search string.
OnDisplay: TDisplayEvent When a search string is found, this event handler is triggered.
OnStringMatch: TStringMatch When a search string is found, this event handler is triggered.

Methods

procedure AddEvent(ID: Integer; Search: String; ToSend: String; Flags: TEventFlags; Handler: TEventHandler); Allows adding an event to search for.
procedure RemoveEvent(ID : Integer) Removes an event in the search list.
procedure RemoveAllEvents Removes all events in the search list.

Support Types

TEventFlag    = (efIgnoreCase, efPersistent); { Ignore case in comparisons / Do not delete event when found }
TEventHandler = procedure (Sender : TObject; ID : Integer) of object;
TDisplayEvent = procedure (Sender : TObject; Msg : String) of object;
TStringMatch  = procedure (Sender : TObject; ID : Integer) of object;

How it works

The class overrides TriggerDataAvailable, where it calls its internal ProcessInputData virtual procedure if there are any search strings set up. The current search algorithm (Revision 1264) searches the received buffer for each event given in the sequence received, so although for the automatic login example below it can receive both 'login' and 'password' in one call from TriggerDataAvailable, it will search for 'login' first, then 'password' and so the events will trigger in the correct sequence.

How To

Automatic login

A simple automatic login procedure could look like this:

   TnScript1.AddEvent(1, 'login',    'root' + #13#10, [efIgnoreCase], nil);
   TnScript1.AddEvent(2, 'password', 'boss' + #13#10, [efIgnoreCase], nil);
   TnScript1.Connect;

After the events trigger, they will be removed from the list of strings to search for, unless you include the efPersistent event flag.