Page 1 of 2

About oBrw:AddColumn

Posted: Thu Feb 28, 2008 1:50 pm
by Marco Turco
Hi,
I am trying to browse an array but I have syntax problems using the oBrw:AddColumn method because I always receive an array access error.

This is a sample code that show the problem.
Any ideas about the correct syntax ?

aBrwArray:=array(0,2)
aadd(aBrwArray,{"01","First"})
aadd(aBrwArray,{"02","Second"})

@ 1.5,5 COLUMN BROWSE aObjects[6] OF oWnd SIZE 150, 135
aObjects[6]:SetArray(aBrwArray)

aObjects[6]:AddColumn(TCColumn:New("Num",aObjects[6]:aArray[aObjects[6]:nAt,1],,,,,100))

aObjects[6]:AddColumn(TCColumn:New("Title",aObjects[6]:aArray[aObjects[6]:nAt,2],,,,,100))

Posted: Thu Feb 28, 2008 2:11 pm
by byte-one
First line should be: aBrwArray:={}

Posted: Thu Feb 28, 2008 2:32 pm
by Marco Turco
Oops, I made this error writing on the forum.

The problem still remain with aBrwArray:={}

Posted: Thu Feb 28, 2008 3:04 pm
by byte-one
Change nAt with nArrayAt!?

Posted: Fri Feb 29, 2008 8:32 am
by Marco Turco
nArrayAt is only available on xbrowse and not on the standard FWH browse.

I made this self contained sample that show the problem
www.softwarexp.co.uk/beta/test.zip

I think the error message due to the addcolumn syntax I used
(I translated it from the tccolumn include file)

Any ideas appreciated.

Posted: Fri Feb 29, 2008 9:20 am
by hua
Marco,
Why don't you just create the columns using commands? I think it'd be easier to read and code. If you still want to do it this way, then why don't you use browse commands but compile with /p switch. By comparing your code and the generated .ppo file you should be able to spot what went wrong. e.g.:

Prg

Code: Select all

  ADD COLUMN TO ::oBrwOrder ARRAY ELM 1                            ;
      HEADER " No."  LEFT                                    ;
      SIZE oBFont1:nWidth * 7                                ;
      PICT "@!K"                                               ;

Ppo

Code: Select all

 ::oBrwOrder:AddColumn( TCColumn():New( If(.F., OemToAnsi(" No."), " No."), {|x| If(Pcount()>0, ::oBrwOrder:aArray[::oBrwOrder:nAt, 1] :=x, ::oBrwOrder:aArray[::oBrwOrder:nAt, 1])}, "@!K",,, Upper("LEFT"), oBFont1:nWidth * 7, .F., .F.,,,, .F. ) )

Posted: Fri Feb 29, 2008 1:30 pm
by mmercado
Hi Marco:

You have several errors in your posted sample, here you are the corrected code

Code: Select all

//----------------------------------------------------------------------------//

function Child()


   local oWndChild, oBrw, oFont
   local nI, aTestData
    local aObjects[10]

   DEFINE WINDOW oWndChild MDICHILD OF oWnd ;
     FROM 10, 50 TO 250, 400 PIXEL  COLOR "N/W"

    aBrwArray:={}
    aadd(aBrwArray,{"01","First"})
    aadd(aBrwArray,{"02","Second"})

    @ 1.5,5 COLUMN BROWSE aObjects[6] OF oWndChild SIZE 150, 135
    aObjects[6]:SetArray(aBrwArray)

    aObjects[6]:AddColumn(TCColumn():New("Num",{|x| ;
    If(Pcount()>0, aObjects[6]:aArray[aObjects[6]:nAt, 1] :=x, aObjects[6]:aArray[aObjects[6]:nAt, 1])},,,,,100))
    aObjects[6]:AddColumn(TCColumn():New("Title",{|x| ;
    If(Pcount()>0, aObjects[6]:aArray[aObjects[6]:nAt, 2] :=x, aObjects[6]:aArray[aObjects[6]:nAt, 2])},,,,,100))

   oWndChild:SetControl( aObjects[6] )

   ACTIVATE WINDOW oWndChild


return nil
Regards

Manuel Mercado

Posted: Fri Feb 29, 2008 5:07 pm
by Marco Turco
Hi, Manuel,
it runs fine. Thanks.

The only problem is that I try to assign the columns through a for cicle I receive an array access error message.

My code:

for i:=1 to 2

aObjects[6]:AddColumn(TCColumn():New("Num",{|x| ;
If(Pcount()>0, aObjects[6]:aArray[aObjects[6]:nAt, i] :=x, aObjects[6]:aArray[aObjects[6]:nAt, i])},,,,,100))

next

Do you know any solution ?

Posted: Fri Feb 29, 2008 7:03 pm
by mmercado
Marco Turco wrote:The only problem is that I try to assign the columns through a for cicle I receive an array access error message.
Then, what you need is something like this:

Code: Select all

function Child()


   local oWndChild, nI, bData, aObjects[ 10], ;
         aTitles := { "Num", "Title" }

   DEFINE WINDOW oWndChild MDICHILD OF oWnd ;
     FROM 10, 50 TO 250, 400 PIXEL  COLOR "N/W"

    aBrwArray:={}
    aadd(aBrwArray,{"01","First"})
    aadd(aBrwArray,{"02","Second"})

    @ 1.5,5 COLUMN BROWSE aObjects[6] OF oWndChild SIZE 150, 135
    aObjects[6]:SetArray(aBrwArray)

    For nI := 1 To Len( aTitles )
      bData := BuildBlock( AObjects[ 6 ], nI )
      aObjects[6]:AddColumn(TCColumn():New( aTitles[ nI ], bData,,,,, 100 ) )
    next

   oWndChild:SetControl( aObjects[6] )

   ACTIVATE WINDOW oWndChild


return nil

//----------------------------------------------------------------------------//
Static Function BuildBlock( oBrw, n )

Return { |x| If( Pcount() > 0, oBrw:aArray[ oBrw:nAt, n ] := x, oBrw:aArray[ oBrw:nAt, n ] ) }
Regards

Manuel Mercado

Posted: Fri Feb 29, 2008 8:06 pm
by Marco Turco
Great !!! Thanks a lot !!
:shock: I never loved the codeblocks..

Could you suggest me what is the correct codeblock code to make also
a column with the progressive number ?

Like the command:

ADD TO oBrw DATA oBrw:nAt()

to explain me better.

Posted: Fri Feb 29, 2008 8:53 pm
by mmercado
Marco Turco wrote:Could you suggest me what is the correct codeblock code to make also
a column with the progressive number ?
Like the command:
ADD TO oBrw DATA oBrw:nAt()
Following your same example:

aObjects[6]:AddColumn(TCColumn():New( "", {||aObjects[6]:nAt},,,,, 25 ) )

Regards

Manuel Mercado

Posted: Fri Feb 29, 2008 9:46 pm
by Marco Turco
Tried but a Bound Error:Array access appairs.

Any ideas ?

function Child()


local oWndChild, nI, bData, aObjects[ 10], ;
aTitles := { "Num", "Title" }

DEFINE WINDOW oWndChild MDICHILD OF oWnd ;
FROM 10, 50 TO 250, 400 PIXEL COLOR "N/W"

aBrwArray:={}
aadd(aBrwArray,{"01","First"})
aadd(aBrwArray,{"02","Second"})

@ 1.5,5 COLUMN BROWSE aObjects[6] OF oWndChild SIZE 150, 135
aObjects[6]:SetArray(aBrwArray)

** column with progressive number **
Objects[6]:AddColumn(TCColumn():New( "", {||aObjects[6]:nAt},,,,, 25 ) )

For nI := 1 To Len( aTitles )
bData := BuildBlock( AObjects[ 6 ], nI )
aObjects[6]:AddColumn(TCColumn():New( aTitles[ nI ], bData,,,,, 100 ) )
next

oWndChild:SetControl( aObjects[6] )

ACTIVATE WINDOW oWndChild


return nil

Posted: Fri Feb 29, 2008 11:08 pm
by mmercado
Marco Turco wrote:** column with progressive number **
Objects[6]:AddColumn(TCColumn():New( "", {||aObjects[6]:nAt},,,,, 25 ) )
Should be:
aObjects[6]:AddColumn(TCColumn():New( "", {||aObjects[6]:nAt},,,,, 25 ) )

Regards

Manuel Mercado

Posted: Sat Mar 01, 2008 8:24 am
by Marco Turco
Yes. You are right.

I need a glasses !!

Many thanks for your support.

Posted: Thu Mar 27, 2008 8:50 pm
by Marco Turco
Hi,
I have a small problem with bitmaps in the TcBrowse.

Do you know how can I translate:

ADD TO oBrw BITMAP DATA aArray[oBrw:nAt(),1]

in code ?