Example for OHIO in Delphi

Top  Previous  Next

unit TestX;

 

interface

 

uses

 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

 Dialogs, zOHIO_TLB, StdCtrls, StrUtils, ComCtrls,

 Mask, ExtCtrls,uTnbHllOhioConsts;

 

type

 TForm1 = class(TForm)

   Memo1 : TMemo;

   Button1 : TButton;

   Button2 : TButton;

   Button3 : TButton;

   Label1: TLabel;

   Label2: TLabel;

   Edit2: TEdit;

   Button4: TButton;

   Button5: TButton;

   MaskEdit1: TMaskEdit;

   Button6: TButton;

   Bevel1: TBevel;

   Label3: TLabel;

   MaskEdit2: TMaskEdit;

   Bevel3: TBevel;

   Label4: TLabel;

   ComboBox1: TComboBox;

   Button7: TButton;

   Button8: TButton;

   Button9: TButton;

   Label5: TLabel;

   ComboBox2: TComboBox;

   Bevel2: TBevel;

   Button10: TButton;

   procedure FormDestroy(Sender : TObject);

   procedure Button1Click(Sender: TObject);

   procedure Button2Click(Sender: TObject);

   procedure Button3Click(Sender: TObject);

   procedure Button4Click(Sender: TObject);

   procedure Button6Click(Sender: TObject);

   procedure Button5Click(Sender: TObject);

   procedure Button7Click(Sender: TObject);

   procedure Button8Click(Sender: TObject);

   procedure Button9Click(Sender: TObject);

   procedure Button10Click(Sender: TObject);

 private

   { Private declarations }

   fOhioManager : IOHIOManager;

   procedure RefreshSessionsCombo;

   procedure ScreenChangeEvent(Sender : TObject; const session: IOHIOSession);

   procedure SessionStateEvent(Sender : TObject; const session: IOHIOSession);

   procedure SessionLockEvent(Sender : TObject; const session: IOHIOSession);

   procedure SessionUnlockEvent(Sender : TObject; const session: IOHIOSession);

 public

   { Public declarations }

 end;

 

var

 Form1 : TForm1;

 

implementation

 

{$R *.dfm}

 

procedure TForm1.Button10Click(Sender: TObject);

begin

 if not fOhioManager.Sessions.Item[ComboBox2.Text].Screen.WaitForNewScreen(10000) then

   ShowMessage('TIMEOUT: Wait for New Screen');

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var OhioMgr : TOHIOManager;

begin

 Button1.Enabled := FALSE;

 ComboBox1.ItemIndex := 0;

 try

   OhioMgr := TOHIOManager.Create(Self);

   OhioMgr.OpenSession('','A');

   OhioMgr.OpenSession('','B');

   OhioMgr.OnScreenChange := ScreenChangeEvent;

   OhioMgr.OnSessionState := SessionStateEvent;

   OhioMgr.OnSystemLock := SessionLockEvent;

   OhioMgr.OnSystemUnLock := SessionUnlockEvent;

   FOhioManager:=OhioMgr.ControlInterface as IOHIOManager;

   Button2.Enabled := TRUE;

   Button3.Enabled := TRUE;

   Button4.Enabled := TRUE;

   Button5.Enabled := TRUE;

   Button6.Enabled := TRUE;

   Button7.Enabled := TRUE;

   Button8.Enabled := TRUE;

   Button9.Enabled := TRUE;

   Button10.Enabled := TRUE;

   Memo1.Enabled := TRUE;

   Edit2.Enabled := TRUE;

   MaskEdit1.Enabled := TRUE;

   MaskEdit2.Enabled := TRUE;

   ComboBox1.Enabled := TRUE;

   ComboBox2.Enabled := TRUE;

   Memo1.Clear;

   Edit2.Clear;

   MaskEdit1.Text := '0';

   MaskEdit2.Text := '0';

 except

   on E : Exception do

   begin

     Memo1.Lines.Add('ERROR: ' + E.Message);

     Button1.Enabled := TRUE;

     Button2.Enabled := FALSE;

     Button3.Enabled := FALSE;

     Button4.Enabled := FALSE;

     Button5.Enabled := FALSE;

     Button6.Enabled := FALSE;

     Button7.Enabled := FALSE;

     Button8.Enabled := FALSE;

     Button9.Enabled := FALSE;

     Button10.Enabled := FALSE;

     Memo1.Enabled := FALSE;

     Edit2.Enabled := FALSE;

     MaskEdit1.Enabled := FALSE;

     MaskEdit2.Enabled := FALSE;

     ComboBox1.Enabled := FALSE;

     ComboBox2.Enabled := FALSE;

     if Assigned(fOhioManager) then

       FreeAndNil(fOhioManager);

     Exit;

   end;

 end;

 RefreshSessionsCombo;

