Select a folder in Navision

kenlkenl Member Posts: 182
edited 2014-01-15 in Navision Attain
Hello,

I am trying to add assit button to select a folder in Navision. I search the forum and find the below download:

http://www.mibuso.com/dlinfo.asp?FileID=169

The download is great ! But in order to run that, I need to register the dll file. Since the download was on 2003/Jan, is there any new method for folder select in Navision 4.0 ?

Thanks

Comments

  • DenSterDenSter Member Posts: 8,281
    Use codeunit 412 - Common Dialog Management.
  • kenlkenl Member Posts: 182
    Hello,

    Thank you for your reply.

    But codeunit 412 - Common Dialog Management is for selecting a FILE. I want to select a folder.

    Any idea ?
  • kinekine Member Posts: 12,562
    The functionality is in "shell32.dll" but no functions or properties are accessible in Navision... (it is OCX, but name is localized in my version of Windows - search in table 2000000042 for SHELL32) you can create some VB wrapper for this or may be that someone made it...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,281
    I don't know how to make that work with any windows component. You could create a lookup form based on the virtual 'File' table though. Just use the form wizard and that will add an OK button for you. Set a filter on the "Is a file" field to where it is No, that should give you the folders only.

    Then you create a rec variable of subtype 'File' and call your new form to retrieve the foldername from the File variable.
  • guidorobbenguidorobben Member Posts: 157
    Name DataType Subtype Length
    WindowsShell Automation 'Microsoft Shell Controls And Automation'.Shell
    SelectedFolder Automation 'Microsoft Shell Controls And Automation'.Folder2
    FolderItem Automation 'Microsoft Shell Controls And Automation'.FolderItem
    ActiveWindow Automation 'CSideWindowCheck'.WindowCheck

    IF ISCLEAR(WindowsShell) THEN
    IF NOT CREATE(WindowsShell) THEN
    EXIT;
    IF ISCLEAR(ActiveWindow) THEN
    IF NOT CREATE(ActiveWindow) THEN
    EXIT;

    SelectedFolder := WindowsShell.BrowseForFolder(ActiveWindow.WindowHandle,FolderName,1,'');
    IF NOT ISCLEAR(SelectedFolder) THEN BEGIN
    FolderItem := SelectedFolder.Self;
    FolderName := FolderItem.Path;
    END;

    This is not my code, This will work. Instead of active window you could just use 0.

    How we solved it is by using the SelectDir function in Delphi. It does the same, but You only have run a function out of your own created DLL.
  • tomtrortomtror Member Posts: 3
    Looks finde, but I don't have the 'CSideWindowCheck' automation server. Is there any other way to get Navision's Window handle?
  • AlbertvhAlbertvh Member Posts: 516
    use this variable instead

    Name DataType Subtype Length
    ActiveWindow Automation 'C/SIDE Utility Classes'.ActiveWindow
  • Timo_LässerTimo_Lässer Member Posts: 481
    tomtror wrote:
    Looks finde, but I don't have the 'CSideWindowCheck' automation server. Is there any other way to get Navision's Window handle?

    I've an older version of this script and there is no use of ActiveWindow:

    (By the way, you can compress the function to simply three lines)
    IF ISCLEAR(ShellControl) THEN 
      CREATE(ShellControl); 
    
    EXIT(FORMAT(ShellControl.BrowseForFolder(0,Text000,0).Items().Item.Path));
    

    With ActiveWindow, it looks like this:
    IF ISCLEAR(ShellControl) THEN 
      CREATE(ShellControl); 
    IF ISCLEAR(ActiveWindow) THEN 
      CREATE(ActiveWindow);
    
    EXIT(FORMAT(ShellControl.BrowseForFolder(ActiveWindow.WindowHandle,Text000,0).Items().Item.Path));
    

    (The TextConst Text000 contains the title of the Dialog)
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • tomtrortomtror Member Posts: 3
    Thanks Albertvh and Timo.

    @Albertvh: Would be nice to have this COM Server :) It seems to be missing in my installation, too.

    @Timo: The count of lines of code is not my Problem :) But if I use 0 instead of the window handle parameter, the folder selection window disapears suddenly when I move the mouse...
    BTW: Greez from WZ Ravensburg

    Any further suggestions?
  • Timo_LässerTimo_Lässer Member Posts: 481
    tomtror wrote:
    [...]
    Would be nice to have this COM Server :) It seems to be missing in my installation, too.
    [...]
    In this topic of my forum you will find the CSideWindowCheck as zip-file.
    (Attend to the correct folder - this zip-file is for german Windows Installations - You have to unzip it to %Program Dir%\CSideUtilities\)

    Greez from Münster (Westphalia)
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • dgroeserdgroeser Member Posts: 39
    how can i set a position in the tree.

    with the rootdirectory parameter ist a problem, because see only this path?
  • Timo_LässerTimo_Lässer Member Posts: 481
    dgroeser wrote:
    how can i set a position in the tree.

    with the rootdirectory parameter ist a problem, because see only this path?
    Sorry, it seems that there is no way to do this.
    The Root Directory is to prevent the user from leaving a specified directory, e. g. all files must be inside a specified \\fileserver\navision\
    So you can make sure that nobody selects a directory on its own HDD.
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • EmerikEmerik Member Posts: 50
    Hi Timo,

    I tried to insert your code:
    (By the way, you can compress the function to simply three lines)
    IF ISCLEAR(ShellControl) THEN 
      CREATE(ShellControl); 
    
    EXIT(FORMAT(ShellControl.BrowseForFolder(0,Text000,0).Items().Item.Path));
    

    But I get the following error message:
    := cannot be performed on arrays.

    Choose a single array value using an expression such as:

    MyArray[...]

    I have no idea, why and where it is expecting an array. How do I fix this problem?

    Thanks for any help
  • kinekine Member Posts: 12,562
    Emerik wrote:
    Hi Timo,

    I tried to insert your code:
    (By the way, you can compress the function to simply three lines)
    IF ISCLEAR(ShellControl) THEN 
      CREATE(ShellControl); 
    
    EXIT(FORMAT(ShellControl.BrowseForFolder(0,Text000,0).Items().Item.Path));
    

    But I get the following error:
    := cannot be performed on arrays.
    
    Choose a single array value using an expression such as:
    
    MyArray[...]
    

    I have no idea, why and where it is expecting an array. How do I fix this problem?

    Thanks for any help
    Problem is inversion. System assume non-array variable but array is used. It means, it expect normal variable but array is used instead...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    Here the original post for this ..

    http://www.mibuso.com/forum/viewtopic.php?t=9329
    Do you make it right, it works too!
  • EmerikEmerik Member Posts: 50
    Hi again,
    I solved the problem with the error message:
    := cannot be performed on arrays.

    Choose a single array value using an expression such as:

    MyArray[...]

    The problem was, that it was inside the OnAssistEdit trigger, which is not expecting a return value. Thus, I cannot use
    EXIT(...)
    

    Yet another problem. The browse for folder functionality in the OnAssistEdit window now works with
    CLEAR(WindowsShell);
    CREATE(WindowsShell);
    
    "Import Directory" := FORMAT(WindowsShell.BrowseForFolder(0,TitleImport,1).Items().Item.Path);
    

    However, the window with the folder structure opens out of focus, and even when I click on the window, it mostly blinks and goes out of focus again. I have to move overlapping windows away, maybe click 4-5 times, before the window with the folder browser stays in place.

    I don't know if it is because I'm not using the ActiveWindow automation:

    'C/SIDE Utility Classes'.ActiveWindow or
    'CSideWindowCheck'.WindowCheck

    described earlier in this topic, but I'd rather not use these automations, if possible, because I fear that I may not always have access to it (since I e.g. haven't got it installed now (by default installation)).

    Can the focus problem be solved (without the use of the (mentioned) ActiveWindow, preferably)?
  • DHendriksenDHendriksen Member Posts: 32
    Hello,

    I've another question about this solution. When I open the selection screen for selecting a folder, close the window by escape, then I get an error "... This instance variable could not be instantiated..."
    This error occures in the code ".Items().Item.Path)", see below.


    IF ISCLEAR(lAutShell) THEN
    CREATE(lAutShell);

    rTxtDirectory := FORMAT(lAutShell.BrowseForFolder(0,iTxtWhichDirectory,0).Items().Item.Path);

    CLEAR(lAutShell);


    When I remove this part I don't get this error, but also I do not get the directory anymore (only if the dir is in use).

    Does somebody have an idea how to fix this? Why this error occures?

    Thanx in advance.
  • SavatageSavatage Member Posts: 7,142
    your having trouble with the automation

    Search the forum for "instantiated"
    http://www.mibuso.com/forum/search.php
  • absolutelyfreewebabsolutelyfreeweb StockholmMember Posts: 103
    well it's an easily breakable short version. the original version works great. thank you.
  • absolutelyfreewebabsolutelyfreeweb StockholmMember Posts: 103
    well, you get a lot of errors trying to shorten things. this is better:
    IF ISCLEAR(shellcontrol) THEN 
      CREATE(shellcontrol); 
    
    selectedfolder := shellcontrol.BrowseForFolder(0,text50000,0);
    IF NOT ISCLEAR(selectedfolder) THEN BEGIN
      folderitems := selectedfolder.Items();
      IF NOT ISCLEAR(folderitems) THEN BEGIN
        folderitem := folderitems.Item();
        folderitem2 := folderitems.Item(0);
        IF NOT ISCLEAR(folderitem) THEN BEGIN
          "directory Path" := folderitem.Path ;
        END ELSE IF ISCLEAR(folderitem) AND NOT ISCLEAR(folderitem2) THEN BEGIN //handle desktop
          "directory Path" := COPYSTR(folderitems.Item(0).Path, 0,
                        STRLEN(folderitems.Item(0).Path) - STRLEN(folderitems.Item(0).Name));
        END;
      END;
    END;
    
Sign In or Register to comment.