【发布时间】:2016-05-14 23:52:05
【问题描述】:
我编写了一个带有接口的 c# 包装类,用于使用 GemBox.Document 进行文档转换。在课堂上,我有以下方法来保存文档:
public string SourcePath{get;set;}
public string DestinationType{get;set;}
public string DestinationPath{get;set;}
private static DocumentModel document;
public void ConvertDocument()
{
try
{
string filename = Path.GetFileNameWithoutExtension(SourcePath);
ComponentInfo.SetLicense(GemboxLicence);
string savePath = String.Format("{0}\\{1}.{2}", DestinationPath, filename, DestinationType);
document = DocumentModel.Load(SourcePath);
document.Save(savePath);
}
catch (Exception e)
{
throw (new Exception("An error occured while saving the document: " + e.Message ));
}
}
当我从另一个 c# 程序调用该类时,它可以正常工作。
我将类的 dll 注册到 com 并使用 regasm 创建了一个 tlb 文件,如下所示:
regasm MBD.GemBox.Document.dll /tlb
我想通过 com 从 delphi 访问 dll,所以我将 tlb 文件导入 Delphi 2009。然后我创建了一个调用 c# dll 的包装器 delphi 库:
procedure ConvertDocument(sourcePath : string ; destinationType : string ; destinationPath : string);
var
doc : TDocumentConvertor;
begin
try
OleInitialize(nil);
doc := TDocumentConvertor.Create(nil);
doc.Connect;
doc.SourcePath := sourcePath ;
doc.DestinationType := destinationType;
doc.DestinationPath := destinationPath;
doc.ConvertDocument;
doc.Disconnect;
doc.Free;
CoUninitialize;
except
on E:Exception do
begin
Writeln(E.Classname, ': ', E.Message);
end;
end;
end;
但是,我明白了
“在 GemBox.Document.dll 中发生了 'System.StackOverflowException' 类型的未处理异常”
当我尝试通过 delphi 调用该方法时。有谁知道为什么会这样?
【问题讨论】:
-
你需要调试你的代码。您似乎遇到了堆栈溢出错误。
-
如果您只是将 WordDocuments 转换为另一种类型,您可能会喜欢这个github.com/tobya/DocTo
标签: delphi com gembox-document