end;

 

procedure TForm1.Button2Click(Sender: TObject);

var

 FieldIdx : integer;

 SessionType : string;

begin

 Memo1.Clear;

 Memo1.Lines.Add('Session Name: ' + fOhioManager.Sessions.Item[ComboBox2.Text].SessionName);

 if (fOhioManager.Sessions.Item[ComboBox2.Text].SessionType = OHIO_TYPE_3270) then

   SessionType := '3270'

 else if (fOhioManager.Sessions.Item[ComboBox2.Text].SessionType = OHIO_TYPE_5250) then

   SessionType := '5250'

 else

   SessionType := 'VT';

 Memo1.Lines.Add('Session Type: ' + SessionType);

 Memo1.Lines.Add('Rows: ' + IntToStr(fOhioManager.Sessions.Item[ComboBox2.Text].Screen.Rows));

 Memo1.Lines.Add('Cols: ' + IntToStr(fOhioManager.Sessions.Item[ComboBox2.Text].Screen.Columns));

 Memo1.Lines.Add('Fields: ' + IntToStr(fOhioManager.Sessions.Item[ComboBox2.Text].Screen.Fields.Count));

 with fOhioManager.Sessions.Item[ComboBox2.Text] do

 begin

   for FieldIdx := 0 to (Screen.Fields.Count - 1) do

   begin

     Memo1.Lines.Add('   Field Nº: ' + IntToStr(FieldIdx));

     Memo1.Lines.Add('      Start Row: ' + IntToStr(Screen.Fields.Item[FieldIdx].StartObj.Row));

     Memo1.Lines.Add('      Start Col: ' + IntToStr(Screen.Fields.Item[FieldIdx].StartObj.Col));

     Memo1.Lines.Add('      End Row: ' + IntToStr(Screen.Fields.Item[FieldIdx].EndObj.Row));

     Memo1.Lines.Add('      End Col: ' + IntToStr(Screen.Fields.Item[FieldIdx].EndObj.Col));

     Memo1.Lines.Add('      Length: ' + IntToStr(Screen.Fields.Item[FieldIdx].Length));

     Memo1.Lines.Add('      Data: ' + Screen.Fields.Item[FieldIdx].String_);

     Memo1.Lines.Add('      Attributes:');

     Memo1.Lines.Add('         Modified: ' + IfThen(Screen.Fields.Item[FieldIdx].Modified,'Yes','No'));

     Memo1.Lines.Add('         Protected: ' + IfThen(Screen.Fields.Item[FieldIdx].Protected_,'Yes','No'));

     Memo1.Lines.Add('         Numeric: ' + IfThen(Screen.Fields.Item[FieldIdx].Numeric,'Yes','No'));

     Memo1.Lines.Add('         HighIntensity: ' + IfThen(Screen.Fields.Item[FieldIdx].HighIntensity,'Yes','No'));

     Memo1.Lines.Add('         PenSelectable: ' + IfThen(Screen.Fields.Item[FieldIdx].PenSelectable,'Yes','No'));

     Memo1.Lines.Add('         Hidden: ' + IfThen(Screen.Fields.Item[FieldIdx].Hidden,'Yes','No'));

     Memo1.Lines.Add('----------------------------------------------------------------------');

   end;

   Application.ProcessMessages;

 end;

end;

 

procedure TForm1.Button3Click(Sender: TObject);

begin

 fOhioManager.Sessions.Item[ComboBox2.Text].Screen.SendKeys(Edit2.Text,StrToInt(MaskEdit2.Text));

end;

 

procedure TForm1.Button4Click(Sender: TObject);

