Vulcan.NET Code Examples

For a screen shot of the code below running, please click here.

Vulcan.NET  Database View using VulcanDB
REFERENCES "VulcanDB"
REFERENCES "System.Drawing"
REFERENCES "System.Windows.Forms"

USING       System.Windows.Forms
USING       System.Drawing

USING       VulcanDB

CLASS DBWin INHERIT System.Windows.Forms.Form
   PROTECT aTextControls AS ARRAY
   PROTECT server AS DBFRdd

CONSTRUCTOR() CLASS DBWin
   Super()
   SELF:InitialiseForm()
   RETURN

METHOD AddTextControl(oControl AS Control) AS VOID CLASS DBWin
   SELF:Controls:Add(oControl)
   AAdd(SELF:aTextControls,oControl)
   RETURN

METHOD Configure() AS VOID CLASS DBWin
   LOCAL nCount AS DWORD
   LOCAL oControl AS TextBox
   LOCAL oButton AS Button
   LOCAL nTopPosition AS DWORD

   LOCAL i AS DWORD

   oButton := System.Windows.Forms.Button{}
   oButton:Location := System.Drawing.Point{300,25}
   oButton:Size := System.Drawing.Size{72,24}
   oButton:Text := "&Previous"
   oButton:Click += System.EventHandler{ SELF,@DBWin.PreviousClick }
   SELF:Controls:Add(oButton)

   oButton := System.Windows.Forms.Button{}
   oButton:Location := System.Drawing.Point{300,50}
   oButton:Size := System.Drawing.Size{72,24}
   oButton:Text := "&Next"
   oButton:Click += System.EventHandler{ SELF,@DBWin.NextClick }
   SELF:Controls:Add(oButton)

   nCount := SELF:server:FieldCount
   SELF:aTextControls := {}

   nTopPosition := 20U
   FOR i := 1U UPTO nCount
      oControl := TextBox{}
      oControl:Size := System.Drawing.Size{200,22}
      oControl:Location := Point{50,(INT)nTopPosition+(i-1)*25}
      oControl:ReadOnly := TRUE
      SELF:AddTextControl(oControl)
   NEXT

   SELF:Size := System.Drawing.Size{400,90+nCount*25}

   RETURN

METHOD FillForm() AS VOID CLASS DBWin
   LOCAL nCount AS DWORD
   LOCAL oControl AS Control
   LOCAL i AS DWORD

   nCount := (DWORD)ALen(SELF:aTextControls)

   FOR i := 1U UPTO nCount
      oControl := (Control)SELF:aTextControls[i]
      oControl:Text := SELF:Server:FieldGet(i):ToString()
   NEXT

   RETURN

METHOD InitialiseForm() AS VOID CLASS DBWin
   SELF:Location := System.Drawing.Point{100,100}
   SELF:Size := System.Drawing.Size{400,100}
   SELF:Text := "DBF Demo"
   RETURN

METHOD NextClick(oControl AS OBJECT , e AS System.EventArgs) AS VOID CLASS DBWin
   SELF:server:Skip(1)
   IF ! SELF:server:Eof
      SELF:FillForm()
   ELSE
      MessageBox(0,"End of file","DBF Demo",0U)
      SELF:server:GoBottom()
   ENDIF

   RETURN

METHOD PreviousClick(oControl AS OBJECT , e AS System.EventArgs) AS VOID CLASS DBWin
   SELF:server:Skip(-1)
   IF ! SELF:server:Bof
      SELF:FillForm()
   ELSE
      MessageBox(0,"Beginning of file","DBF Demo",0U)
   ENDIF

   RETURN

METHOD Use(oDBF AS DBFRdd) AS VOID CLASS DBWin
  SELF:server := oDBF
  SELF:Configure()
  SELF:FillForm()
  RETURN

FUNCTION IndexKeyCallback( db AS DBFRDD, expr AS STRING ) AS OBJECT
   LOCAL o AS OBJECT

   IF String.Compare( expr, "state + city", TRUE ) == 0
      o := db:FieldGetString( "state" ) + db:FieldGetString( "city" )
   ELSE   
      // all the other indexes are simple field names
      o := db:FieldGet( expr )
   ENDIF

   RETURN o

_DLL FUNCTION MessageBox( hWnd AS INT, Text AS STRING, caption AS STRING, type AS DWORD ) AS INT PASCAL:User32.dll.MessageBox

FUNCTION Start AS VOID
   LOCAL o AS DBWin
   LOCAL db AS DBFRdd
   LOCAL eh AS VulcanDB.EvalIndexKeyEventHandler  

   System.Windows.Forms.Application.EnableVisualStyles()

   db := DBFRdd{}

   // This has to be present or the DBF will not open without error
   eh := EvalIndexKeyEventHandler{ NULL, @IndexKeyCallback }
   db:OnEvalIndexKey += eh  

   db:Open("customer2.dbf")

   o := DBWin{}
   o:Use(db)

   Application.Run(o)

   db:Close()

   RETURN