tDolphin and xBrowse fields definition..

tDolphin and xBrowse fields definition..

Postby bosibila » 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: Select all  Expand view
@ 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: Select all  Expand view
   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: Select all  Expand view
#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)
User avatar
bosibila
 
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

Re: tDolphin and xBrowse fields definition..

Postby Daniel Garcia-Gil » Fri Sep 30, 2011 11:43 pm

Hello

Code: Select all  Expand view
  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
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: tDolphin and xBrowse fields definition..

Postby nageswaragunupudi » Sat Oct 01, 2011 3: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
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: tDolphin and xBrowse fields definition..

Postby bosibila » Sat Oct 01, 2011 6: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)
User avatar
bosibila
 
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 102 guests