Common Dialog Management CU. Cancel action
 
            
                
                    Sl1m4er                
                
                    Member Posts: 42                
            
                        
            
                    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:
But the resulting message is so ugly. :shock:
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.
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:
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.
                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.
0                
            Answers
- 
            in other words, you want to catch the "Cancel" event when the user press it.
 you can use the "IF codeunit.run then" trick...search mibuso for "if codeunit.run"...this should do the work for you0
- 
            Hello, Belias.in other words, you want to catch the "Cancel" event when the user press it.
 Exactly.you can use the "IF codeunit.run then" trick...search mibuso for "if codeunit.run"...this should do the work for you
 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:WorkBookPath := ComDialogMgt.OpenFile('',FileName,4,Text027,1); IF WorkBookPath = '' THEN EXIT;0
- 
            if u use this:FileName := 'WhatIsTheInitValue?'; WorkBookPath := ComDialogMgt.OpenFile('',FileName,4,Text027,1); IF WorkBookPath = '' THEN EXIT;
 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.Do you make it right, it works too!0
- 
            garak wrote:if u use this:FileName := 'WhatIsTheInitValue?'; WorkBookPath := ComDialogMgt.OpenFile('',FileName,4,Text027,1); IF WorkBookPath = '' THEN EXIT;
 and the variable FileName isn't BLANK at the begin, then the WorkBookPath isn't empty. It has then the value of FileName.
 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. 0 0
- 
            1. create a global variable boolean in Cu 412: GlobalShowerror
 create a function in codeunit 412:---function--- globalshowerror := true add this code to cu412.openfile function:CommonDialogControl.CancelError := globalshowerror; 
 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:codeunit412.---function--- codeunit412.openfile(pass all the global variables you just flushed) 
 then in your source code, instead of calling the standard codeunit412, call:mynewcodeunit.getparameter(all pars for codeunit 412) if mynewcodeunit.run then begin //Common dialog succesful end else begin //Common dialog failed -manage the error as you want end; 0
- 
            read the last senstens
 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
 regardsDo you make it right, it works too!0
- 
            Belias wrote:1. create a global variable boolean in Cu 412: GlobalShowerror
 create a function in codeunit 412:---function--- globalshowerror := true add this code to cu412.openfile function:CommonDialogControl.CancelError := globalshowerror; 
 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:codeunit412.---function--- codeunit412.openfile(pass all the global variables you just flushed) 
 then in your source code, instead of calling the standard codeunit412, call:mynewcodeunit.getparameter(all pars for codeunit 412) if mynewcodeunit.run then begin //Common dialog succesful end else begin //Common dialog failed -manage the error as you want end; 
 Thanks, Belias. I've got the idea and going to try it.garak wrote:read the last senstens
 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, 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.0
- 
            So, you're welcome.
 RegardsDo you make it right, it works too!0
- 
            Belias wrote:
 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).aspxDo you make it right, it works too!0
- 
            0
- 
            And thats the link http://msdn.microsoft.com/en-us/library/aa259661(VS.60).aspx for the "CommonDialog Control" where all Methods and properties are described.
 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).Do you make it right, it works too!0
- 
            Belias, garak
 Your suggestion to use wrapper around 412 CU worked for me great! \:D/
 Thank you for your help once again. I really appreciate it. 0 0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 323 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions


