About oBrw:AddColumn

User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

About oBrw:AddColumn

Post 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))
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Post by byte-one »

First line should be: aBrwArray:={}
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Post by Marco Turco »

Oops, I made this error writing on the forum.

The problem still remain with aBrwArray:={}
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Post by byte-one »

Change nAt with nArrayAt!?
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Post 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.
Best Regards,

Marco Turco
SOFTWARE XP LLP
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Post 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. ) )
User avatar
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Post 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
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Post 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 ?
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Post 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
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Post 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.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Post 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
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Post 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
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Post 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
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Post by Marco Turco »

Yes. You are right.

I need a glasses !!

Many thanks for your support.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Post 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 ?
Best Regards,

Marco Turco
SOFTWARE XP LLP
Post Reply