Bug in ADEL() ?

Issues and Discussions related to Harbour

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 1838
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 278 times
Been thanked: 63 times
Contact:

Bug in ADEL() ?

Post by serge_girard » Sat Aug 10, 2013 12:13 pm

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.

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Sat Aug 10, 2013 1:02 pm

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: 1838
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 278 times
Been thanked: 63 times
Contact:

Post by serge_girard » Sat Aug 10, 2013 1:31 pm

Thank you Pablo, it is working!

User avatar
Rathinagiri
Posts: 5162
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 128 times
Been thanked: 130 times
Contact:

Post by Rathinagiri » Sat Aug 10, 2013 1:56 pm

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: 1838
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 278 times
Been thanked: 63 times
Contact:

Post by serge_girard » Sat Aug 10, 2013 2:25 pm

Yes it is!

Thx, Serge

Carlos Britos
Posts: 219
Joined: Sat Aug 02, 2008 5:03 pm
Has thanked: 6 times
Been thanked: 2 times

Post by Carlos Britos » Sat Aug 10, 2013 5:42 pm

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: 4337
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 221 times
Been thanked: 77 times
Contact:

Post by esgici » Sat Aug 10, 2013 6:43 pm

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: 1838
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 278 times
Been thanked: 63 times
Contact:

Post by serge_girard » Sat Aug 10, 2013 7:04 pm

I'll try things tomorrow !

Thx all, Serge

Post Reply