Twbrowse - error : Bound array access

Twbrowse - error : Bound array access

Postby driessen » Fri Oct 08, 2010 1:21 pm

Hello,

If the value "oLbx:nAt" in a listbox, containing an array, gets a value which is higher then the length of the array, a bound array error occurs.

Is there no possibility to change the Twbrowse class in this way : when "oLbx:nAt" gets a value which is higher then the length of the array in the listbox, "oLbx:nAt" is automatically set to the length of the array. This would prevent the bound array error to occur.

My only problem : I know to little about classes to build this change.

Thank you very much in advance for any help.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Twbrowse - error : Bound array access

Postby Willi Quintana » Fri Oct 08, 2010 1:47 pm

Hi Driessen
oLbx: NAT should never exceed the length of the array, this data should be checked every time
is better than a user has control of the length of the array, so we'll know more assurance that the function is working properly,, (sorry my english)
regards
User avatar
Willi Quintana
 
Posts: 1002
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú

Re: Twbrowse - error : Bound array access

Postby driessen » Fri Oct 08, 2010 1:56 pm

Willi,

Thank you for your answer.

My experience is otherwise though.

If you are positioned on the last line of the array, and you delete this line, then you always have to take care about oLbx:nAt because otherwise the bound error array occurs. To my opinion that should be checked in the class itself.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Twbrowse - error : Bound array access

Postby hag » Fri Oct 08, 2010 2:58 pm

Driessen:

I agree with your suggestion. A behind the senes check by oLbx: NAT is an excellent idea.
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Re: Twbrowse - error : Bound array access

Postby James Bott » Fri Oct 08, 2010 5:44 pm

Michel,

If you are positioned on the last line of the array, and you delete this line, then you always have to take care about oLbx:nAt because otherwise the bound error array occurs. To my opinion that should be checked in the class itself.


Can you provide a small self-contained example showing the problem?

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Twbrowse - error : Bound array access

Postby Willi Quintana » Sat Oct 09, 2010 2:05 am

Each time you remove an element of an array, you must control the length of the array, if it reaches zero (0), is added an element with empty data ... must use the Asize()
regards
User avatar
Willi Quintana
 
Posts: 1002
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú

Re: Twbrowse - error : Bound array access and division by zero

Postby xhbcoder » Thu Jun 09, 2011 6:39 pm

Hi All,

We are also experiencing a bound array access error with TWBrowse FWH version 10.9 but it is hard to reproduce in our application.

The following are extracted from our error log.

20110602;13:25:33
(b)TRY@16
(b)STARTPCR@1590
(b)TWBROWSE@152
TWBROWSE:DRAWLINE@0
Alias PLU
PC/Register+(tm) 5.3-20110518 SN0000000001
Error BASE/1132 Bound error: array access Args: (A:{ ... }) (N:-3)

20110608;10:10:14
(b)TRY@16
(b)STARTPCR@1590
TWBROWSE:DRAWSELECT@464
TWBROWSE:LBUTTONDOWN@1216
Alias PLU
PC/Register+(tm) 5.3-20110518 SN0000000001
Error BASE/1132 Bound error: array access Args: (A:{ ... }) (N:0)

Is this a similar issue?

Do we have a solution or update to TWBrowse Class or any suggestions that may resolve this issue?

Thank you very much,

Jose


Division by Zero:
Actually we are also experiencing a division by zero error with TWBrowse. It is happening randomly when we access the application via Remote DeskTop.

20110602;13:48:12;(b)TRY@16
TWBROWSE:LBUTTONUP@1261
TCONTROL:HANDLEEVENT@1489
TWBROWSE:HANDLEEVENT@1656
Alias CLERK
PC/Register+(tm) 5.3-20110518 SN0000000001
Error BASE/1340 Zero divisor: / Args: (N:0) (N:0.00)

Any idea?

Thank you very much.

Jose
xhbcoder
 
Posts: 100
Joined: Wed Oct 04, 2006 4:50 pm
Location: USA

Re: Twbrowse - error : Bound array access

Postby James Bott » Tue Jun 21, 2011 12:08 am

Jose,

Error BASE/1132 Bound error: array access Args: (A:{ ... }) (N:-3)

Error BASE/1132 Bound error: array access Args: (A:{ ... }) (N:0)

Is this a similar issue?

Do we have a solution or update to TWBrowse Class or any suggestions that may resolve this issue?


In the two examples you gave, N=-3 in one and N=0 in the other. I expect the problem is in your code. I'm not sure how you can get a -3 value for the row pointer. The 0 pointer probably means you have a empty array; either it was empty when the browse was initiated, or the user deleted all the records. Please check your code to make sure you are adjusting the array length value in the Browse (oLbx:nAt) when deleting and adding records. I don't know if wBrowse can handle an empty array or not--it should be easy to test.
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Twbrowse - error : Bound array access

Postby Francisco Horta » Tue Jun 21, 2011 6:19 pm

