FreeGadget issue

Just starting out? Need help? Post your questions and find answers here.
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

FreeGadget issue

Post by eck49 »

I have a Window which includes a ContainerGadget which is always present.

This container acts as a formatted bucket for a lot of text gadgets which are variable in number, location and content. It's a sort of situation report.

The variability makes it expedient to wipe the container clean and recreate (not reuse) the gadgets for each use. It's quick enough, there are only about 80 gadgets at the most.

But I am finding that the container is showing the old content partially overwritten by the new if the new does not cover where the old was, as is frequently the case.

This is the case despite using FreeGadget, HideGadget , even moving and miniturising the old gadgets using ResizeGadget.
Is this normal? Is it the case that FreeGadget only deletes the gadget from memory, not from the window, thus leaving the content in place?

Or have I missed something, as I often seem to?

EDIT: FreeGadget, not RemoveGadget!!! :oops:
Last edited by eck49 on Tue Jun 08, 2021 7:23 pm, edited 2 times in total.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: RemoveGadget issue

Post by IdeasVacuum »

Hi eck49

.... It would be easier and faster to use a ListIcon wouldn't it?

1) Have you tried deleting the Container?
2) Try using a Canvas as a Container.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: FreeGadget issue

Post by eck49 »

Neither a Listicon nor the various grid gadgets around would give the flexibilty of layout needed without a considerable weight of code. And execution speed isn't really an issue here.

Trying out deleting the container, I realise I this is all about FreeGadget(), not RemoveGadget. I'll revise the Thread title!

Maybe using a Canvas would work, but I think I need to understand FreeGadget better or the same thing would happen there.... or in another project.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: FreeGadget issue

Post by eck49 »

There's nothing like a good meal (and therefore a break from the computer) for sharpening the brain cells...

The problem was down to FreeGadget not being asked to free the gadgets I meant it to. So a program bug after all. Usually is, I find, when I find it.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4635
Joined: Sun Apr 12, 2009 6:27 am

Re: FreeGadget issue

Post by RASHAD »

Make sure you are using CloseGadgetList()
If Yes try to refresh the Main Window(Hidewindow(?,0))
Egypt my love
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: FreeGadget issue

Post by eck49 »

@RASHAD
No issue with the CloseGadgetList, this has been carefully managed (Open and Close always in the same procedure). Refreshing the window made no difference because PB was still aware of the gadgets which I thought had been Freed.

