FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour tDolphin and xBrowse fields definition..
Posts: 53
Joined: Wed Aug 06, 2008 05:27 PM
tDolphin and xBrowse fields definition..
Posted: Fri Sep 30, 2011 11:01 PM
Hello everybody,

I start to rewrite my old FWH programs from DBFs to MySql database with tDolphin and I am finish with scaning changes, to have do in source. I am very satisfied with this combination but I have one more thing to solve. I try do define fields on xBrowse/tDolphin query with array with field name, format and header, but without success. Example with xBrowse line below
Code (fw): Select all Collapse
@ 0,0 XBROWSE oBrw OF oWnd FIELDS oData:first, oData:last, oData:city HEADERS "Head 1","Head 2","Head 3" FASTEDIT LINES CELL

working good, but when i try same thing with array of fields I get "{...}" in cell of xBrowse.
Code (fw): Select all Collapse
    aadd( aFields, "oData:first" );    aadd( aHead, "Head 1" );    aadd( aFormat, "" )
   aadd( aFields, "oData:last"  );    aadd( aHead, "Head 2" );    aadd( aFormat, "" )
   aadd( aFields, "oData:city"  );    aadd( aHead, "Head 3" );    aadd( aFormat, "" )

   @ 0,0 XBROWSE oBrw OF oWnd FIELDS aFields HEADERS aHead LINES CELL FASTEDIT


Here is simple example:
Code (fw): Select all Collapse
#include "Fivewin.ch"
#include "tdolphin.ch"
#include "xbrowse.ch"

///////////////////
Function Main()

   local oServer
   local cServer, cUser, cPassword, nPort, cDBName,nFlags
   local oErr,oQry,nFld,oFont,oData
   local oWnd, oBrw
   local aFields:={}, aFormat:={}, aHead:={}, aAlias


   SET DATE german
   SET DELETED ON
   SET EXCLUSIVE OFF
   SET SOFTSEEK ON
   SET WRAP ON
   SET _3DLOOK ON
   SET EPOCH TO YEAR(date()) - 50

   SetHandleCount( 100 )

/* conexion al mysql servidor con tdolphin.lib */

   cServer   := "dolphintest.sitasoft.net"
   cUser     := "test_dolphin"
   cPassword := "123456"
   nPort     := "3306"
   cDBName   := "dolphin_man"
   nFlags    := "0"


   TRY

   CONNECT oServer HOST cServer ;
                      USER cUser ;
                      PASSWORD cPassword ;
                      PORT nPort ;
                      FLAGS nFlags;
                      DATABASE cDBName

                      msgwait( "Connected ...",,1 )
   CATCH oErr
      MsgStop( "Konekcija na bazu nije ostvarena." )
      RETURN NIL
   END


   *
   *
   *
   oServer:Execute( "SET NAMES 'cp1250'" )
   oQry = TDolphinQry():New( "SELECT * FROM customer where 1", oServer )
   oData:=oQry

   *
   *
   *
   DEFINE WINDOW oWnd TITLE "Auto edit browse"

   @ 0,0 XBROWSE oBrw OF oWnd FIELDS oData:first, oData:last, oData:city HEADERS "Head 1","Head 2","Head 3" FASTEDIT LINES CELL


/*
   //-----------------------------------------------------------------------------------------
   *
   *   xBrowse fields definition from array?
   *
   aadd( aFields, "oData:first" );    aadd( aHead, "Head 1" );    aadd( aFormat, "" )
   aadd( aFields, "oData:last"  );    aadd( aHead, "Head 2" );    aadd( aFormat, "" )
   aadd( aFields, "oData:city"  );    aadd( aHead, "Head 3" );    aadd( aFormat, "" )

   @ 0,0 XBROWSE oBrw OF oWnd FIELDS aFields HEADERS aHead LINES CELL FASTEDIT
   //-----------------------------------------------------------------------------------------
*/

   oBrw:SetDolphin( oQry,.f. )

   oBrw:CreateFromCode()
   oWnd:oClient = oBrw

   ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus()

   oQry:End()

return nil


I welcome any idea.

Best regards,
Boris (FWH 20.07, xHarbour 1.2.3, Harbour 3.2.0, BCC74, MySql 5.7)
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: tDolphin and xBrowse fields definition..
Posted: Fri Sep 30, 2011 11:43 PM
Hello

Code (fw): Select all Collapse
   aadd( aFields, "first" );    aadd( aHead, "Head 1" );    aadd( aFormat, "" )
   aadd( aFields, "last"  );    aadd( aHead, "Head 2" );    aadd( aFormat, "" )
   aadd( aFields, "city"  );    aadd( aHead, "Head 3" );    aadd( aFormat, "" )

   @ 0,0 XBROWSE oBrw OF oWnd OBJECT oQry COLUMNS aFields HEADERS aHead LINES CELL FASTEDIT
   //-----------------------------------------------------------------------------------------


   oBrw:CreateFromCode()
   oWnd:oClient = oBrw
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: tDolphin and xBrowse fields definition..
Posted: Sat Oct 01, 2011 03:55 AM

May I suggest even more structured and more readable way of specifying column specs for xbrowse?

Prepare a multi-dimensional array with all column specs. Each row is an array specifying { <fieldname>, [<header>], [<picture>], [<width>], [<align>], [<sortorder>]. Only first column is compulsory and all others are optional.

In the above example,
aCols := { ;
{ "first", "Head-1" }, ;
{ "Last", "Head-2" }, ;
{ "City", "Head-3", "@!", 40 } }

@ 0,0 XBROWSE oBrw OF oWnd COLUMNS aCols DATASOURCE oQry CELL LINES

This code will be clear for us to understand and maintain even after years.
This approach also suits parametrized browses.
In addition we can save the specs to disk and retrieve.

Example:
Memowrit( "specs.txt", FW_ValToExp( aCols ) )
Later
aCols := &( MemoRead( "specs.txt" ) )

Regards



G. N. Rao.

Hyderabad, India
Posts: 53
Joined: Wed Aug 06, 2008 05:27 PM
Re: tDolphin and xBrowse fields definition..
Posted: Sat Oct 01, 2011 06:33 AM

Thanks,

everything is working fine.

Best regards,

Boris (FWH 20.07, xHarbour 1.2.3, Harbour 3.2.0, BCC74, MySql 5.7)

Continue the discussion