Page 1 of 2
Problem with dcbrowse and empty array
Posted: Tue Feb 12, 2013 3:48 am
by skiman
Hi,
I have a problem with a DCbrowse of an array. When the array is empty, I'm getting an error. This is because the colorblock is using the array to define the color.
Code: Select all
#INCLUDE "dcdialog.CH"
FUNCTION Main()
LOCAL GetList[0], GetOptions, oBrowse
Local aDir := {}
@ 1,0 DCBROWSE oBrowse DATA aDir SIZE 40,10 FIT MAX 100 ;
USEVISUALSTYLE ;
CURSORMODE XBPBRW_CURSOR_ROW ;
FONT '10.Lucida Console' ;
SORTSCOLOR GRA_CLR_WHITE,GRA_CLR_RED SORTUCOLOR GRA_CLR_WHITE,GRA_CLR_RED ;
COLOR {|o,aSub|aSub := o:dataSource[o:arrayElement] , if(empty(aSub[1]),{ GRA_CLR_YELLOW , GRA_CLR_DARKGRAY},{ GRA_CLR_RED , GRA_CLR_DARKGRAY} )}
DCBROWSECOL ELEMENT 1 HEADER 'File Name' WIDTH 20 PARENT oBrowse
DCBROWSECOL ELEMENT 2 HEADER 'File Size' WIDTH 10 PARENT oBrowse
DCBROWSECOL ELEMENT 3 HEADER 'File Date' WIDTH 10 PARENT oBrowse
DCBROWSECOL ELEMENT 4 HEADER 'File Time' WIDTH 10 PARENT oBrowse
DCGETOPTIONS RESIZE
DCREAD GUI FIT TITLE 'Testing Owner Draw Browse' OPTIONS GetOptions
RETURN nil
The cause is the colorblock which is using the array to define the color. If there is no colorblock, then it is working fine.
I could make a change in the colorblock, but normally the dcbrowse methods should take care of this.
Re: Problem with dcbrowse and empty array
Posted: Tue Feb 12, 2013 3:58 am
by Tom
Hi, Chris.
If browsing arrays that can be empty, you need to take care about this when referencing this array maybe in data-codeblocks. The error is here:
Code: Select all
COLOR {|o,aSub|aSub := o:dataSource[o:arrayElement] , if(empty(aSub[1]),{ GRA_CLR_YELLOW , GRA_CLR_DARKGRAY},{ GRA_CLR_RED , GRA_CLR_DARKGRAY} )}
"aSub" is empty, so you can't access "aSub[1]". Try this:
COLOR {|o,aSub|aSub := o:dataSource[o:arrayElement] , IF(Len(o:dataSource)=0 .OR. empty(aSub[1]),{ GRA_CLR_YELLOW , GRA_CLR_DARKGRAY},{ GRA_CLR_RED , GRA_CLR_DARKGRAY} )}
Re: Problem with dcbrowse and empty array
Posted: Tue Feb 12, 2013 4:08 am
by skiman
Hi Tom,
Yes, as I wrote 'I could make a change in the colorblock...'.
IMO, if the array is empty, the drawrow method shouldn't be executed at all?
Also, if you use an old dclipx.dll, you also won't have the error. I think the error appears since the zebra modifications.
Re: Problem with dcbrowse and empty array
Posted: Tue Feb 12, 2013 5:09 am
by Tom
Hi, Chris.
Older versions of eXpress++ weren't able to deal with empty arrays in browses, as I remember - doing so caused an error. Somewhere between build x and build y, Roger caught this situation, so browsing an array behaves somehow like browsing a table: If there is no record, the phantom record shows up. One line is painted anyway! As a side effect, code reflecting this must reflect an empty array. You have to change the codeblock, like if you would deal with the DATA clause in DCBROWSECOL, for instance using DC_GetColArray.
Re: Problem with dcbrowse and empty array
Posted: Tue Feb 12, 2013 6:56 am
by Tom
I think the error appears since the zebra modifications.
This maybe true for the color block. This:
DCBROWSECOL DATA {||IF(DC_GetColArray(1,oBrowse)>1,"+","-")} PARENT oBROWSE ...
caused an error since at least build #1 with an empty array.

It's almost the same thing. Accessing not existing data creates errors.
Re: Problem with dcbrowse and empty array
Posted: Tue Feb 12, 2013 7:41 am
by rdonnay
Chris -
I can deal with an empty array as the dataSource but not a reference in the color block.
I cannot analyze code within a code block and prevent errors.
The only way to do this is to trap errors.
I tried this in the past and it caused other problems because it would not display coding errors.
I could modify the Alaska source code for XbpBrowse() but don't want to do that because then I would own it.
My only suggestion is for you to write your own function that you call within the code block.
That function would test for an empty array.
Roger
Re: Problem with dcbrowse and empty array
Posted: Tue Feb 12, 2013 7:55 am
by Tom
Hi, Roger.
The only way to do this is to trap errors.
You did this in earlier versions, right? That caused blank zones in browses with that kind of errors inside drawing routines or color codeblocks.
This shows the limit of a framework like eXpress++. Programmers should still take care about their logic. eXpress++ should not be responsible for this.
Re: Problem with dcbrowse and empty array
Posted: Tue Feb 12, 2013 8:29 am
by rdonnay
Tom -
Yes, I did it in earlier versions and it was not a good idea.
When a programmer uses a code block, he is responsible for the logic within the code block.
If eXpress++ creates a code block, then eXpress++ is responsible for the logic within the code block.
eXpress++ creates lots of code blocks and I take it seriously that they must work reliably.
Roger
Re: Problem with dcbrowse and empty array
Posted: Wed Feb 13, 2013 11:46 pm
by skiman
Hi Roger and Tom,
I modified my codeblock, no problem.
With a dclipx.dll from 2010 there is no error in the above case. I suppose there was some check when there was an empty array.
Re: Problem with dcbrowse and empty array
Posted: Thu Feb 14, 2013 12:59 pm
by rdonnay
With a dclipx.dll from 2010 there is no error in the above case. I suppose there was some check when there was an empty array.
There WAS an error, but I put an error trap in the DC_XbpBrowse() class so it would not display the error.
That was a bad idea and I removed it. I put it there to prevent errors such as those that a bad code block would cause. NEVER AGAIN!!!!