When using the FileOpenSave dialog and using the Visu_FbFileListProvider FB as an In/Output I could not manage to detect the difference of pressing the "Load" button on the dialog vs. pressing the "Cancel" button. In both cases, the selected file is updated if the dialog is closed when checking using the Visu_FbFileListProvider.GetSelectedFileName() command.
How can I prevent reading or writing of a file when the "Cancel" button was pressed?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Maybe there is a better way, but a long time ago I created a test application that worked like this:
With a button I opened the dialog and I added a "Input configuration - OnDialogClosed" "Execute ST-Code" action to this same button which called the following Function when the dialog was closed:
F_OnFileDialogClosed(pClientData);
Below this Function which handled the result:
// This function is called from the visualization when the dialog is closed.FUNCTIONF_OnFileDialogClosed:BOOLVAR_INPUTpClientData:POINTERTOVisuElems.VisuStructClientData;END_VARVARdialogMan:VisuElems.IDialogManager;FileOpenCloseDialog:VisuElems.IVisualisationDialog;result:VisuElems.Visu_DialogResult;_sFileName:STRING(255);END_VAR
// the DialogManager is provided via the implicitly available VisuManagerdialogMan:=VisuElems.g_VisuManager.GetDialogManager();IFdialogMan<>0ANDpClientData<>0THENFileOpenCloseDialog:=dialogMan.GetDialog('VisuDialogs.FileOpenSave');// gets the FileOpenSave dialogIFFileOpenCloseDialog<>0THENresult:=FileOpenCloseDialog.GetResult();// gets the result (OK, Cancel) of the dialogIFresult=VisuElems.Visu_DialogResult.OKTHEN// Original codegvlFile.FileListProvider();_sFileName:=CONCAT(gvlFile.FileListProvider._stDirectory,gvlFile.FileListProvider.stFile);// do something with this file name...END_IFEND_IFEND_IF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for your response! It seems like the VisuElems library has updated functions to the ones you used but apparently these older ones still work, even if I couldn't find them in the library documentation and they are also not suggested automatically by Codesys (when using Ctrl + Space).
However, its precisely what I was looking for and it works. Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When using the FileOpenSave dialog and using the
Visu_FbFileListProvider
FB as an In/Output I could not manage to detect the difference of pressing the "Load" button on the dialog vs. pressing the "Cancel" button. In both cases, the selected file is updated if the dialog is closed when checking using theVisu_FbFileListProvider.GetSelectedFileName()
command.How can I prevent reading or writing of a file when the "Cancel" button was pressed?
Maybe there is a better way, but a long time ago I created a test application that worked like this:
With a button I opened the dialog and I added a "Input configuration - OnDialogClosed" "Execute ST-Code" action to this same button which called the following Function when the dialog was closed:
F_OnFileDialogClosed(pClientData);
Below this Function which handled the result:
Thanks for your response! It seems like the VisuElems library has updated functions to the ones you used but apparently these older ones still work, even if I couldn't find them in the library documentation and they are also not suggested automatically by Codesys (when using Ctrl + Space).
However, its precisely what I was looking for and it works. Thanks!