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.
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
Codeunit 412 uses an OCX though, so slightly different thing going on.
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.
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 ...
Regards
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
WHY WHY WHY WHY..... BSTR
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).
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.
](*,)
I think it is just a little buggy with this automation, go figure... it's Microsoft.