begin

 try

   fOhioManager.Sessions.Item[ComboBox2.Text].Screen.Fields.Item[StrToInt(MaskEdit1.Text)].String_ := Edit2.Text;

 except

   on E:Exception do

     ShowMessage(E.Message);

 end;

end;

 

procedure TForm1.Button5Click(Sender: TObject);

begin

 try

   fOhioManager.Sessions.Item[ComboBox2.Text].Screen.SetString(Edit2.Text,StrToInt(MaskEdit2.Text));

 except

   on E:Exception do

     ShowMessage(E.Message);

 end;

end;

 

procedure TForm1.Button6Click(Sender: TObject);

begin

 try

   Edit2.Text := fOhioManager.Sessions.Item[ComboBox2.Text].Screen.Fields.Item[StrToInt(MaskEdit1.Text)].String_;

 except

   on E:Exception do

     ShowMessage(E.Message);

 end;

end;

 

procedure TForm1.Button7Click(Sender: TObject);

begin

 try

   fOhioManager.Sessions.Item[ComboBox2.Text].Screen.SendAid(ConvertStrAidToIntAid(ComboBox1.Text));

 except

   on E:Exception do

     ShowMessage(E.Message);

 end;

end;

 

procedure TForm1.Button8Click(Sender: TObject);

begin

 Button1.Enabled := TRUE;

 Button2.Enabled := FALSE;

 Button3.Enabled := FALSE;

 Button4.Enabled := FALSE;

 Button5.Enabled := FALSE;

 Button6.Enabled := FALSE;

 Button7.Enabled := FALSE;

 Button8.Enabled := FALSE;

 Button8.Enabled := FALSE;

 Button9.Enabled := FALSE;

 Button10.Enabled := FALSE;

 Memo1.Enabled := FALSE;

 Edit2.Enabled := FALSE;

 MaskEdit1.Enabled := FALSE;

 MaskEdit2.Enabled := FALSE;

 ComboBox1.Enabled := FALSE;

 ComboBox2.Enabled := FALSE;

 Memo1.Clear;

 Edit2.Clear;

 MaskEdit1.Text := '0';

 MaskEdit2.Text := '0';

 ComboBox2.Clear;

 if Assigned(fOhioManager) then

   fOhioManager:=nil;

end;

 

procedure TForm1.Button9Click(Sender: TObject);

begin

 if Assigned(fOhioManager) then

 begin

   try

     fOhioManager.Sessions.Refresh;

     RefreshSessionsCombo;

   except

     Button8Click(Button8);

   end;

 end;

end;

 

procedure TForm1.FormDestroy(Sender : TObject);

begin

 Button8Click(Button8);

end;

 

procedure TForm1.RefreshSessionsCombo;

var

 i : integer;

begin

 ComboBox2.Clear;

 for i := 0 to (fOhioManager.Sessions.Count - 1) do

   ComboBox2.Items.Add(fOhioManager.Sessions.Item[i].SessionName);

 ComboBox2.ItemIndex := 0;

end;

 

procedure TForm1.ScreenChangeEvent(Sender: TObject; const session: IOHIOSession);

begin

 Memo1.Lines.Add('------------------------------------------------------------------');

 Memo1.Lines.Add('|   Session "' + session.SessionName + '" Screen has changed   |');

 Memo1.Lines.Add('------------------------------------------------------------------');

end;

 

procedure TForm1.SessionStateEvent(Sender: TObject; const session: IOHIOSession);

begin

 Memo1.Lines.Add('------------------------------------------------------------------');

 Memo1.Lines.Add('|   Session "' + session.SessionName + '" State has changed   |');

 Memo1.Lines.Add('------------------------------------------------------------------');

end;

 

procedure TForm1.SessionLockEvent(Sender: TObject; const session: IOHIOSession);

begin

 Memo1.Lines.Add('-----------------------------------------------------');

 Memo1.Lines.Add('|   Session "' + session.SessionName + '" Lock   |');

 Memo1.Lines.Add('-----------------------------------------------------');

end;

 

procedure TForm1.SessionUnlockEvent(Sender: TObject; const session: IOHIOSession);

begin

 Memo1.Lines.Add('-----------------------------------------------------');

 Memo1.Lines.Add('|   Session "' + session.SessionName + '" Unlock   |');

 Memo1.Lines.Add('-----------------------------------------------------');

end;

 

end.