What is the purpose of the "Result" of a Dialog

If you create a dialog (eg. OpenDialog) you get a Result, and you can use it, but you still have to declare a FolderItem and set that to the return of the Dialog.

Correct code from the LR
Var dlg As OpenFileDialog
Var f As FolderItem
dlg = New OpenFileDialog
#If Not TargetLinux Then
dlg.InitialFolder = SpecialFolder.Documents
#Else //open Home directory on linux
dlg.InitialFolder = SpecialFolder.Home

dlg.Title = "Select a Text file"
dlg.Filter = FileTypes1.Text  // "text/plain" file type defined in FileTypes1 set
f = dlg.ShowModal
If f <> Nil Then
  //proceed normally
  //User Cancelled
End If

Incorrect Code example
dlg.result = dlg.ShowModal

I have read the LR but can’t find a use for it, So Why is it there?

(P.S. Grumble. I cannot get it to completely mark stuff as code)

try a empty line between

the example here looks odd, i agree

ShowModal returns a FolderItem. dlg.Result is a read-only property of type FolderItem. I agree, they seem redundant.

That statement is, as you pointed out, incorrect. The inner mysteries of the dialog are what actually assign the value to dlg.result, not you. You might have a variable with the name result (appropriately typed for the type of value the dialog returns). So, if your dialog returns a folderitem, the variable type for result must be Folderitem.

Var result As FolderItem
result = dlg.ShowModal

Maybe you could do

Call dlg.ShowModal
f = dlg.Result

if you really want to use that Result property :slight_smile:

i guess it is prepared for use non Modal.

1 Like

I find an empty line before, and also AFTER, helps. You should then select everything including these two empty lines and use the </>.

Is this worthy of filing a feedback for improvement code, as in making Result more usable?

Ask for a documentation improvement to describe under what conditions one might use dlg.result.

1 Like

The example is:

[Var](https://documentation.xojo.com/api/language/var.html) dlg [As](https://documentation.xojo.com/api/language/as.html) OpenDialog
[Var](https://documentation.xojo.com/api/language/var.html) f [As](https://documentation.xojo.com/api/language/as.html) FolderItem
dlg = [New](https://documentation.xojo.com/api/language/new.html) OpenDialog
dlg.PromptText = "Select a file"
f = dlg.ShowModal
[If](https://documentation.xojo.com/api/code_execution/if.html...Then...Else) dlg.Result <> [Nil](https://documentation.xojo.com/api/language/nil.html) [Then](https://documentation.xojo.com/api/code_execution/if.html...Then...Else)
MessageBox("You selected: " + dlg.Result.NativePath)
// User Cancelled
[End If](https://documentation.xojo.com/api/code_execution/if.html...Then...Else)

I don’t see dlg.result = dlg.ShowModal in the doc !!!