Codeblock Using Position Out Of An Array

Post Reply
User avatar
gkuhnert
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands
Contact:

Codeblock Using Position Out Of An Array

Post by gkuhnert »

Hi,

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

Code: Select all | Expand

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

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

Re: Codeblock Using Position Out Of An Array

Post by James Bott »

Gilbert,

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

James
User avatar
gkuhnert
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands
Contact:

Re: Codeblock Using Position Out Of An Array

Post by gkuhnert »

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

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

Re: Codeblock Using Position Out Of An Array

Post by James Bott »

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
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Codeblock Using Position Out Of An Array

Post by nageswaragunupudi »

From version 8.03 onwards, it is no more necessary to code like

Code: Select all | Expand

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

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

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

Re: Codeblock Using Position Out Of An Array

Post by James Bott »

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
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Codeblock Using Position Out Of An Array

Post by nageswaragunupudi »

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

Yes.
Similarly for arrays

Code: Select all | Expand


ADD TO oBrw ARRAY ELEMENT 2 ORDER 3

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

G. N. Rao.
Hyderabad, India
Post Reply