Hello All,
How do you check and trap for the instantiation of a COM component when you are unsure of whether or not a user will have the component library installed?
In VFP I can do:
TRY
*-- Create zipper object
loZipper = CREATEOBJECT( "XceedSoftware.XceedZip.4" )
CATCH
ENDTRY
IF TYPE("loZipper") <> "O"
* Could not create zip object, probably don't have the Xceed components installed
MESSAGEBOX("Please check to make sure you have the Xceed Zip Compression Library installed", ;
0 + 16,"Error: Missing Required Files")
RETURN .F.
ENDIF
However, if I try to do the following in C#:
try
{
XceedZipLib.XceedZipClass loZipper = new XceedZipLib.XceedZipClass();
}
catch
{
MessageBox.Show("Please check to make sure you have the Xceed Zip Compression Library installed",
"Error: Missing Required Files", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return false;
}
loZipper.PreservePaths = false;
loZipper.FilesToProcess = ...
I get an error saying that "The type or namespace name 'type/namespace' could not be found (are you missing a using directive or an assembly reference?)" when I try to do anything with the loZipper object. If remove the try-catch, everything is fine. Why does the scope change in the try-catch?
So... How should I be testing for loZipper creation?
Thanks,
- Brian
VFP6 SP5, VFP8 SP1, VFP 9 SP 1 and Win XP SP 3 (unless otherwise specified)
www.wulfsden.com