Problem with dcbrowse and empty array

This forum is for eXpress++ general support.
Message
Author
skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Problem with dcbrowse and empty array

#1 Post 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.
Best regards,

Chris.
www.aboservice.be

User avatar
Tom
Posts: 1234
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Problem with dcbrowse and empty array

#2 Post 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} )}
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

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

Re: Problem with dcbrowse and empty array

#3 Post 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.
Best regards,

Chris.
www.aboservice.be

User avatar
Tom
Posts: 1234
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Problem with dcbrowse and empty array

#4 Post 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.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
Tom
Posts: 1234
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Problem with dcbrowse and empty array

#5 Post 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.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

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

Re: Problem with dcbrowse and empty array

#6 Post 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
The eXpress train is coming - and it has more cars.

User avatar
Tom
Posts: 1234
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Problem with dcbrowse and empty array

#7 Post 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.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

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

Re: Problem with dcbrowse and empty array

#8 Post 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
The eXpress train is coming - and it has more cars.

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

Re: Problem with dcbrowse and empty array

#9 Post 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.
Best regards,

Chris.
www.aboservice.be

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

Re: Problem with dcbrowse and empty array

#10 Post 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!!!!
The eXpress train is coming - and it has more cars.

Post Reply