FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Codeblock Using Position Out Of An Array
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Codeblock Using Position Out Of An Array
Posted: Mon Aug 24, 2009 08:30 AM
Hi,

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

Code (fw): Select all Collapse
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 (fw): Select all Collapse
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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Codeblock Using Position Out Of An Array
Posted: Mon Aug 24, 2009 01:08 PM

Gilbert,

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

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Re: Codeblock Using Position Out Of An Array
Posted: Mon Aug 24, 2009 02: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 (fw): Select all Collapse
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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Codeblock Using Position Out Of An Array
Posted: Mon Aug 24, 2009 02: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Codeblock Using Position Out Of An Array
Posted: Mon Aug 24, 2009 05:55 PM
From version 8.03 onwards, it is no more necessary to code like
Code (fw): Select all Collapse
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 (fw): Select all Collapse
aSort := { 3, 1, 2 }
for nI := 1 to len(oBrw:aCols)
    oBrw:aCols[nI]:bLClickHeader := {|| Msginfo(aSort[nI])}
next

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



G. N. Rao.

Hyderabad, India
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Codeblock Using Position Out Of An Array
Posted: Mon Aug 24, 2009 07: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Codeblock Using Position Out Of An Array
Posted: Mon Aug 24, 2009 09:45 PM
James Bott wrote:
add column to oBrw data company header "Company" order "company"
James

Yes.
Similarly for arrays
Code (fw): Select all Collapse
ADD TO oBrw ARRAY ELEMENT 2 ORDER 3

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



G. N. Rao.

Hyderabad, India

Continue the discussion