【问题标题】:Sending attachment using TIdAttachment in c++ builder在 c++ builder 中使用 TIdAttachment 发送附件
【发布时间】:2011-11-03 10:55:46
【问题描述】:

如何使用 TIdyAttachment 发送附件?

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

【问题讨论】:

  • 真的比原来容易!只需写 TIdAttachmentFile(mess->MessageParts,"c:\\pic.jpg"); 就完成了 Suhrob !!

标签: delphi c++builder indy indy10


【解决方案1】:

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

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

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

请注意,在 Delphi 中,您可以拥有 constructor Create(Integer)constructor CreateEx(Integer),它们是可区分的。这不能转换为 C++Builder,因为 both 转换为 MyClass(int),因此如果 Delphi 程序员希望他或她的类在 C++Builder 中可用,则应避免这样做。

【讨论】:

  • 实际上,在 Indy 10 中,TIdAttachment 一个抽象类。您必须改用TIdAttachmentFile
  • 正确的语法是 msg->MessageParts
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-29
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
相关资源
最近更新 更多