[NOT SOLVED] BStr retour from Filedialog, can not handled

bulebule Member Posts: 7
I make a procedure to create a word document from Navision (3.70). After the document is maked, the document must be saved.
Therefore i create a filedialog with automation server ('Microsoft Office 11.0 Object Library') (Fd = FileDialog | FileDialogSelectedItems = DialogSelectedItems)
      Fd := FileDialog(2);  
      WITH Fd DO BEGIN
        AllowMultiSelect := FALSE;
        InitialView := 1;
        InitialFileName := FilenameStr;
        Title := 'Navision';
      END;
      Output := Fd.Show;
      IF Output =-1 THEN BEGIN
         FileDialogSelectedItems := Fd.SelectedItems;
         StrNm := FileDialogSelectedItems.Item(1);       
         WrdDoc.SaveAs (StrNm);
      END;
Everythings seems perfect, execpt the following statement gives an error.
:shock: StrNm := FileDialogSelectedItems.Item(1);

    The following error appears:
    This datatype is not supported by C/Side. Only data from the following types can be used:
    VT_VOID, VT_I2,VT_I4...etc....VT_BSTR AND VT_BOOL

    StrnNm = Text with length 1024
    The method gives a Bstr back, and this can not be handled by navision. But in codeunit 412 is also a Bstr used. So why can that work properly in codeunit 412 and not in this code? Here they used the Microsoft Common Dialog Control, version 6.0 (SP6), and this one gives also a Bstr back.
      from :
    http://msdn.microsoft.com/en-us/library/ms221069(VS.85).aspx
    A BSTR (Basic string or binary string) is a string data type that is used by COM, Automation, and Interop functions. A BSTR is a composite data type that consists of a length prefix, a data string, and a terminator.


    Who can help me??

    Comments

    • XypherXypher Member Posts: 297
      Since you're not allowing multiple selected files, why not just do..
      StrNm := Fd.Item;
      
      :wink:

      Codeunit 412 uses an OCX though, so slightly different thing going on.
    • bulebule Member Posts: 7
      Without the parameter it will not compilled in navison
    • XypherXypher Member Posts: 297
      With little time spent on testing I haven't really come up with any results either. What is so wrong with using the Common Dialog Management codeunit to get your filepath + name?
    • bulebule Member Posts: 7
      I call a word applicatie and add a document, during this time the user see the word applicatie build up and write the data from navision to the new document. When i use the common dialog, the user don't see it.
      First the applicatie must be closed, saved or deactivated, then the dialog box is visible. The user is be asking to save the document, the wil follow the instruction, but an error appears after that, because the document is allready closed.

      Whe using the filedialog box, the dialog appears while the document is still there. I have build in excel several years ago this procedure, and still today it is working very fine.
    • garakgarak Member Posts: 3,263
      So, back to your Word Problem.

      Here the solution: U use the automation "Microsoft Office 11.0 Object Library') (Fd = FileDialo" Why this :?: In Word, there is also the Dialog Object and the methods of this object is also runable from Nav ;-)

      Here an example ...


      if isclear(WordApp) then
        create(WordApp);
      
      WordApp.Visible(TRUE);
      WordDocuments := WordApp.Documents;
      WordDocument := WordDocuments.Add();
      WordDocument.Activate;
      WordSelection := WordApp.Selection;
      WordSelection.TypeText := 'Here is some text';
      WordDialogs := WordApp.Dialogs;
      WordDialog := WordDialogs.Item(84); //wdDialogFileSaveAs
      WordDialog.Show;
      

      Regards
      Do you make it right, it works too!
    • bulebule Member Posts: 7
      Amost i have a solution. The last solution using the word dialog works properly, but i want to set a standard path. The documents must be ordered in a certain structuur and with the code before this part of code i had allready find where the document must be stored, and i have allready find which standard name he must get.
      So, the user only have to choice, he want store this document or throw it away, and he can addapt the name if he wants. But in common way, he need only push the button to save.
      The worddialog is not capebilty to set a standard path
    • bulebule Member Posts: 7
      Still I don't know how to solve. Why does navision accept on an other place a bstr and here not?

      WHY WHY WHY WHY..... BSTR
    • XypherXypher Member Posts: 297
      You know bule, I really can't make sense of it either. I have tried running some of my own tests on this using several different ways of attempting to get the result bstr path.

      At first I thought it might have been because of SelectedItems being a Collection datatype. Which is, of course, not supported by Navision.

      This still may be the case but I really have no way of testing this (I don't think).
    • bulebule Member Posts: 7
      Thanks Xypher,

      It makes me mad. :evil:

      In codeunit 412 is also a Bstr used, there is no error at all. Here, while using the filedialog navision complains.

      ](*,)
    • XypherXypher Member Posts: 297
      Everything you use that has text is technically a Bstr, whether it is being referenced with an automation or not.

      I think it is just a little buggy with this automation, go figure... it's Microsoft. :D
    Sign In or Register to comment.