Difference between revisions of "TTnScript"

From Overbyte
Jump to navigation Jump to search
 
(8 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 ==
 +
 +
{|
 +
| 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: TDisplayEvent]] |||| When a search string is found, this event handler is triggered.
 +
|-
 +
| valign="top" | [[TTnScript.OnStringMatch| OnStringMatch: TStringMatch]] |||| When a search string is found, this event handler is triggered.
 +
|}
  
 
== Methods ==
 
== Methods ==
 +
{|
 +
|  | [[TTnScript.AddEvent | procedure AddEvent(ID: Integer; Search: String; ToSend: String; Flags: TEventFlags; Handler: TEventHandler);]] |||| Allows adding an event to search for.
 +
|-
 +
| valign="top" | [[TTnScript.RemoveEvent | procedure RemoveEvent(ID : Integer)]] |||| Removes an event in the search list.
 +
|-
 +
| valign="top" | [[TTnScript.RemoveAllEvents | 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.

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.