Xojo2024R2.1: how to call method in the WebPage from within DataSource

In the DataSource method RowData used by WebListbox on WebPage “myWebPage1” I can have the following code:

myWebPage1.MyMethodName

Is there a way to make the above code more generic either by:

  • using class/method name redirection
    or
  • using some other technique like using this pseudo code: Parent.MyMethodName ?

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.

It is showing up here for a WebPage in 2024r2.1.

3 Likes

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.

Greg, thank you very much, I need to fully understand and digest what you have suggested. Thanks again.