如何在 Xojo 上动态访问子类的 属性?
How can I access a property of a subclass on Xojo dynamically?
在 Xojo WebApp 上,我创建了一个 TextFieldClass
和 属性 "required as boolean"。
在网页上,我有一些 TextFieldClass
个对象。
我想做的很简单……我想在网页上做一个self.ControlCount
,检查是否所有textFieldClass
都符合要求属性和"true"值其实里面有内容。
简单吧?…
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
感谢您的帮助!
试试这个:
c = TextFieldClass(self.ControlAtIndex(i))
你们真的很亲密。由于 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
在 Xojo WebApp 上,我创建了一个 TextFieldClass
和 属性 "required as boolean"。
在网页上,我有一些 TextFieldClass
个对象。
我想做的很简单……我想在网页上做一个self.ControlCount
,检查是否所有textFieldClass
都符合要求属性和"true"值其实里面有内容。
简单吧?…
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
感谢您的帮助!
试试这个:
c = TextFieldClass(self.ControlAtIndex(i))
你们真的很亲密。由于 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