Dynamic dbForms
<< Back
There are a couple of small details you need to pay attention to when dynamically creating/destroying dbForms
- When creating dbForms dynamically, try to call Bind_Data before End_Object, or you will have to call "End_Construct_Object" manually (which is highly discouraged!)
- When destroying dbForms dynamically, please remove the dbForm from its server before destroying it, or your program WILL crash randomly.
Here is a full-blown sample using the Order Entry's customer table.
Use DfAllEnt
Open "Customer.dat" as Customer
Object oPanel is a Panel
Set Size to 300 500
Object oClient is a ClientArea
Activate_View Activate_oTestView for oTestView
Object oTestView is a dbView
Set Size to 300 300
Property Handle[] phForms
Object oDD is a DataDictionary
Set Main_File to Customer.File_Number
Set Ordering to 1
End_Object
Set Server to (oDD(Self))
Set Main_DD to (oDD(Self))
Procedure CreateForm Integer iField Integer iY String sLabel
Handle[] hForms
Handle hForm
Object oForm Is A dbForm
Move Self to hForm
Set Label to sLabel
Send Bind_Data Customer.File_Number iField
Set Server to (oDD(Self))
Set Location to iY 100
Set Size to 20 100
End_Object
Send Activate of hForm
Get phForms to hForms
Move hForm to hForms[SizeOfArray(hForms)]
Set phForms to hForms
End_Procedure
Procedure DestroyForms
Handle[] hForms hBlanks
Handle hServer
Integer iCount
Get phForms to hForms
Move (SizeOfArray(hForms)) to iCount
While (iCount > 0)
Decrement iCount
Get Server of hForms[iCount] to hServer
Send Remove_User_Interface of hServer hForms[iCount]
Send Destroy of hForms[iCount]
Loop
Set phForms to hBlanks
End_Procedure
Object oButton is a Button
Set Label to "Create"
Procedure OnClick
Send CreateForm Field Customer.Customer_Number 50 "Number"
Send CreateForm Field Customer.Name 70 "Name"
Send CreateForm Field Customer.Address 90 "Address"
End_Procedure
End_Object
Object oButton is a Button
Set Label to "Destroy"
Set Location to 0 50
Procedure OnClick
Send DestroyForms
End_Procedure
End_Object
End_Object
End_Object
End_Object
Send Activate_oTestView of (oClient(oPanel(Self)))
Start_UI