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?
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:
Below this Function which handled the result:
// This function is called from the visualization when the dialog is closed.
FUNCTION F_OnFileDialogClosed : BOOL
pClientData : POINTER TO VisuElems.VisuStructClientData;
dialogMan : VisuElems.IDialogManager;
FileOpenCloseDialog : VisuElems.IVisualisationDialog;
result : VisuElems.Visu_DialogResult;
_sFileName : STRING(255);
// the DialogManager is provided via the implicitly available VisuManager
dialogMan := VisuElems.g_VisuManager.GetDialogManager();
IF dialogMan <> 0 AND pClientData <> 0 THEN
FileOpenCloseDialog := dialogMan.GetDialog('VisuDialogs.FileOpenSave'); // gets the FileOpenSave dialog
IF FileOpenCloseDialog <> 0 THEN
result := FileOpenCloseDialog.GetResult(); // gets the result (OK, Cancel) of the dialog
IF result = VisuElems.Visu_DialogResult.OK THEN
// Original code
_sFileName := CONCAT(gvlFile.FileListProvider._stDirectory, gvlFile.FileListProvider.stFile);
// do something with this file name...
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!
Log in to post a comment.