FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Creating XBrowse from a resource
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Creating XBrowse from a resource
Posted: Thu Feb 20, 2014 06:54 PM
Code (fw): Select all Collapse
oBrw := TXBrowse():new( oDlg ):CreateFromResource( 11 )

All my xbrowses are made with code so I have no experience with creating one from a resource. I note that the above line creates a browse with all fields in the database.

I am wondering how one would just add specified fields? Can anyone provide an example? Do you have to delete all the default fields first, then add only the ones you want?

Nages?

I could not find an example in the \samples directory.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 332
Joined: Thu Nov 17, 2005 09:11 PM
Re: Creating XBrowse from a resource
Posted: Thu Feb 20, 2014 07:04 PM

Hi James,

Lista1 := TXBrowse():New( oDlg )
Lista1:nMarqueeStyle := MARQSTYLE_HIGHLROW
Lista1:CreateFromResource( 109 )

oCol:= Lista1:AddCol()
oCol:bStrData := { || ARQEMP->SIGLA}
oCol:cHeader := "SIGLA"
oCol:= Lista1:AddCol()
oCol:bStrData := { || ARQEMP->FANTASIA}
oCol:cHeader := "FANTASIA"
oCol:= Lista1:AddCol()
oCol:bStrData := { || ARQEMP->UF}
oCol:cHeader := "UF"

...

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Creating XBrowse from a resource
Posted: Thu Feb 20, 2014 07:12 PM

Wanderson,

But calling the CreateFromResource() method has already added all the fields in the database. So when you start adding new columns are they added after all the existing ones? It seems like you have to delete all the existing columns before adding new ones?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Creating XBrowse from a resource
Posted: Thu Feb 20, 2014 07:18 PM
OK, I tried this:

Code (fw): Select all Collapse
   oBrw := TXBrowse():new( oDlg ):CreateFromResource( 11 )
   oCol:= oBrw:AddCol()
   oCol:bStrData := { || cust->LAST}
   oCol:cHeader := "Last"


And I only see the one field. Strange. But, I'm glad it works.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Creating XBrowse from a resource
Posted: Thu Feb 20, 2014 08:19 PM
James

Here is a simple dialog and xBrowse for a single Header and Invoice screen using Ado ( ms access )
Rick Lipkin

Code (fw): Select all Collapse
// BillView.prg
//

#INCLUDE "FIVEWIN.CH"
#Include "xBrowse.Ch"

//----------------------
FUNC _BillView( cMODE,oRsBill,oFontB,oBtn0,oBtn1,oBtn2,oBtn3,oBtn4,oBtn13  )

LOCAL SAYING, oUSERS, lOK, oBmp,oLbxD
LOCAL lOK1,oButt1,oButt2,cTitle

Local dBillDate,nInvoiceNumber,cPublication,cDescription,nAmountDue,nBills,cDetail
Local oBillDate,oInvoiceNumber,oPublication,oDescription,oAmountDue,oBills,oDetail
Local oSay1,oSay2,oSay3,oSay4,oSay5,oSay6,oSay7,oSay8,oSay9

Local oRsBillDetail,cSql,oErr,nRn
Local cAdName,oAdName

Local oDueDate,dDueDate,oTerms,cTerms

IF oRsBill:EOF
   SAYING := "SORRY ... No Billing Information to View"
   MsgInfo( SAYING )
   RETURN(.F.)
ENDIF

cMode := "V"

nRn := oRsBill:Fields("Rn"):Value

oRsBillDetail := TOleAuto():New( "ADODB.Recordset" )
oRsBillDetail:CursorType     := 1        // opendkeyset
oRsBillDetail:CursorLocation := 3        // local cache
oRsBillDetail:LockType       := 3        // lockoportunistic

cSql := "Select * from [BillingDetail] where [Rn] = "+ltrim(str(nRn))
cSql += " Order By [PublicationName],[Week]"

