Webdialog.parent = nil

Hi all,

Quite new to web - and there are probably more clever ways of doing what I need, but I thought the .parent property of webdialogs would be a useful starting point, but it always returns nil…

I have webdialog that appears on different pages and actions should vary depending on which page is the “parent”. I was optimistic when I saw that webdialogs have a .parent as webview property and I perhaps naively thought this would give info on parent page, but it seems not, because it’s always nil…

There are probably errors on multiple levels (excuse my ignorance!), but putting a button on a webdialog with the code:

MessageBox(self.Parent.Page.Name)

causes a NilObjectException and inspecting the webdialog properties, webdialog.parent = nil.

Not sure I understand how parent should be used?
Many thanks
Stam

It’s used by controls on a page to determine the parent. It works fine for controls. WebDialog is a bit different, and probably has the property as a result of subclassing. It probably could be implemented, file a ticket.

Since the framework is broken, you could very easily pass your own reference in when creating the WebDialog instance. That is the way it’s been done for years before that property existed.

Is this a web dialog placed on a page or is it instantiated in code?

instantiated in code:

var wd as new MyWebDialog
wd.show

should I have this as a property of the page instead and just instantiate with ‘new’? Or is there some way to assign as a child of the page on instantiation?

Dialogs instantiated in code won’t know what their parent is, but you could add your own property and set it when you create the instance.

1 Like

literally just tried that, doesn’t work sadly - parent is still nil :frowning:

I would wildly guess you tried to set Parent and didn’t create your own property to store the reference in.

2 Likes

In your subclass, make your own property and set its value to the page, maybe like this…

property myPage as WebPage
var wd as new MyWebDialog
var myPage as WebPage = self
wd.show

and then in your dialog, you can access the myPage property to find out what page it is on.

There’s also the possibility that you could just get the current page with Session.CurrentPage.

Sorry to display my ignorance here - I am probably misunderstanding you.

What I did test: I created a property in the parent web page of type the webdialog to show (lets call it myWebDialog) in the IDE. When launching the webdialog:

myDialog = new myWebDialog
myDialog.show

This doesn’t set the parent property of myWebDialog, which remains nil, so I presume I’m not doing what is recommended.
I also presume that this is an actual bug, as the .parent property seems pointless for webdialogs.

As @Greg_O suggests, I’ll just set a property of the webdialog on call it I guess…

  1. Go to your myWebDialog class
  2. Make a property called my myPage as WebPage
  3. In your initialization code between when you create the instance and when you show it, set that property:
    MyDialog.myPage = Session.CurrentPage
1 Like

Thanks Greg, have done and it works around the .parent issue