Page 1 of 2
Twbrowse - error : Bound array access
Posted: Fri Oct 08, 2010 1:21 pm
by driessen
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.
Re: Twbrowse - error : Bound array access
Posted: Fri Oct 08, 2010 1:47 pm
by Willi Quintana
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
Re: Twbrowse - error : Bound array access
Posted: Fri Oct 08, 2010 1:56 pm
by driessen
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.
Re: Twbrowse - error : Bound array access
Posted: Fri Oct 08, 2010 2:58 pm
by hag
Driessen:
I agree with your suggestion. A behind the senes check by oLbx: NAT is an excellent idea.
Re: Twbrowse - error : Bound array access
Posted: Fri Oct 08, 2010 5:44 pm
by James Bott
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
Re: Twbrowse - error : Bound array access
Posted: Sat Oct 09, 2010 2:05 am
by Willi Quintana
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
Re: Twbrowse - error : Bound array access and division by zero
Posted: Thu Jun 09, 2011 6:39 pm
by xhbcoder
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
Re: Twbrowse - error : Bound array access
Posted: Tue Jun 21, 2011 12:08 am
by James Bott
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.
Re: Twbrowse - error : Bound array access
Posted: Tue Jun 21, 2011 6:19 pm
by Francisco Horta
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
Re: Twbrowse - error : Bound array access
Posted: Fri Jun 24, 2011 6:02 pm
by Willi Quintana
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
Re: Twbrowse - error : Bound array access
Posted: Fri Jun 24, 2011 7:38 pm
by Antonio Linares
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
Re: Twbrowse - error : Bound array access
Posted: Thu Jul 07, 2011 5:36 am
by xhbcoder
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
Re: Twbrowse - error : Bound array access
Posted: Thu Jul 07, 2011 6:26 am
by James Bott
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
Re: Twbrowse - error : Bound array access
Posted: Fri Jul 08, 2011 9:26 am
by Demont Brecht
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()
Re: Twbrowse - error : Bound array access
Posted: Fri Jul 08, 2011 11:23 am
by James Bott
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