Hi, guys.
Is there any appropriate way to get the result of the Cancel button being pressed in the opened dialog?
I've tried to add the following code in CU 412, before calling ShowOpen or ShowSave methods:
CommonDialogControl.CancelError := TRUE;
But the resulting message is so ugly. :shock:
Microsoft Dynamics NAV Classic
This message is for C/AL programmers:
The call to member ShowSave failed. CommonDialog returned the following message:
Cancel was selected.
Of course I could rely on the fact that in case the result returned by CommonDialogManagement.OpenFile is equal to DefaultFileName then the Cancel was pressed. This works great in case FileName is just the file name without the path.
FileName := EIEHeader."File Name";
WorkBookPath := ComDialogMgt.OpenFile('',FileName,4,Text027,1);
//this is supposed to be Cancel
IF WorkBookPath = FileName THEN
EXIT;
But in my case FileName is predefined by the user during setup and it can contain the full path to the file. For example like this: C:\Users\Public\50162. And this path should be opened by default.
Thus when I open the dialog, FileName = C:\Users\Public\50162 and just press Save then the returned WorkBookPath = C:\Users\Public\50162 - the system just stops executing the code, because WorkBookPath = FileName.
In case I remove this code:
//this is supposed to be Cancel
IF WorkBookPath = FileName THEN
EXIT;
The above scenario works fine but when I press Cancel in the opened dialog, the system proceeds with saving/opening the file.
I would appreciate any ideas on the issue described.
Answers
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
you can use the "IF codeunit.run then" trick...search mibuso for "if codeunit.run"...this should do the work for you
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Exactly.
I'm not sure how this can help. Can you please clarify what do you mean? Do you suggest to modify Common Dialog Management CU?
For now the only solution I've seen and that is used around in NAV is that FileName parameter passed to the ComDialogMgt.OpenFile or ComDialogMgt.OpenFileWithName is blank. Thus it is easy to handle the situation with Cancel button being pressed like this:
and the variable FileName isn't BLANK at the begin, then the WorkBookPath isn't empty. It has then the value of FileName. So, if WorkBookPath = FileName then the user press cancel.
Hi, garak.
Yes, and that's the problem in my case. FileName is predefined by the user in a setup form and it is never empty in my code. If I had FileName = '' all the time before OpenFile is run I woul never start this thread.
create a function in codeunit 412: add this code to cu412.openfile function:
create a new codeunit with a getparameter function in it: pass to this function all the necessary parameters you need for codeunit 412; in the code of this function, flush all these parameters to global variables.
in the onrun of this codeunit:
then in your source code, instead of calling the standard codeunit412, call:
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Also u can modify the CU412 to use the CancelError(BOOL) function of the "Microsoft Common Dialog Control".
http://msdn.microsoft.com/en-us/library/aa226974(VS.60).aspx
regards
Thanks, Belias. I've got the idea and going to try it.
Thanks, garak. If FileName = WorkBookPath - in my code means that user decided not to change the default path he had already set up, and wants to save it to FileName path. But in case I use IF FileName = WorkBookPath THEN EXIT statement, I will not be able to save it to the default path.
Also thanks for the link.
Regards
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
copy it, the forum cut the .asp, and paste it in the address field of your browser.
Here the Link that should work:
http://msdn.microsoft.com/en-us/library/aa226974(VS.60).aspx
Use the updated one : http://msdn.microsoft.com/en-us/library/aa226974(VS.60).aspx
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Regards.
@Sl1m4er: if you found it is a good solution for you and your problem is solved, please edit the first post and set there the attribute (it's on top).
Your suggestion to use wrapper around 412 CU worked for me great! \:D/
Thank you for your help once again. I really appreciate it.