在c ++ builder中使用TIdAttachment发送附件

Suh*_*iev 1 delphi indy c++builder indy10

如何使用TIdyAttachment发送附件?

如何将这个TIdAttachment.Create(msg.MessageParts, 'c:\attach.bmp');delphi语句转换为c ++ builder?如何在c ++ builder中使用这个抽象类?由于它是抽象的我无法创建它的实例!

Rud*_*uis 5

请注意,这TIdAttachment确实是抽象的(正如Remy Lebeau在评论中指出的那样).请TIdAttachmentFile改用.在C++中,我想它应该看起来像(更新:我看到你已经发现了):

TIdAttachmentFile *attachment = new TIdAttachmentFile(msg->MessageParts, "C:\\attach.bmp");
Run Code Online (Sandbox Code Playgroud)

FWIW,TMyClass.Create(args)在Delphi中命名的构造函数调用new TMyClass(args)在C++ Builder中被翻译.这就是为什么Delphi经常重载Create,而不是使用不同命名的构造函数CreateWithSpecialParams.在Delphi中,构造函数可以有任何名称,但不能在C++中.

请注意,在Delphi中,您可以拥有a constructor Create(Integer)和a,constructor CreateEx(Integer)并且它们是可区分的.这不能转换为C++ Builder,因为两者都转换为MyClass(int),所以如果Delphi程序员希望他或她的类在C++ Builder中可用,那么应该避免这样做.