Differenze tra le versioni di "Verificare l'esistenza di un Controllo in un Contenitore"
Da Gambas-it.org - Wikipedia.
Riga 7: | Riga 7: | ||
Public Sub Button1_Click() | Public Sub Button1_Click() | ||
− | If Object.IsValid(FMain["<FONT color=gray>'' | + | If Object.IsValid(FMain["<FONT color=gray>'''''Variabile'''_del_Controllo''</font>"]) Then |
Print "L'oggetto è presente nel Form !" | Print "L'oggetto è presente nel Form !" | ||
Endif | Endif | ||
Riga 67: | 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 | ||
Riga 79: | Riga 79: | ||
For Each ob In Me.Children | For Each ob In Me.Children | ||
− | If ob.Name = "<FONT color=gray>'' | + | If ob.Name = "<FONT color=gray>'''''Variabile'''_del_Controllo''</font>" Then |
Print "L'oggetto è presente nel Form !" | Print "L'oggetto è presente nel Form !" | ||
Endif | Endif |
Versione delle 09:35, 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_del_Controllo" 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