Codeblock Using Position Out Of An Array

Codeblock Using Position Out Of An Array

Postby gkuhnert » Mon Aug 24, 2009 8:30 am

Hi,

untill now I had hardcoded the codeblocks for every column of a xBrowse, like

Code: Select all  Expand view
oBrw:aCols[1]:bLClickHeader := {|| Sort(1)}
oBrw:aCols[2]:bLClickHeader := {|| Sort(3)}
oBrw:aCols[3]:bLClickHeader := {|| Sort(2)}
 

this worked fine, but now I want to assign the numbers using an array like
Code: Select all  Expand view
aSort := { 3, 1, 2 }
for nI := 1 to len(oBrw:aCols)
    oBrw:aCols[nI]:bLClickHeader := {|| Msginfo(aSort[nI])}
next


But if I click a header, doesn't matter which one, I always get as a response "2" (the last item of the array), but I wanted by clicking at the header at the first column a "3" and on the second column a "1"
Do you have any suggestion how to solve this problem?
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Codeblock Using Position Out Of An Array

Postby James Bott » Mon Aug 24, 2009 1:08 pm

Gilbert,

You have to use a "detached local." Search the form for more info.

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

Re: Codeblock Using Position Out Of An Array

Postby gkuhnert » Mon Aug 24, 2009 2:20 pm

James,
thank you very much for your quick response.

However, I found an alternative solution and wonder, if I might encounter problems, because I use an object that is marked "used internally" in the source code of TXbrowse:

Here my working solution:
Code: Select all  Expand view
FOR nI := 1 TO len(aSort)
  oLB:aCols[nI]:Cargo := nI // first I use the "Cargo"-Information to remember, which column-number I have to deal with
  oCol := oLB:aCols[nI]
  IF aSort[nI] > 0
    oCol:bLClickHeader :=  {|| Msginfo(aSort[oLB:oCapCol:Cargo]) } // oLB:oCapCol is marked as "used internally"
  ENDIF
NEXT
 
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Codeblock Using Position Out Of An Array

Postby James Bott » Mon Aug 24, 2009 2:33 pm

Gilbert,

Generally, Antonio uses those comments to signify that a var should not be used outside the class. Ideally, these vars should be made "hidden" so that cannot be used or even seen outside the class. So, the answer is that you should never change those vars.

So I still think you should use a detached local.

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

Re: Codeblock Using Position Out Of An Array

Postby nageswaragunupudi » Mon Aug 24, 2009 5:55 pm

From version 8.03 onwards, it is no more necessary to code like
Code: Select all  Expand view
oBrw:aCols[2]:bLClickHeader := {|| Sort(3)}
for sorting on columns.

Please see whatsnew.txt:
b) New DATA cSortOrder. It is now not necessary to do the tedious coding of
oCol:bLclickHeader to enable sorting of data in response the Left Click on the header.
Assiging the name of index order in case of RDD, column names in case of ADO or the
column number of array to the Data cSortOrder is all that is needed.

So the proposed code
Code: Select all  Expand view
aSort := { 3, 1, 2 }
for nI := 1 to len(oBrw:aCols)
    oBrw:aCols[nI]:bLClickHeader := {|| Msginfo(aSort[nI])}
next
 

can be written as
Code: Select all  Expand view
aSort := { 3, 1, 2 }
for nI := 1 to len(oBrw:aCols)
    oBrw:aCols[nI]:cSortOrder  := aSort[ nI ]
next
 
Regards

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

Re: Codeblock Using Position Out Of An Array

Postby James Bott » Mon Aug 24, 2009 7:28 pm

I don't know if this helps, but you can also define the sort order using index tags.

add column to oBrw data company header "Company" order "company"

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

Re: Codeblock Using Position Out Of An Array

Postby nageswaragunupudi » Mon Aug 24, 2009 9:45 pm

James Bott wrote:add column to oBrw data company header "Company" order "company"
James

Yes.
Similarly for arrays
Code: Select all  Expand view

ADD TO oBrw ARRAY ELEMENT 2 ORDER 3

This is internally translated as oCol:cSortOrder := 3
Regards

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


Return to FiveWin for Harbour/xHarbour

Who is online

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