|
Post by Roger Cabo on Jul 5, 2022 16:58:39 GMT 1
Hi everyone, mostly I know what I'm doing! I have some data that repeat for X times. And they should shown in a controls set.
With this code I can create 10 command buttons:
___________ Form frm1 = "any form", 0, 0, 500, 500 Dim i%, m%=10 For i% = 0 To m% OcxOcx frm1 Command puhh(i) = "1", 200, 100 + i * 25, 200, 20 Next i%
Do Sleep Loop until me is nothing _________
But how to delete the last Button "Command puhh(10)" at runtime? Or the complete Command puhh() array?
The reason is: Sometimes my database require more or less buttons at runtime.
|
|
|
Post by (X) on Jul 6, 2022 13:52:18 GMT 1
This is a crude demo of how to delete or make buttons invisble and visible again.
$Library "gfawinx" $Library "UpdateRT" UpdateRuntime ' Patches GfaWin23.Ocx LoadForm frm1
Dim i%, m% = 10 For i% = 0 To m% OcxOcx frm1 Command puhh(i) = Str(i), 10, 10 + i * 25, 200, 20 puhh(i).ToolTipText = "Shift-Click to remove." Next i%
Do Sleep Loop Until Me Is Nothing
Proc P_RemoveButtonIndex(i) If chk_Delete '''''''''''''''''''''''''''''''''''''''''''''''''' ' This deletes the specified control ' Set puhh(i) = Nothing Else puhh(i).Visible = False EndIf Local c As Control For Each c In frm1.Controls If TypeOf(c) Is Command Debug "c.name: "; c.name,"c.index:";c.index EndIf Next
Sub puhh_Click(index%) Trace index Trace MouseK If MouseKB And 1 P_RemoveButtonIndex(index) If chk1 P_ReorderButtons EndIf
Sub frm1_MouseUp(Button&, Shift&, x!, y!) If Button = 2 P_ReorderButtons EndIf
Proc P_ReorderButtons Local by = 10 Local by_inc = 25 Local c As Control For Each c In frm1.Controls If TypeOf(c) Is Command If (c.visible) c.left = 10 c.top = by by += by_inc EndIf EndIf Next
Sub lbl1_Click Local by = 10 Local by_inc = 25 Local c As Control For Each c In frm1.Controls If TypeOf(c) Is Command c.left = 10 c.top = by by += by_inc c.visible = True EndIf Next
|
|
|
Post by Roger Cabo on Jul 8, 2022 14:30:27 GMT 1
Thank you very much X! Before I use this behavior, I will create and destroy 100 controls and do this 1000 times. Perhaps there are any GC leaks or crash issues.
|
|
|
Post by Roger Cabo on Jul 8, 2022 17:42:28 GMT 1
I wrote a small ocx stress test. Some of the Memory is a bit leaking. It's not much. The result is anyway fine. If you have a lot of controls to reposition and redraw, you should use the SendMessage command before and after. Otherwise it could be possible GB32 could crash on heavily resizing the a form.
I did not experienced any crash with SendMessage(). Without SendMessage() and heavy resizing a main from and repositioning a lot controls, gb32 crash sometimes.
Here is a small test code: Open the taskmanager (onTop) and resize a bit to fit both on the screen.
$Library "gfawinx" $Library "UpdateRT" UpdateRuntime ' Patches GfaWin23.Ocx
Form frm1 = "any form", 0, 0, 1900, 550 OcxOcx frm1 Command cdo = " Do" , 0, 0, 100, 25 OcxOcx frm1 CheckBox ckb = " Enable WM_SETREDRAW" , 0, 25, 200, 25
Do Sleep Loop Until Me Is Nothing
Sub cdo_Click C0(2000) EndSub
Proc HideRedraw If (ckb.Value) ~SendMessage(frm1.hWnd, WM_SETREDRAW, 0, 0) EndIf
Proc ShowRedraw If (ckb.Value) ~SendMessage(frm1.hWnd, WM_SETREDRAW, 1, 0) ~RedrawWindow(frm1.hWnd, Null, Null, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN) EndIf Proc C0(c%) Dim i% HideRedraw() For i = 0 To c frm1.Caption = "Create " & Str$(i) OcxOcx frm1 TextBox puhh(i) = "1", Random(1800), Random(500), 200, 20 puhh(i).BorderStyle = 0 puhh(i).Appearance = 0 puhh(i).BackColor = RGB(Random(255), Random(255), Random(255)) DoEvents Next i ShowRedraw() DoEvents HideRedraw() For i = 0 To c Step 1 frm1.Caption = "Delete " & Str$(i) Set puhh(i) = Nothing Next i% ShowRedraw() DoEvents HideRedraw() For i = 0 To c frm1.Caption = "Create " & Str$(i) frm1.Caption = Str$(i) OcxOcx frm1 TextBox puhh(i) = Random(100), Random(1800), Random(500), 200, 20 puhh(i).BorderStyle = 0 puhh(i).Appearance = 0 puhh(i).BackColor = RGB(Random(255), Random(255), Random(255)) frm1.Caption = "Delete " & Str$(i) Set puhh(i) = Nothing DoEvents Next i ShowRedraw() DoEvents
|
|
|
Post by Roger Cabo on Jul 8, 2022 17:56:26 GMT 1
This is a crude demo of how to delete or make buttons invisble and visible again.
Try the following: Simply add a command button to the main form then start and delete Button Command(9). I got a OLE error. Did you have the same issue?
Attachments:
|
|
|
Post by (X) on Jul 9, 2022 0:47:15 GMT 1
This catches the error... Local c As Control For Each c In frm1.Controls If TypeOf(c) Is Command Try Debug "c.name: "; c.name,"c.index:";c.index Catch EndCatch EndIf Next The '.index' property does not exist for a non-indexed* control...
* As opposed to an indexed control array: "<some_control>(<some_index>).index".
|
|