hi driessen,
Willy say: oLbx: NAT should never exceed the length of the array.. and is correct, but if you delete the last record, then should be this action:
ADel( YourArray, oLbx:nAt )
ASize( YourArray, Len( YourArray ) - 1 )
oLbx:GoUp()
oLbx:Refresh()

works fine for me !!
regards
paco
____________________
Paco
Francisco Horta
 
Posts: 845
Joined: Sun Oct 09, 2005 5:36 pm
Location: la laguna, mexico.

Re: Twbrowse - error : Bound array access

Postby Willi Quintana » Fri Jun 24, 2011 6:02 pm

Something else,,, every time you make a ASIZE, ADEL, must necessarily indicate a SetArray, example:

Adel (YourArray, oLbx NAT)
ASize (YourArray, Len (YourArray) - 1)
oLbx: SetArray (YourArray) <--------------- this is where the:: nAt is updated ..
oLbx: goup ()
oLbx: Refresh ()

Regards
User avatar
Willi Quintana
 
Posts: 1002
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú

Re: Twbrowse - error : Bound array access

Postby Antonio Linares » Fri Jun 24, 2011 7:38 pm

driessen wrote:If you are positioned on the last line of the array, and you delete this line...


Michel,

How do you delete it ? thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Twbrowse - error : Bound array access

Postby xhbcoder » Thu Jul 07, 2011 5:36 am

James Bott wrote:In the two examples you gave, N=-3 in one and N=0 in the other. I expect the problem is in your code. I'm not sure how you can get a -3 value for the row pointer. The 0 pointer probably means you have a empty array; either it was empty when the browse was initiated, or the user deleted all the records. Please check your code to make sure you are adjusting the array length value in the Browse (oLbx:nAt) when deleting and adding records. I don't know if wBrowse can handle an empty array or not--it should be easy to test.


James,

Thank you for the reply. I tried to find the bug but unable. The array is initialized in the beginning to 200 and not resized through the execution of the program.

Here is the offending code from wbrowse.prg line 152 - It is an inline method.

wBrwLine( ::hWnd, ::hDC, If( nRow == nil, ::nRowPos, nRow ), ;
Eval( ::bLine, Self ), ::GetColSizes(), ::nColPos,;
::nClrText, ::nClrPane,;
If( ::oFont != nil, ::oFont:hFont, 0 ),;
ValType( ::aColSizes ) == "B", ::aJustify, nil, ::nLineStyle,,, ::oVScroll,;
::bLogicLen )

I wonder if which of these parameters triggers the error and what is 'N' in this code?

Any idea?

Thank you all,

Jose
xhbcoder
 
Posts: 100
Joined: Wed Oct 04, 2006 4:50 pm
Location: USA

Re: Twbrowse - error : Bound array access

Postby James Bott » Thu Jul 07, 2011 6:26 am

Jose,

I expect the N is either nRow or ::nColPos. However, since the error is not easy to generate, it will be very hard to find.

Perhaps it would be easier to switch to using xBrowse instead.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Twbrowse - error : Bound array access

Postby Demont Brecht » Fri Jul 08, 2011 9:26 am

driessen wrote:Hello,

If the value "oLbx:nAt" in a listbox, containing an array, gets a value which is higher then the length of the array, a bound array error occurs.

Is there no possibility to change the Twbrowse class in this way : when "oLbx:nAt" gets a value which is higher then the length of the array in the listbox, "oLbx:nAt" is automatically set to the length of the array. This would prevent the bound array error to occur.

My only problem : I know to little about classes to build this change.

Thank you very much in advance for any help.


Michel ,

It seems to me that we have to add a method in tcbrowse. It can be done without changing the source from tcbrowse . In the init procedure or in the main module you can :

EXTEND CLASS <ClassName> WITH ;
[ MESSAGE <MessageName>] METHOD <FunctionName>

Or , without this define

__ObjAddMethod(TCBrowse,"DelRow",@DelRow())

Then you can make a function :

Function Delrow()

LOCAL Self := HB_QSelf()
LOCAL Array := aDel(::aArray,::nAt,.T.) // Third parameter extension from xharbour
// IF LEN(Array) == 0 , create a empty array element
::SetArray(Array)
::Refresh()
RETURN nil

After that you can call this like

tcbrowse:Delrow()
Demont Brecht
 
Posts: 55
Joined: Fri Jul 08, 2011 6:43 am

Re: Twbrowse - error : Bound array access

Postby James Bott » Fri Jul 08, 2011 11:23 am

Michel,

If you are positioned on the last line of the array, and you delete this line, then you always have to take care about oLbx:nAt because otherwise the bound error array occurs. To my opinion that should be checked in the class itself.


The problem is that nAt occurs 43 times in the TWBrowse class. In order to do what you suggest it would require comparing nAt with the length of the array in most of those 43 instances.

Alternately, when you write the code to delete an element of the array you can adjust the value of nAt and you only have to do this once. I will admit that the disadvantage is that you have to remember to do this.

Even with Demont's suggestion of adding a method (I like it), you still have to remember to add it each time you use TWBrowse with an array.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Rick Lipkin and 71 guests