TTnScript

From Overbyte
Revision as of 20:30, 17 January 2016 by Stevia (talk | contribs) (→‎Overview)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.