TRY
   oRsBillDetail:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening BillingDetail table" )
   RETURN(.F.)
END TRY

oBtn0:Disable()
oBtn1:Disable()
oBtn2:Disable()
oBtn3:Disable()
oBtn4:Disable()
oBtn13:Disable()


LightGreenGrad()


dBillDate      := If(empty(oRsBill:Fields("BillDate"):Value),Ctod(""),;
                      TtoDate(oRsBill:Fields("BillDate"):Value ))
nInvoiceNumber := If(empty(oRsBill:Fields("InvoiceNumber"):Value),0,;
                           oRsBill:Fields("InvoiceNumber"):Value)
cPublication   := If(empty(oRsBill:Fields("PublicationName"):Value),space(50),;
                           oRsBill:Fields("PublicationName"):Value)
cDescription   := If(empty(oRsBill:Fields("Description"):Value),space(50),;
                           oRsBill:Fields("Description"):Value)
cAdName        := If(empty(oRsBill:Fields("AdName"):Value),space(50),;
                           oRsBill:Fields("AdName"):Value )
nAmountDue     := If(empty(oRsBill:Fields("AmountDue"):Value),0,;
                           oRsBill:Fields("AmountDue"):Value)
nBills         := If(empty(oRsBill:Fields("Bills"):Value),0,;
                           oRsBill:Fields("Bills"):Value)
dDueDate       := If(empty(oRsBill:Fields("DueDate"):Value),Ctod(""),;
                      TtoDate(oRsBill:Fields("DueDate"):Value ))
cTerms         := If(empty(oRsBill:Fields("Terms"):Value),space(15),;
                           oRsBill:Fields("Terms"):Value)


cTITLE := "Billing-Invoicing Information"

DO CASE
CASE cMODE = "A"
     cTITLE := "Billing-Invoicing Information   ADD"
CASE cMODE = "E"
     cTITLE := "Billing-Invoicing Information  EDIT"
CASE cMODE = "V"
     cTITLE := "Billing-Invoicing Information  VIEW"
ENDCASE

lOK := .F.

DEFINE BITMAP oBmp   RESOURCE "BILLVIEW"
DEFINE DIALOG oUSERS RESOURCE "BILLVIEW" ;
       TITLE cTITLE

    REDEFINE SAY oSay1 ID 115 OF oUsers UPDATE   // billdate
             oSay1:SetFont( oFontB )
    REDEFINE SAY oSay2 ID 117 OF oUsers UPDATE   // invoice number
             oSay2:SetFont( oFontB )
    REDEFINE SAY oSay3 ID 119 OF oUsers UPDATE   // publication
             oSay3:SetFont( oFontB )
    REDEFINE SAY oSay4 ID 128 OF oUsers UPDATE   // description
             oSay4:SetFont( oFontB )
    REDEFINE SAY oSay5 ID 113 OF oUsers UPDATE   // ad campaign
             oSay5:SetFont( oFontB )
    REDEFINE SAY oSay6 ID 123 OF oUsers UPDATE   // amount due
             oSay6:SetFont( oFontB )
    REDEFINE SAY oSay7 ID 125 OF oUsers UPDATE   // number bills
             oSay7:SetFont( oFontB )
    REDEFINE SAY oSay8 ID 129 OF oUsers UPDATE   // due date
             oSay8:SetFont( oFontB )
    REDEFINE SAY oSay9 ID 121 OF oUsers UPDATE   // terms
             oSay9:SetFont( oFontB )

    REDEFINE xBROWSE oLbxD           ;
         RECORDSET oRsBillDetail     ;
         COLUMNS "PUBLICATIONNAME",  ;
                 "DESCRIPTION",      ;
                 "TOTALBILLED"       ;
         COLSIZES 160,155,75         ;
         HEADERS "Publication",      ;
                 "Description",      ;
                 "Billed"            ;
         ID 111 of oUsers            ;
         AUTOCOLS LINES CELL

         oLbxD:lRecordSelector := .f.
         oLbxD:lHScroll := .f. // turn off horiz scroll bar

         _BrowColor(oLbxD)

    REDEFINE GET oBillDate      VAR dBillDate      ID 116 of oUSERS COLOR "N/W" READONLY
    REDEFINE GET oDueDate       VAR dDueDate       ID 114 of oUSERS COLOR "N/W" READONLY
    REDEFINE GET oInvoiceNumber VAR nInvoiceNumber ID 118 of oUSERS PICTURE "999999999999" COLOR "N/W" READONLY
    REDEFINE GET oTerms         VAR cTerms         ID 122 of oUSERS COLOR "N/W" READONLY
    REDEFINE GET oPublication   VAR cPublication   ID 120 of oUSERS COLOR "N/W" READONLY
    REDEFINE GET oAdName        VAR cAdName        ID 112 of oUSERS COLOR "N/W" READONLY
    REDEFINE GET oDescription   VAR cDescription   ID 127 of oUSERS COLOR "N/W" READONLY
    REDEFINE GET oAmountDue     VAR nAmountDue     ID 124 of oUSERS PICTURE "99999999.99" COLOR "N/W" READONLY
    REDEFINE GET oBills         VAR nBills         ID 126 of oUSERS PICTURE "9999" COLOR "N/W" READONLY


REDEFINE BTNBMP oButt1 ID 150 of oUSERS   ;     // ok
         RESOURCE "OK", "DOK", "DOK" ;
         PROMPT "  &Ok    " LEFT 2007;
         ACTION (lOK := .T., oUsers:END())

REDEFINE BTNBMP oButt2 ID 160 of oUSERS   ;    // cancel
         RESOURCE "CANCEL", "DCANCEL", "DCANCEL" ;
         PROMPT "&Cancel   " LEFT 2007;
         ACTION ( lOk := .f., oUSERS:END())

ACTIVATE DIALOG oUSERS ;
         ON INIT (oLbxD:SetFocus() );
         ON PAINT (PalBmpDraw( hDC, 0, 0, oBmp:hBitmap ))

oRsBillDetail:CLose()
oRsBillDetail := nil

LightGreyGrad()

oBmp:End()

oBtn0:Enable()
oBtn1:Enable()
oBtn2:Enable()
oBtn3:Enable()
oBtn4:Enable()
oBtn13:Enable()

RETURN(.t. )

//--------------
Static Func LightGreenGrad()

SetDlgGradient( { { .50, nRGB(210,235,216), nRGB( 255, 255, 255 ) } } )

Return(nil)

//------------------
Static Func LightGreyGrad()

SetDlgGradient( { { .50, nRGB( 216, 216, 216 ), nRGB( 255, 255, 255 ) } } )

Return(nil)

//-------------------
Static Func _BrowColor( oLbx )
                               // foreground      // background
local aGradBarSelFocus := {{1, RGB(0,128,255) , RGB(0,128,255) }}   // in focus
local aGradBarSel      := {{1, RGB(255,255,255), RGB(192,192,192)  }}   // not in focus   192

WITH OBJECT oLbx
       :bClrSel       := {|| { CLR_BLACK, aGradBarSel } }  // not in focus
       :bClrSelFocus := { || { CLR_WHITE, aGradBarSelFocus } }     // in focus
END

Return(nil)


// end BillView.prg


.Rc
Code (fw): Select all Collapse
BILLVIEW DIALOG 383, 47, 292, 322
STYLE WS_POPUP | WS_CAPTION
FONT 6, "MS Sans Serif"
{
 EDITTEXT 116, 103, 23, 54, 12
 EDITTEXT 118, 103, 37, 54, 12, ES_RIGHT | WS_BORDER | WS_TABSTOP
 EDITTEXT 120, 103, 65, 177, 12
 EDITTEXT 112, 103, 51, 177, 12
 EDITTEXT 127, 103, 79, 177, 12
 EDITTEXT 124, 79, 287, 54, 12, ES_RIGHT | WS_BORDER | WS_TABSTOP
 EDITTEXT 126, 79, 301, 54, 12, ES_RIGHT | WS_BORDER | WS_TABSTOP
 CONTROL "&Ok", 150, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 191, 288, 41, 25
 CONTROL "&Cancel", 160, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 236, 288, 41, 25
 LTEXT "Invoice Number", 117, 10, 37, 88, 12, SS_NOPREFIX | WS_GROUP
 LTEXT "Bill Date", 115, 10, 23, 88, 12, SS_NOPREFIX | WS_GROUP
 LTEXT "Publication ", 119, 10, 66, 88, 12, SS_NOPREFIX | WS_GROUP
 LTEXT "Number Bills", 125, 10, 301, 62, 12, SS_NOPREFIX | WS_GROUP
 LTEXT "Amount Due", 123, 10, 287, 62, 12, SS_NOPREFIX | WS_GROUP
 LTEXT "Description", 128, 10, 80, 88, 12, SS_NOPREFIX | WS_GROUP
 CONTROL "", 111, "TXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 7, 97, 279, 182
 LTEXT "Ad Campaign Name", 113, 10, 52, 88, 12, SS_NOPREFIX | WS_GROUP
 EDITTEXT 114, 218, 23, 62, 12
 LTEXT "Terms", 121, 169, 37, 48, 12, SS_NOPREFIX | WS_GROUP
 EDITTEXT 122, 218, 37, 62, 12
 LTEXT "Due Date", 129, 169, 23, 48, 12, SS_NOPREFIX | WS_GROUP
}
[URL=https://imageshack.com/i/j7ef08j]<img src="http://imagizer.imageshack.us/v2/xq90/691/ef08.jpg" alt="" loading="lazy">[/URL]
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
Re: Creating XBrowse from a resource
Posted: Thu Feb 20, 2014 09:04 PM

James

Xbrowse has a very powerful feature with the column syntax

this is a sample

REDEFINE XBROWSE oBrw ID 201 OF ODLG ;
COLUMNS "CLI","NOM","RUE","POSTAL","VILLE","TEL","TEL2","TEL3","NOMFAC","EMAIL" ;
HEADERS " ","Nom","Adresse","Code" + CRLF + "Postal","Ville","Téléphone","Fax","Mobile","Nom" + CRLF + "Facturation","@E-Mail" ;
COLORS {|| { CLR_BLUE, CLR_WHITE } } ;
FONT AFONT ;
ALIAS "CLI" AUTOSORT

I highly suggest you go this direction

Richard

http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Creating XBrowse from a resource
Posted: Thu Feb 20, 2014 10:23 PM

Rick and Richard,

I had used my global search looking for "REDEFINE XBROWSE" and it turned up nothing. Thus I assumed it didn't exist. After your posts I manually searched xbrowse.ch and found this:

xcommand REDEFINE [ COLUMN ] XBROWSE <oBrw> [<clauses,...>] ID <nID> [<moreClauses,...>] ;

  =&gt; @ 0,0 XBROWSE &lt;oBrw&gt; [&lt;clauses&gt;] ID &lt;nID&gt; [&lt;moreClauses&gt;]

Of course my automatic search wasn't successful because of the [ COLUMN ] option (actually, I'm not sure what that means).

Thanks for showing me the REDEFINE examples.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Creating XBrowse from a resource
Posted: Thu Feb 20, 2014 11:46 PM
James,

James Bott wrote:Of course my automatic search wasn't successful because of the [ COLUMN ] option (actually, I'm not sure what that means).


Nothing. It only means that you can use

Code (fw): Select all Collapse
REDEFINE XBROWSE


or

Code (fw): Select all Collapse
REDEFINE COLUMN XBROWSE


EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Creating XBrowse from a resource
Posted: Fri Feb 21, 2014 12:38 AM

Enrico,

Thanks for the clarification. I notice that the COLUMN syntax is also in the TCBrowse.ch. I have never seen the COLUMN syntax used before.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Creating XBrowse from a resource
Posted: Fri Feb 21, 2014 09:33 AM
James,

James Bott wrote:I have never seen the COLUMN syntax used before.


Me neither.

EMG
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Creating XBrowse from a resource
Posted: Fri Feb 21, 2014 01:40 PM
James

Here is the .ppo of the xBrowse in my above sample ..

Rick Lipkin
Code (fw): Select all Collapse
 oLbxD := XbrowseNew( oUsers, 0, 0,,,, {"Publication",       "Description",       "Billed"}, {160,155,75},,,,,,,,, .F., oRsBillDetail,, .F.,, .F., 111, .F., .T. ,, {"PUBLICATIONNAME",   "DESCRIPTION",       "TOTALBILLED"},,, .F., .F., .T., .T.,,,,, .F., .F. )

         oLbxD:lRecordSelector := .F.
         oLbxD:lHScroll := .F.

         _BrowColor(oLbxD)
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Creating XBrowse from a resource
Posted: Fri Feb 21, 2014 02:52 PM
Rick,

This is how REDEFINE XBROWSE is processed in xbrowse.ch.

Code (fw): Select all Collapse
#xcommand REDEFINE [ COLUMN ] XBROWSE  <oBrw> [<clauses,...>] ID <nID> [<moreClauses,...>] ;
      => @ 0,0 XBROWSE <oBrw> [<clauses>] ID <nID> [<moreClauses>]


It appears that it is just changing it to:

@ 0,0 XBROWSE...ID

Then it is handled just the same as if you coded it this way in the first place:

@ 0,0 XBROWSE...

Then the class object is initialized by calling a function ( xbrowsenew() ) rather than the class' New() method. Very strange. I wonder why?

Thanks for pointing this out.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Creating XBrowse from a resource
Posted: Fri Feb 21, 2014 03:38 PM
James,

James Bott wrote:This is how REDEFINE XBROWSE is processed in xbrowse.ch.

Code (fw): Select all Collapse
#xcommand REDEFINE [ COLUMN ] XBROWSE  <oBrw> [<clauses,...>] ID <nID> [<moreClauses,...>] ;
      => @ 0,0 XBROWSE <oBrw> [<clauses>] ID <nID> [<moreClauses>]


It appears that it is just changing it to:

@ 0,0 XBROWSE...ID

Then it is handled just the same as if you coded it this way in the first place:

@ 0,0 XBROWSE...

Then the class object is initialized by calling a function ( xbrowsenew() ) rather than the class' New() method. Very strange. I wonder why?


No. It just means that @ 0,0 XBROWSE is in turn preprocessed to xbrowsenew(). :-)

EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Creating XBrowse from a resource
Posted: Fri Feb 21, 2014 05:21 PM
Enrico,

No. It just means that @ 0,0 XBROWSE is in turn preprocessed to xbrowsenew().

Maybe I'm missing something? My point is that the class' New() method is not being called directly but rather through a function. This makes subclassing difficult if not impossible.

Also I see this line in the xbrowsenew() function.
Code (fw): Select all Collapse
  oBrw        := TXBrows():New( oWnd )

Isn't this missing an "e"? Shouldn't it be:
Code (fw): Select all Collapse
  oBrw        := TXBrowse():New( oWnd )

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Creating XBrowse from a resource
Posted: Fri Feb 21, 2014 06:24 PM
James,

James Bott wrote:Maybe I'm missing something? My point is that the class' New() method is not being called directly but rather through a function.


REDEFINE commands are normally preprocessed to Redefine() method not New() method. Anyway, I agree that there is something unusual inside TXBrowse. :-)

EMG

Continue the discussion