DCBROWSE ... SORT and dc_setscopearray()

This forum is for eXpress++ general support.
Message
Author
reganc
Posts: 257
Joined: Thu Jan 28, 2010 3:08 am
Location: Hersham, Surrey, UK
Contact:

DCBROWSE ... SORT and dc_setscopearray()

#1 Post by reganc »

Hi Roger

I have just recently been coaxed into using the dc_setscopearray() function to create a scope on a set of records. It works great for getting a small subset of records that matches criteria that we set. But I have a problem...

The browse which I want to use this for has 4 sortable columns (REF,ACCOUNT,POSTCODE,TELEPHONE) based on physical indexes.
We have a search facility on that dialog that will return a set of record numbers for use with dc_setscopearray.

What I want to be able to do is to show the records using the dc_setscopearray() but in the correct ascending/descending order based on the browse sort settings. When I tried to do this myself, it worked when the browse sort was in ascending order but the record movement was 'upside-down' when it was set to descending.

Steve pointed out to me that the dc_setscopearray can be multi-dim (which I had missed, duh!).

So I can use the other dimensions to hold the sorting keys and simply sort the array into the necessary order instead of using an index.

Am I thinking along the right track? Or is there a better way of doing this?

I have tried to make the problem clear enough to understand because putting a sample together would take too long in this instance...

Thanks for any insight you can give me...
Regan Cawkwell
Real Business Applications Ltd
http://www.rbauk.com

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DCBROWSE ... SORT and dc_setscopearray()

#2 Post by rdonnay »

Regan -

It seems to me that you are going in the right direction.
Alternatively, you could reload the scope array in your sort code block but this may take longer depending on the database size.

Roger
The eXpress train is coming - and it has more cars.

reganc
Posts: 257
Joined: Thu Jan 28, 2010 3:08 am
Location: Hersham, Surrey, UK
Contact:

Re: DCBROWSE ... SORT and dc_setscopearray()

#3 Post by reganc »

Thanks Roger

I'm trying it out this morning...
Regan Cawkwell
Real Business Applications Ltd
http://www.rbauk.com

reganc
Posts: 257
Joined: Thu Jan 28, 2010 3:08 am
Location: Hersham, Surrey, UK
Contact:

Re: DCBROWSE ... SORT and dc_setscopearray()

#4 Post by reganc »

One other question...

Does dc_setscopearray() override the normal dc_setscope() facility or can it be used at the same time?
Regan Cawkwell
Real Business Applications Ltd
http://www.rbauk.com

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: DCBROWSE ... SORT and dc_setscopearray()

#5 Post by skiman »

Hi Regan,

Both are in my opinion totally different.

With dc_setscopre you are really working on indexes. You have your top and your bottom key. With dc_setscopearray the browse is based on the array. This is working without any indexes.

If you fill your array, you can have an index active, so the array is filled in the order of the index.

If you set a dc_scope, you can use this to fill your array, at the moment you set your dc_setscopearray() this comes active. I don't know if it is needed, but I'm always clearing my scope before changing from one system to another.
Best regards,

Chris.
www.aboservice.be

reganc
Posts: 257
Joined: Thu Jan 28, 2010 3:08 am
Location: Hersham, Surrey, UK
Contact:

Re: DCBROWSE ... SORT and dc_setscopearray()

#6 Post by reganc »

Hi Chris

Thanks for that last explanation... It basically confirms what I thought.

On the browse I have, the first column is a unique numeric transaction id. When the browse first displays, the records are shown based on the main index, the key of which is 'str(DPREF,6)'. I also set a start scope of 'str(1,6)' and an end scope of 'str(999999,6)'. The browse shows fine at this point.

I am using a version of the text seeking stuff that you originally spoke with Steve about a long time ago. The user types in the text they want to search for and it goes and creates an array of all records that match that text. I'll call this the matching array.

In my browse sort function I get the index order to be used to show the records, make sure the correct index is in use along with the correct scopes for that index. I go through the matching array and use dc_dbgoto to go to the record. If it is within the scopes set, then the key for the current index is used to get a key value for that record and put into a 2 dim array where the first element in the record number and the second is the sort key. Once all records have been gone through, the resulting array is sorted by the 2nd element of each row to put it into the correct order. This array is then assigned to dc_setscopearray() for the database.

After the above has been done, the browse is fine. The entries are sorted in the correct ascending order.

If you then right-click the browse column to sort it 'descending' the browse freezes and 9 times out of ten I get an XPPFATAL.LOG exit.

Below is one of the XPPFATAL logs for example:

