XBROWSE and code blocks

XBROWSE and code blocks

Postby frose » Mon Apr 27, 2009 10:17 am

Hello to all,

just started to work with XBROWSE, running into probs when adding new columns:

These lines are NOT functional:
- ADD TO oBrw DATA bBlock HEADER "City bBlock" CARGO { 1, 2 }
- oBrw:AddColumn( OemToAnsi("City CB*"), bBlock,,,,,, .F., .F.,,,,,, .F.,,,,, .F.,,, { 1, 2 } )
- oBrw:AddColumn( OemToAnsi("City CB*"), Get_Block( cBlock, cAlias ),,,,,, .F., .F.,,,,,, .F.,,,,, .F.,,, { 1, 2 } )
Why?

This is functional:
- oBrw:AddColumn( OemToAnsi("City CB*"), Format_Block( cBlock, cAlias ),,,,,, .F., .F.,,,,,, .F.,,,,, .F.,,, { 1, 2 } )

Here is the sample code:
Code: Select all  Expand view
STATIC FUNCTION My_Browse()
   LOCAL oWnd
   LOCAL oBrw
   LOCAL oCol
   //LOCAL cAlias := cGetNewAlias( "CUSTOMER" )
   LOCAL cAlias := "CUSTOMER"
   LOCAL n
   LOCAL cBlock
   LOCAL bBlock

   USE CUSTOMER NEW Alias ( cAlias ) SHARED VIA "DBFCDX"
   Set ORDER TO TAG FIRST
   GO TOP

   DEFINE WINDOW ownd MDICHILD OF WndMain() TITLE "My_Browse"

   @  0,  0 XBROWSE oBrw OF ownd ALIAS cAlias

   oBrw:bKeyChar := { | nKey | If( nKey == VK_ESCAPE, oWnd:End(), nKey ) }

   oBrw:bClrRowFocus := oBrw:bClrSelFocus

   ADD TO oBrw DATA ( cAlias )->CITY HEADER "City" CARGO { 1, 2 }
 
   ADD TO oBrw DATA { || ( cAlias )->CITY } HEADER "City CB" CARGO { 1, 2 }

   cBlock := "{ || ( cAlias )->CITY }"
   bBlock := &( "{ || ( cAlias )->CITY }" )
   //
   // Doesn't compile, "syntax error at 'TO'"
   //
   //ADD TO oBrw DATA bBlock HEADER "City bBlock" CARGO { 1, 2 }
   //
   // Compile, but Error LEN
   //
   //oBrw:AddColumn( OemToAnsi("City CB*"), bBlock,,,,,, .F., .F.,,,,,, .F.,,,,, .F.,,, { 1, 2 } )
   //
   // Detached local: Error LEN
   //
   //oBrw:AddColumn( OemToAnsi("City CB*"), Get_Block( cBlock, cAlias ),,,,,, .F., .F.,,,,,, .F.,,,,, .F.,,, { 1, 2 } )
   //
   // This is functional
   //
   oBrw:AddColumn( OemToAnsi("City CB*"), Format_Block( cBlock, cAlias ),,,,,, .F., .F.,,,,,, .F.,,,,, .F.,,, { 1, 2 } )

   AEval( oBrw:aCols, { | o | o:nEditType := EDIT_GET } )
   //AEval( oBrw:aCols, { | o | o:bPopUp := { | o | ColMenu( o ) } } )

   oBrw:CreateFromCode()
   oWnd:oClient := oBrw

   SET MESSAGE OF oWnd TO "RDD All Cols" 2007

   ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus()

RETURN NIL

STATIC FUNCTION Get_Block( cBlock, cAlias )
RETURN &( cBlock )

STATIC FUNCTION Format_Block( cBlock, cAlias )
   cBlock := StrTran( cBlock, "( cAlias )", cAlias )
   cBlock := StrTran( cBlock, "cAlias", Chr( 34 ) + cAlias + Chr( 34 ) )
RETURN &( cBlock )
 


Ok, I can solve it with the function "Format_Block()", but that's not very smart and why it doesn't work with '&( cBlock )?
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: XBROWSE and code blocks

Postby frose » Tue Apr 28, 2009 8:52 am

ok,

it doesn't work because <cAlias> is LOCAL and isn't visible for the code block as soon as the macro operator &() is involved. So 'detached locals' isn't a possible solution!

Any other proposals?
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: XBROWSE and code blocks

Postby nageswaragunupudi » Tue Apr 28, 2009 2:38 pm

Add to oBrw ... command is perfectly working for me.
I used your own sample and it is working here.
Code: Select all  Expand view
#include "fivewin.ch"
#include "ord.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

function main()

   local oWnd, oBar

   define window oWnd mdi
   define buttonbar oBar of oWnd 2007
   define button of oBar action my_browse()

   activate window oWnd

return nil

STATIC FUNCTION My_Browse()

   LOCAL oWnd
   LOCAL oBrw
   LOCAL cAlias := cGetNewAlias( "CUSTOMER" )
   LOCAL n

   USE CUSTOMER NEW Alias ( cAlias ) SHARED VIA "DBFCDX"
   Set ORDER TO TAG FIRST
   GO TOP

   DEFINE WINDOW ownd MDICHILD OF WndMain() TITLE "My_Browse"

   @  0,  0 XBROWSE oBrw OF ownd ALIAS cAlias

   oBrw:bKeyChar := { | nKey | If( nKey == VK_ESCAPE, oWnd:End(), nKey ) }

   oBrw:bClrRowFocus := oBrw:bClrSelFocus

   ADD TO oBrw DATA ( cAlias )->CITY HEADER "City" CARGO { 1, 2 }

   ADD TO oBrw DATA { || ( cAlias )->CITY } HEADER "City CB" CARGO { 1, 2 }

   AEval( oBrw:aCols, { | o | o:nEditType := EDIT_GET } )
   //AEval( oBrw:aCols, { | o | o:bPopUp := { | o | ColMenu( o ) } } )
   // now we can say oBrw:bPopUp := { |o| OutMenu( o ) }.
   // oBrw:bPopUp by default applies to all columns, unless columns have
   // their own popups ...from Version 9.04

   oBrw:CreateFromCode()
   oWnd:oClient := oBrw

   SET MESSAGE OF oWnd TO "RDD All Cols" 2007

   ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus()

RETURN NIL
 

Build the above code, it works. ( I am using fwh 9.04)

Also please see the notes in addColumn method
Code: Select all  Expand view
  // This method is intended only to support command syntax
   // and this method should not be called directly in the
   // application program
 

In future versions they may change the order of the parameters or do anything. Better not to use this method directly. Instead use the commands. Or totally go the oops way using oBrw:AddCol()
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: XBROWSE and code blocks

Postby frose » Tue Apr 28, 2009 6:37 pm

Hello Rao,

thank you very much for your response.

Yes, you are quite right, so I will switch to the oops syntax.

My problem starts if you change the code to:

Code: Select all  Expand view
ADD TO oBrw DATA &( "{ || ( cAlias )->CITY }" ) HEADER "City CB" CARGO { 1, 2 }

Because <cAlias> is LOCAL, it's not visible for the code block.

At the beginning I thought 'detached locals' is a solution, but as soon as the macro operator &() is involved, <cAlias> is not visible for the code block, even in the lower-level-function 'Get_Block()' :-(

So I'm starting to replace the occurrences of "cAlias" in the code block string, see Format_Block().

But perhaps someone has a better solution?
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 86 guests

cron