Bug in ADEL() ?

Issues and Discussions related to Harbour

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Bug in ADEL() ?

Post by serge_girard »

Hello all,

Should the function ADEL() change the LEN of the array?
AADD does but ADEL doesn't:

Code: Select all

#include <hmg.ch>
#include <Dbstruct.ch>

SET PRINTER TO debug.TXT 
SET PRINTER ON 
SET CONSOLE OFF

aDbf := {}
FOR A = 1 TO 10
	cF = 'F' + ALLTRIM(STR(A))
	AADD(aDbf, { cF, "C", 5, 0 })
NEXT A
DBCREATE("TESTARR", aDbf)

USE TESTARR NEW
aStruct := TESTARR->(DBSTRUCT())

FOR j := 1 To len(aStruct)
	? STR(j) + ' ' + aStruct [j] [1] + ' ' + aStruct [j] [2] + ' ' + STR(aStruct [j] [3]) + ' ' + STR(aStruct [j] [4])
NEXT j

? STR(LEN(aStruct)) +   ' Before AADD ->LEN(aStruct)' 
AADD(aStruct,{'XX','C',5, 0})
? STR(LEN(aStruct)) +   ' After AADD  ->LEN(aStruct)' 

? '----------------------------------------' 
? STR(LEN(aStruct)) +   ' Before ADEL ->LEN(aStruct)' 
nPOS = 3
ADEL(aStruct, nPOS)      
ADEL(aStruct, nPOS)      
ADEL(aStruct, nPOS)      
? STR(LEN(aStruct)) +   ' After ADEL  ->LEN(aStruct)' 
FOR j := 1 To len(aStruct)  // gives Error BASE/1068 Argument error: array access
	? STR(j) + ' ' + aStruct [j] [1] + ' ' + aStruct [j] [2] + ' ' + STR(aStruct [j] [3]) + ' ' + STR(aStruct [j] [4])
NEXT j

SET PRINTER TO  
SET PRINTER Off
SET CONSOLE On
Anybody any idea?

Thx, Serge
[u]Moderator Notes[/u] (Pablo César) wrote:Topic moved from Forum Help.
Please note this issue is a Harbour matter and the section of "Forum Help" is used to let suggestions and claims, not for techinicals proposes of HMG or Harbour.
There's nothing you can do that can't be done...
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Bug in ADEL() ?

Post by Pablo César »

I think the name ADEL is rather misleading, since the function does NOT actually delete elements, but rather nullifies them, and you have to use asize()[*] to achieve what you probably wanted to do. Perhaps ANUL() would be a more precise name but i think it's a little late now to rename it.

ADEL() does delete the element, it just doesn't resize the array, so you will always get a NIL at the end of the array. It's not the same as 'array[ n ] := NIL'.

Try to use AKill(aStruct, nPOS), but put at begging of prg file:

#translate AKill( <a>, <e> ) => ASize( ADel( <a>, <e> ), Len( <a> ) - 1 )
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Bug in ADEL() ?

Post by serge_girard »

Thank you Pablo, it is working!
There's nothing you can do that can't be done...
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Bug in ADEL() ?

Post by Rathinagiri »

adel() function deletes a particular item and all the items behind will be pushed forward and the last array element is made nil. Pablo's function is neat and simple.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Bug in ADEL() ?

Post by serge_girard »

Yes it is!

Thx, Serge
There's nothing you can do that can't be done...
Carlos Britos
Posts: 245
Joined: Sat Aug 02, 2008 5:03 pm

Re: Bug in ADEL() ?

Post by Carlos Britos »

serge_girard wrote:Hello all,

Should the function ADEL() change the LEN of the array?
AADD does but ADEL doesn't:
Hi,
try with hb_ADel( aArray, nPos, .T. )
Regards/Saludos, Carlos (bcd12a)
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Bug in ADEL() ?

Post by esgici »

Carlos Britos wrote:
serge_girard wrote: Should the function ADEL() change the LEN of the array?
AADD does but ADEL doesn't:
try with hb_ADel( aArray, nPos, .T. )
Harbour ChangLog; 2012-09-04] wrote:
use: hb_ADel( <aVal>, <nPos>, .t. )
instead of: ADel( <aVal>, <nPos> ); ASize( <aVal>, Len( <aVal> ) - 1 )
Or simply use ADEL() with 3.th parameter and #include "hbcompat.ch"

Code: Select all

ADel( aArray, nPos, .T. )
Sample:

Code: Select all

#include "hbcompat.ch"
a1 := { 1,2,3,4,5 }
ADel( a1, 3, .T. )
AEval( a1, { | x1, i1 | QOUT( i1, x1 ) } )
NOTE : HB_ADel() not requires #include "hbcompat.ch"
Viva INTERNATIONAL HMG :D
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Bug in ADEL() ?

Post by serge_girard »

I'll try things tomorrow !

Thx all, Serge
There's nothing you can do that can't be done...
Post Reply