FATAL ERROR LOG
Not recoverable Error!
SYS Thread-ID: 1432
Module: EH
Error Codes: EH: 900 Sub: 0(0) OS: 0 XPP: 0
Call Stack of Thread 1 (1540):
@DC_GETLIST@I@EVENTLOOP(3915)
@DC_GETLIST@I@READGUI(3647)
DC_READGUI(103)
XB_MENU(605)
MAIN(496)
Call Stack of GUI Thread (1348):
Call Stack of Thread 3 (928):
@JD_MAGICHELPTHREAD@I@EXECUTE(50)
(B)@JD_MAGICHELPTHREAD@I@INIT@0000(36)
Call Stack of Thread 4 (888):
USER_THREAD_PROCESSING(599)
(B)LOGON(564)
Call Stack of Thread 5 (820):
STANDARDEH(101)
(B)ERRORSYS@0000(54)
@DC_XBPCOLUMN@I@SORT(2580)
(B)_HeaderDown(2664)
@DC_GETLIST@I@EVENTLOOP(4386)
@DC_GETLIST@I@READGUI(3647)
DC_READGUI(103)
DP_LOOKUP_NEW(2408)
DP_LOOKUP(92)
(B)CS_UPDATE@0021(345)
_PROCESSHOTKEY(5215)
@DC_GETLIST@I@EVENTLOOP(4466)
@DC_GETLIST@I@READGUI(3647)
DC_READGUI(103)
CS_UPDATE(2420)
(B)MENURUN(0)
RUNFUNCTION(76)
(B)RUN_PROCEDURE(63)
File: h:\xbprog\rbawin\prog\RBA32.EXE
TimeStamp: 20101027 16:54
End of FATAL ERROR LOG.

The DP_NEW_LOOKUP function is the one that displays the dialog I am working on at the time the log is created.

The problem only seems to happen when the column is to be displayed in descending order. As I mentioned, this browse has 4 sortable columns. If I buiild the dc_setscope array when the first column is the selected sort order and then right-click on each of the other three sortable headings, it does not crash. It is only when I right click on the heading that is already the current sort order that I get the crash.

It is truly weird and frustrating...

If you (or anyone else for that matter) have any thoughts about what may be the problem, please let me know...
Regan Cawkwell
Real Business Applications Ltd
http://www.rbauk.com

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: DCBROWSE ... SORT and dc_setscopearray()

#7 Post by skiman »

Hi Regan,

I'm afraid this is something in eXPress. I remember I had the same issue when I added the sorting in my browses. I have NODESCENDTOGGLE in my browses.

I didn't need them at that moment, and I never searched for the cause.
Best regards,

Chris.
www.aboservice.be

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: DCBROWSE ... SORT and dc_setscopearray()

#8 Post by Auge_Ohr »

reganc wrote:Error Codes: EH: 900 Sub: 0(0) OS: 0 XPP: 0
try disable DEP (Data Execution Protection) or try Compatible XP Mode
reganc wrote:Call Stack of Thread 5 (820):
STANDARDEH(101)
(B)ERRORSYS@0000(54)
@DC_XBPCOLUMN@I@SORT(2580)
(B)_HeaderDown(2664)
here your Problem begin.

what OS() ? what Xbase++ Version ?
can you show some Code ? how dow your :sortBlock look like ?

my is based on C:\ALASKA\XPPW32\Source\samples\basics\GuiBrow\FBROWSE.prg

Code: Select all

******************************************************************************
* Change the sorting order of the data source
* The 'index' array is sorted according to values of the data source array
******************************************************************************
FUNCTION SortFiles( oBrowse, nSubScript )
LOCAL nStartAt := 1
LOCAL aArray   := oBrowse:cargo
LOCAL oColumn  := oBrowse:getColumn( aArray[ ARR_ORD ] + 1 )
LOCAL bBlock   := oColumn:colorBlock

LOCAL aSort    := aArray[ ARR_SORT ]
LOCAL aSource  := aArray[ ARR_SRC  ]
LOCAL nNo      := aArray[ ARR_NO   ]

DEFAULT nSubScript TO F_NAME

   IF nSubScript > LEN(aSort)
      RETURN .F.
   ENDIF

   // First, put all sub-directories
   // at the beginning of the list
   ASort( aArray[ ARR_SORT ] ,,, {|i,j| "D" $ aArray[ ARR_SRC, i, F_ATTR ] } )

   // Now, lets find out where the other
   // files are
   AEVAL(aArray[ARR_SORT],{|x,i| nStartAt := IF("D" $ aArray[ARR_SRC,x,F_ATTR],i,nStartAt)})

   // Sort sub-directories only
   ASort( aArray[ ARR_SORT ] ,1, nStartAt, ;
      {|i,j| aArray[ ARR_SRC, i, F_NAME ] < ;
             aArray[ ARR_SRC, j, F_NAME ] } )

   nStartAt++

   // Sort only the non-directory files.
   // Sort Array based on the first subarray
   // element
   ASort( aArray[ ARR_SORT ] ,nStartAt,, ;
   {|i,j| aArray[ ARR_SRC, i, nSubScript ] < ;
          aArray[ ARR_SRC, j, nSubScript ] } )

   aArray[ ARR_ORD ]  := nSubScript

RETURN .T.
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DCBROWSE ... SORT and dc_setscopearray()

#9 Post by rdonnay »

Regan -

Can you reproduce this problem in a sample?

Roger
The eXpress train is coming - and it has more cars.

reganc
Posts: 257
Joined: Thu Jan 28, 2010 3:08 am
Location: Hersham, Surrey, UK
Contact:

Re: DCBROWSE ... SORT and dc_setscopearray()

#10 Post by reganc »

skiman wrote:Hi Regan,

I'm afraid this is something in eXPress. I remember I had the same issue when I added the sorting in my browses. I have NODESCENDTOGGLE in my browses.

I didn't need them at that moment, and I never searched for the cause.
Ah, OK.

I added the NODESCENDTOGGLE clause to my browse and that does stop the crash from occurring.

Thanks.
Regan Cawkwell
Real Business Applications Ltd
http://www.rbauk.com

Post Reply