繁体   English   中英

DeleteFile() 在 Embarcadero C++ Builder 中不起作用

[英]DeleteFile() doesn't work in Embarcadero C++ Builder

我将几个 pdf 加载到 Embarcadero C++ 中,并使用 Gnostice pdfToolkit Vcl 对它们进行数字签名。 问题是在已签名的情况下删除未签名的 pdf。 这是代码:

gtPDFDocumento->LoadFromFile("no_firmado.pdf");
gtPDFDocumento->AddSignature(firma_digital.pfx);
gtPDFDocumento->SaveToFile("firmado.pdf");

//You have to reload the pdf because if it does not give an error
gtPDFDocumento->LoadFromFile("firmado.pdf");
//
if(!DeleteFile("no_firmado.pdf"){
    int e = GetLastError();
    AnsiString error = SysErrorMessage(e);
    ShowMessage(error);
    return;
}

这是GetLastError()错误的结果:

该进程无权访问该文件,因为它正被另一个进程使用。

我想知道如何解锁未签名的 pdf 以将其删除。

您仍然可以从最初加载它的行打开no_firmado.pdf文件。

gtPDFDocumento->LoadFromFile("no_firmado.pdf");

这就是您收到此错误的原因。

显式关闭文件,然后可以将其删除。

 // Free Resources
 gtPDFDocumento->Reset();

 // Destroy PDF document object
 FreeAndNil(gtPDFDocumento);
 // After this point gtPDFDocumento can not be used unless reinitialized.

现在你可以调用DeleteFile(...)

我已经尝试过该代码,但它给出了同样的错误:

gtPDFDocument->LoadFromFile("not_signed.pdf");
gtPDFDocument->AddSignature(digital_signature.pfx);
gtPDFDocument->SaveToFile("signed.pdf");

//You have to reload the pdf because if it does not give an error
gtPDFDocument->LoadFromFile("signed.pdf");
//
// Free Resources
gtPDFDocument->Reset();
// Destroy PDF document object
FreeAndNil(gtPDFDocument);
// After this point gtPDFDocument can not be used unless reinitialized.
if(!DeleteFile("not_signed.pdf"){
inte = GetLastError();
AnsiString error = SysErrorMessage(e);
ShowMessage(error);
return;
}

谢谢!!

我已经尝试过该代码,但它给出了同样的错误:

gtPDFDocument->LoadFromFile("not_signed.pdf");
gtPDFDocument->AddSignature(digital_signature.pfx);
gtPDFDocument->SaveToFile("signed.pdf");

//You have to reload the pdf because if it does not give an error
gtPDFDocument->LoadFromFile("signed.pdf");
//
// Free Resources
gtPDFDocument->Reset();
// Destroy PDF document object
FreeAndNil(gtPDFDocument);
// After this point gtPDFDocument can not be used unless reinitialized.
if(!DeleteFile("not_signed.pdf"){
inte = GetLastError();
AnsiString error = SysErrorMessage(e);
ShowMessage(error);
return;
}

谢谢!!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM