Creating XBrowse from a resource

Creating XBrowse from a resource

Postby James Bott » Thu Feb 20, 2014 6:54 pm

Code: Select all  Expand view
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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Creating XBrowse from a resource

Postby Wanderson » Thu Feb 20, 2014 7: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"

...
Wanderson
 
Posts: 332
Joined: Thu Nov 17, 2005 9:11 pm

Re: Creating XBrowse from a resource

Postby James Bott » Thu Feb 20, 2014 7: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Creating XBrowse from a resource

Postby James Bott » Thu Feb 20, 2014 7:18 pm

OK, I tried this:

Code: Select all  Expand view
  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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Creating XBrowse from a resource

Postby Rick Lipkin » Thu Feb 20, 2014 8:19 pm

James

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

Code: Select all  Expand view

// 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: Select all  Expand view

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]Image[/URL]
 
User avatar
Rick Lipkin
 
Posts: 2636
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Creating XBrowse from a resource

Postby Richard Chidiak » Thu Feb 20, 2014 9: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
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: Creating XBrowse from a resource

Postby James Bott » 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,...>] ;
=> @ 0,0 XBROWSE <oBrw> [<clauses>] ID <nID> [<moreClauses>]

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Creating XBrowse from a resource

Postby Enrico Maria Giordano » 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: Select all  Expand view
REDEFINE XBROWSE


or

Code: Select all  Expand view
REDEFINE COLUMN XBROWSE


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8381
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Creating XBrowse from a resource

Postby James Bott » 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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Creating XBrowse from a resource

Postby Enrico Maria Giordano » Fri Feb 21, 2014 9:33 am

James,

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


Me neither.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8381
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Creating XBrowse from a resource

Postby Rick Lipkin » Fri Feb 21, 2014 1:40 pm

James

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

Rick Lipkin
Code: Select all  Expand view

 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)
 
User avatar
Rick Lipkin
 
Posts: 2636
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Creating XBrowse from a resource

Postby James Bott » Fri Feb 21, 2014 2:52 pm

Rick,

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

Code: Select all  Expand view
#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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Creating XBrowse from a resource

Postby Enrico Maria Giordano » Fri Feb 21, 2014 3:38 pm

James,

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

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8381
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Creating XBrowse from a resource

Postby James Bott » Fri Feb 21, 2014 5: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: Select all  Expand view
 oBrw        := TXBrows():New( oWnd )

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

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Creating XBrowse from a resource

Postby Enrico Maria Giordano » Fri Feb 21, 2014 6: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
User avatar
Enrico Maria Giordano
 
Posts: 8381
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Otto, sysctrl2 and 40 guests