WideStudio Logo
WideStudio
Programming Guide
WideStudio Index
Table of contents


The sample of the event procedures for WSCvifield



Executing some event procedures by return key

You can execute the specified procedures in the event procedure. Here, the following sample shows executing the procedure which name is "InputFixed".

(* A sample of WSEV_KEY_HOOK trigger. *)
let cbop obj =
  (* (A)Get the pressed key. *)
  let key = get_int (_WSGIappKeyboard '() -> getKey ()) in
  (* (B)If the key is return.. *)
  if (key = get_int _WSK_Return) then
    (* Execute the procedure which name is "InputFixed". *)
    ignore(obj -> execProcedure ( "InputFixed" ));
  ()
let _ = Callback.register "cbop" cbop

This procedure sometimes is used to execute some procedure on the end of key input.

Clearing the last input string on starting of next input

Here, you create a procedure which clears the last input string on starting of the next. the procedure clears the string the first key input since the input field instance is focused or clicked by the mouse pointer. The clear process is as follows:

(* To contain the last focused input field. *)
let focus_if = C_void

(* A sub-procedure with WSEV_FOCUS_CH *)
let _focus_ch_ obj =
  (* (A) Examine whether the instance is focused. *)
  if ( focus_if <> C_void) &&
     ( get_string (focus_if -> getInstanceName()) <> get_string (obj -> getIsntanceName ()) ) &&
     ( get_int (obj -> getFocus ()) == get_int _False ) then begin
    (* (C)store that the last focused one is. *)
    let focus_if = obj in
    (* (B)It need to clear the string! *)
    (* Set the clear flag True.        *)
    ignore(obj -> setVariantData ("CLEAR TIMING", 1 ));
  end;
  ()
let _ = Callback.register "_focus_ch_" _focus_ch_

(*(2)A sub-procedure with WSEV_MOUSE_PRESS *)
let _btn_press_ obj =
  (* (E) store that the last focused one is. *)
  let focus_if = obj in
  (* (D)  if clicked by the mouse pointer,   *)
  (*  it needs to clear the string!          *)
  (*  Set the clear flag True                *)
  obj -> setVariantData("CLEAR TIMING",1);
  obj -> setProperty("cursorPos",0);
  ()
let _ = Callback.register "_btn_press_" _btn_press_

(* (3)A sub-procedure with WSEV_KEY_PRESS *)
let _key_hook_ obj =
  (* (F) See the clear flag to clear the last input string. *)
  let fl = get_int (obj -> getVariantData("CLEAR TIMING")) in
  if (fl == 1) then begin
    let key = get_int (_WSGIappKeyboard '() -> getKey()) in
    (* (G) Clear the string,if the key is not cursor key. *)
    if (key <> get_int _WSK_Tab &&
        key <> get_int _WSK_Up &&
        key <> get_int _WSK_Down &&
        key <> get_int _WSK_Left &&
        key <> get_int _WSK_Right) then begin
      (* (H)Clear... *)
      ignore(obj -> setProperty("labelString",""));
      (* (I)Set the clear flag False.        *)
      ignore(obj -> setVariantData("CLEAR TIMING",0));
    end;
  end;
  ()
let _ = Callback.register "_key_hook_" _key_hook_

(* The main-procedure.                                             *)
(* (4)Set the input field instance with WSEV_INITIALIZE trigger.   *)
let ifdclr obj =
  (* Setup the sub-procedure(1) with WSEV_FOCUS_CH  *)
  obj -> addProcedure( "ac1", "_focus_ch_", _WSEV_FOCUS_CH);
  (* Setup the sub-procedure(2) with WSEV_MOUSE_PRESS *)
  obj -> addProcedure( "ac2", "_btn_press_", _WSEV_MOUSE_PRESS);
  (* Setup the sub-procedure(3) with WSEV_KEY_HOOK *)
  obj -> addProcedure( "ac3", "_key_hook_", _WSEV_KEY_HOOK);
  ()
let _ = Callback.register "ifdclr" ifdclr

In the focus_ch event procedure, To examine the instance is focused afresh, It uses the static variable which is stored the last focused instance.


Document Release 3.80 for WideStudio ver 3.80, Jan 2005


WideStudio documents index | Table of contents

Copyright(C) WideStudio Development Team, 1999-2005 Last modified: Jan 05, 2005