What was happening was that these containerised gadgets had their PB index numbers [ie what is returned from TextGadget(#PB_Any, ...)] stored in a dedicated array but, due to a subscripting error, when it came time to free them most of the array of gadgets was not being Freed as intended. Since the array was then being overwritten with the numbers relating to the replacement gadgets there would have been no longer any way of tracking down the old, now orphaned, gadgets for any purpose. Hence my frustration, but all is now sorted.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4635
Joined: Sun Apr 12, 2009 6:27 am

Re: FreeGadget issue

Post by RASHAD »

Hi eck49
Why don't you use List() instead of Array() so you can add ,delete items as you wish and on time
Egypt my love
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: FreeGadget issue

Post by eck49 »

Hi Rashad

Array works fast and easy, so I see no need to change.

There is more than one way of skinning a cat - so I'm told. Before Cats Protection get onto me, I've never tried nor wanted to!
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: FreeGadget issue

Post by skywalk »

Lists are preferred for small quantities.
This is my data structure cheat sheet.

Code: Select all

; DEF:  When to use array|list|map?
;       Map:    Unique list, no order. Text defines elements.
;               Ex. Menu items, except watch for sub-menus with same names.
;               MapSize(map()) returns base 1 count.
;               !Warning! After traversing map(), with:
;                 ForEach map() or While NextMapElement(map())
;                 Any reference to the map() will raise an error.
;                 [11:08:35] [ERROR] The Map doesn't have a current element.
;               !Remember! Move map() pointer back to top or somewhere.
;       List:   Doubly linked ordered list. Usually small and unknown size at creation.
;               Ex. Retrieving a table's contents without knowing count.
;                   Or appending to existing list without care to size.
;               ListSize(ll()) returns base 1 count.
;       Array:  When speed or list size demand.
;               ArraySize(ar()) returns base 0 count.
;
; STRUCTURE NOTES:
; ClearStructure(*Pointer, Structure)
;   Clears structured memory area. (No internal check that structure matches memory area.)
;   Useful when structure contains strings, array, list or map which have been allocated 
;   internally by PureBasic. 
;   'Structure' = structure name to clear.
;   All fields set to zero, even native type like long, integer, etc.
;   ClearStructure(m1, st1) : Dim m1\a$(10) ;<-- Requires re-initialization of structure objects.
; 
; ResetStructure(*Pointer, Structure)
;   Clears structured memory area and initializes for use.
;   Useful when structure contains strings, array, list or map which have been allocated 
;   internally by PureBasic. 
;   'Structure' = structure name to clear.
;   All fields set to zero, even native type like long, integer, etc.
;   ResetStructure(m1, st1)                 ;<-- Does NOT require re-initialization of structure objects.
;
; NOTES:  Contains general use Array|List|Map functions/subroutines
;         Array|List|Map are passed as ByRef parameters to Procedures.
;         Meaning, any changes in the Procedure affect the original array|list|map.
;         If using Shared in the Procedure or Global arrays,
;         then no need to be pass 'Array|List|Map' parameter.
;
;         To conform with C/C++ Structure format and allow direct API structure porting: 
;         Static arrays defined in structures are different than Dynamic arrays defined by Dim/ReDim.
;           a[2] allocates an array from 0 to 1.
;         But,
;           Dim a(2) allocates an array from 0 to 2.
;         And PB does NOT support multidimensional static arrays.
;           a[3][2] must be defined as product of dimensions.
;           a[3*2]
;
;         To get size of a static array use SizeOf():
;         Structure myStruc
;           aX.b[128]
;           aY.b[5]
;           s.s{32}   ; Fixed length strings are ok, but not variable length.
;         EndStructure
;         Define me.myStruc
;         Debug Sizeof(me\aX)
;         For nested Structures, use combinations of Sizeof() and Len()
;
;         Dynamic multidimensional arrays in Structures:
;         Structure MyData
;           nPts.i                ; num points
;           Array X.d(0,0)        ; (sets,nPts)
;           Array Y.d(0,0)        ; (sets,nPts)
;         EndStructure
;         Define myDat.MyData     ; Empty contents.
;         Dim myDat\X(10,10)      ; 1st Dim of structure array clears contents.
;         ReDim myDat\X(10,100)   ;<-- ReDim last index only.
;
;         Swap cmd does NOT work on entire array. Only individual elements.
;         Use CopyArray() instead.
;
;-!Array order in memory:
; Ex. Human perceived multidimensional 2D array(matrix) of 3 rows x 3 cols:
;           0  1  2 <-- Col
;       0 | 1  2  3 |   R
;       1 | 4  5  6 |   o
;       2 | 7  8  9 |   w
;
; Row-major order: (PureBasic/C/C++/Python step along col's for each row.)
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
;   |   1   |   2   |   3   |   4   |   5   |   6   |   7   |   8   |   9   |
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; 
; Col-major order: (Fortran/Matlab/VB6 step along rows for each col.)
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
;   |   1   |   4   |   7   |   2   |   5   |   8   |   3   |   6   |   9   |
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; C  2D arrays --> ar2D[nrows][ncols]
; PB 2D arrays --> ar2D(nCols-1, nRows-1)
; This allows dual access of 2D data within a 1D array or syntactical 2D(c,r) array.
; Ex. Dim ar2D(nCols-1, nRows-1) --> Dim ar1D(nCols*nRows-1)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply