2016-03-20 63 views
1

在Xojo WebApp上,我創建了一個TextFieldClass,其屬性爲「布爾值必需」。如何動態地訪問Xojo上的子類的屬性?

在網頁上,我有一些TextFieldClass對象。

我想要做的很簡單...我想在網頁上做一個self.ControlCount,並檢查所有帶有「true」值的屬性的textFieldClass實際上是否包含內容。 ?

容易,對不對?

Dim i as integer 
Dim c As textFieldClass 
For i=0 To self.ControlCount 
    if self.ControlAtIndex(i) isa textFieldClass then 
     **c=self.ControlAtIndex(i) // i got an error… expected class textFieldClass, but got class webObject…** 
    End If 
Next 

如果我嘗試:

Dim i as integer 
Dim c As WebObject 
For i=0 To self.ControlCount 
    if self.ControlAtIndex(i) isa textFieldClass then 
     c=self.ControlAtIndex(i) 
     **if c.required then // I got an error… Type "WebObject" has no member named "required"** 
      // do something here… 
     end if 
    End If 
Next 

感謝您的幫助!

回答

2

試試這個:

c = TextFieldClass(self.ControlAtIndex(i)) 
1

你是非常接近。由於controlAtIndex帶回RectControl,因此必須將RectControl強制轉換爲textFieldClass子類。技術上與上述相同,但有更多解釋。

Dim i as integer 
Dim c As WebObject 
For i=0 To self.ControlCount-1 //Fixes mistake in original code. 
    if self.ControlAtIndex(i) isa textFieldClass then 
     c= textFieldClass(self.ControlAtIndex(i)) //Need to cast here 
     if c.required then 
      // do something here… 
     end if 
    End If 
Next