You can make the WebPage itself implement the data source interface, and set the data source to the WebPage. This is how I built ARGen to make Web 2.0 DataSource containers.
If you use the WebPage as the WebDataSource instead of a class or module, you have access to things on the page. At least that was the theory behind the decision with ARGen. It has honestly been quite some time since I’ve looked into WebDataSource.
The other thing you could do is to create a WeakRef on your DataSource class that points to the parent control. Which you set when you create it. You would need to do some casting or make an interface to make it truly generic.
Private Property mParent as WeakRef
Computed Property Parent as WebPage
Get
If mParent = Nil or mParent.Value = Nil then
Return nil
End if
Return WebPage(mParent.Value)
End Get
Sub Constructor(parent as WebPage)
mParent = parent
End Sub
As I mentioned, you could use a custom Class Interface instead and just replace Webpage with YourCustomInterface instead if there’s only a few things that the DataSource should be able to do. Otherwise, your usage will need to be something like this:
Var p as WebPage = Self.Parent
If p <> Nil then
Select case p
Case IsA WebPage1
WebPage1(p).PublicMethodOnWebpage1
Case IsA YourCustomInterface
YourCustomInterface(p).InterfaceMethod
End Select
End If
Interfaces also give you the advantage that the methods don’t need to be public.