Differenze tra le versioni di "Verificare l'esistenza di un Controllo in un Contenitore"
Da Gambas-it.org - Wikipedia.
(Creata pagina con "Analizzeremo il caso in cui si debba verificare l'esistenza di un Oggetto grafico su un ''Form'', e l'esistenza di un Oggetto grafico a sé stante privo di ''genitore''. =Veri...") |
|||
Riga 16: | Riga 16: | ||
Public Sub Button1_Click() | Public Sub Button1_Click() | ||
− | If Object.Is(<FONT color=gray>'' | + | Dim ob As Object |
− | + | ||
− | + | For Each ob In Me.Children | |
+ | If Object.Is(ob, "<FONT color=gray>''Nome_della_'''Classe'''_dell'Oggetto''</font>") Then | ||
+ | Print "L'oggetto è presente nel Form !" | ||
+ | Endif | ||
+ | Next | ||
End | End | ||
Riga 28: | Riga 32: | ||
For Each ob In Me.Children | For Each ob In Me.Children | ||
− | If ob Is "<FONT color=gray>'' | + | If ob Is "<FONT color=gray>''Nome_della_'''Classe'''_del_Controllo''</font>") Then |
Print "L'Oggetto è presente nel Form !" | Print "L'Oggetto è presente nel Form !" | ||
Endif | Endif | ||
Riga 41: | Riga 45: | ||
For Each ob In Me.Children | For Each ob In Me.Children | ||
− | If Object.Class(ob).Name = "<FONT color=gray>'' | + | If Object.Class(ob).Name = "<FONT color=gray>''Nome_della_'''Classe'''_del_Controllo_cercato''</font>" Then |
Print "L'Oggetto è presente nel Form !" | Print "L'Oggetto è presente nel Form !" | ||
Endif | Endif | ||
+ | Next | ||
+ | |||
+ | End | ||
+ | |||
+ | ===Usando Object.Type()=== | ||
+ | |||
+ | Public Sub Button1_Click() | ||
+ | |||
+ | Dim ob As Object | ||
+ | |||
+ | For Each ob In Me.Children | ||
+ | If Object.Type(ob) = "<FONT color=gray>''Nome_della_'''Classe'''_del_Controllo_cercato''</font>" Then Print "L'Oggetto è presente nel Form !" | ||
Next | Next | ||
Riga 51: | Riga 67: | ||
Public Sub Button1_Click() | Public Sub Button1_Click() | ||
− | If IsNull(Me.Controls["<FONT color=gray>'' | + | If IsNull(Me.Controls["<FONT color=gray>''Nome_della_variabile_del_Controllo''</font>"]) = False Then |
Print "L'Oggetto è presente nel Form !" | Print "L'Oggetto è presente nel Form !" | ||
Endif | Endif |
Versione delle 09:29, 12 dic 2023
Analizzeremo il caso in cui si debba verificare l'esistenza di un Oggetto grafico su un Form, e l'esistenza di un Oggetto grafico a sé stante privo di genitore.
Indice
Verifica sul form principale
Per verificare l'esistenza di oggetto su un Form, possiamo adottare almeno tre modalità:
Usando Object.IsValid()
Public Sub Button1_Click() If Object.IsValid(FMain["Variabile_del_Controllo"]) Then Print "L'oggetto è presente nel Form !" Endif End
Usando Object.Is()
Public Sub Button1_Click() Dim ob As Object For Each ob In Me.Children If Object.Is(ob, "Nome_della_Classe_dell'Oggetto") Then Print "L'oggetto è presente nel Form !" Endif Next End
Usando Is
Public Sub Button1_Click() Dim ob As Object For Each ob In Me.Children If ob Is "Nome_della_Classe_del_Controllo") Then Print "L'Oggetto è presente nel Form !" Endif Next End
Usando Object.Class().Name
Public Sub Button1_Click() Dim ob As Object For Each ob In Me.Children If Object.Class(ob).Name = "Nome_della_Classe_del_Controllo_cercato" Then Print "L'Oggetto è presente nel Form !" Endif Next End
Usando Object.Type()
Public Sub Button1_Click() Dim ob As Object For Each ob In Me.Children If Object.Type(ob) = "Nome_della_Classe_del_Controllo_cercato" Then Print "L'Oggetto è presente nel Form !" Next End
Usando IsNull()
Public Sub Button1_Click() If IsNull(Me.Controls["Nome_della_variabile_del_Controllo"]) = False Then Print "L'Oggetto è presente nel Form !" Endif End
Usando la Proprietà ".Name" dei Controlli
Public Sub Button1_Click() Dim ob As Object For Each ob In Me.Children If ob.Name = "Variabile_dell'Oggetto" Then Print "L'oggetto è presente nel Form !" Endif Next End
Verifica di un oggetto a sé stante senza Genitore
Poniamo il caso di un Oggetto di tipo Window senza genitore, creato ad esempio così:
Private w As Window Public Sub Form_Open() With w = New Window As "w" .W = 100 .H = 200 .X = 300 .Y = 300 .Background = Color.Yellow .Show End With End
Ne potremo verificare l'esistenza come segue:
Public sub Button1_Click() ' All'interno della funzione "Object.IsValid()" verrà inserita la variabile del tipo dell'oggetto a sé stante, del quale cui si vuole verificare l'esistenza: If Object.IsValid(w) Then Print "Oggetto esistente !" End