@Shield,
It's a big program, so I've taken a pair of scissors to make an illustration... it does not run, but shows the idea.
I create a new Structure() as uGrid's are created and displayed. Often they are on child windows and are only transient (like a requester).
When the window is closed I want to get rid of the uGrid as well.
Please excuse any errors... done in haste!
Code: Select all
; This is a demo of what I'm trying to do... do not run me!
Procedure uGridGadget(GadNum.i,gX,Gy,width,height,ColTitles.s,RowCount,flags) ; Create a new MicroGrid
If GridCount > 1
Redim uGrid(GridCount)
EndIf
; Create memory block for CELL data
*P = AllocateMemory(SizeOf(uG) * ColCount * RowCount)
If *P = 0 : ProcedureReturn 0 : EndIf
; Save essential data of the new GRID
With uGrid(GridCount)
\GridWin = GetActiveWindow()
\GridCellPointer = *P
\GridColCount = ColCount
\GridRowCount = RowCount
\GridBackImage = CreateImage(#PB_Any,\GridPixW+2,\GridPixH+2)
\GridDataImage = CreateImage(#PB_Any,\GridPixW+2,\GridPixH+2)
; etc etc ... about 34 items
EndWith
GridCount + 1
EndProcedure
Until now I have created all the transient windows and manage their visibility with HideWindow(). I'm not too keen on this because it (1) is not a good general solution, (2) I have to allocate resources to items that may not get used and (3) I think it is untidy!
This is a first cut of what I'm trying to do. The code has never been run is incomplete and probably bugged... but again I think the intention is clear. I'm now wondering if the Redim() does what I want in this case... but this is not the only instance of the problem!
Code: Select all
Procedure uGridDeleteGrid(GadNum) ; UNFINISHED - Work in progress - NOT TESTED
Protected Gr,n,T,
Gr = uGridGetGridIndex(GadNum) ; Find index of uGrid in grid table
If Gr =-1 : ProcedureReturn 0 : EndIf ; Not found.
; Ensure associated canvas does not have focus
; ???
; Free resources
With uGrid(Gr)
FreeImage(\GridBackImage) ; Free bitmaps
FreeImage(\GridDataImage)
; Free strings associated with every individual CELL
*P = \GridCellPointer ; Pointer to first CELL
For T = 1 To \GridRowCount * \GridColCount
*CellDat.CELLOPTIONS = *P
ClearStructure(*P,CELLOPTIONS) ; String pointers =>0, Numbers => 0
*P + SizeOf(uG) ; Pointer to next CELL
Next
FreeMemory(\GridCellPointer) ; Free grid data memory
FreeGadget(\GridPBNum) ; Destroy CanvasGadet()
EndWith
ClearStructure(@uGrid(Gr),GRIDOPTIONS) ; Free any strings etc..
; Shuffle table shut... ???
If Gr ???
For n = Gr To GridCount - 1
CopyStructure(@uGrid(n+1),@uGrid(n),GRIDOPTIONS)
Next
EndIf
; Eliminate the top item
If GridCount > 1 ; Re-dim table one smaller
GridCount - 1 ; Decrease number of grids
Redim uGrid(GridCount)
EndIf
EndProcedure
You can see the whole project if you search for uGrid on this site.
Cheers,
RichardL