帮我翻译一段代码(Delphi-> C++ Builder)(50分)

  • 主题发起人 主题发起人 gwdb
  • 开始时间 开始时间
G

gwdb

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能帮我把以下一个indy附带收email的一段代码翻译成C++ Builder 5的形式的代码?
主要是注释部分,谢谢。

ShowStatus('Decoding attachments (' + IntToStr(Msg.MessageParts.Count) + ')');
for intIndex := 0 to Pred(Msg.MessageParts.Count) do
//这一句
begin
if (Msg.MessageParts.Items[intIndex] is TIdAttachment) then
//这一句
begin
//general attachment
pnlAttachments.visible := true;
li := lvMessageParts.Items.Add;
li.ImageIndex := 8;
li.Caption := TIdAttachment(Msg.MessageParts.Items[intIndex]).Filename;
////这一句
li.SubItems.Add(TIdAttachment(Msg.MessageParts.Items[intIndex]).ContentType);
//这一句
end
else
begin
//body text
if Msg.MessageParts.Items[intIndex] is TIdText then
//这一句
begin
Memo1.Lines.Clear;
Memo1.Lines.AddStrings(TIdText(Msg.MessageParts.Items[intIndex]).Body);
////这一句
end
end;
end;
 
怎么没有人会啊?
 
delphi C++
"is" -> "as"
"." -> "->"
":=" ->" ="
 
to yanghai0437:
你是指这句
if (Msg.MessageParts.Items[intIndex] is TIdAttachment) then

转换为:
if (Msg->MessageParts->Items[intIndex] as TIdAttachment)
???这样不对啊,as不是代替is的,其他的转换我知道,就是这几句不懂
 
if (Msg->MessageParts->Items[intIndex] is TIdAttachment) //这一句
li->Caption := TIdAttachment(Msg->MessageParts->Items[intIndex])->Filename;
////这一句
li->SubItems->Add(TIdAttachment(Msg->MessageParts->Items[intIndex])->ContentType);
//这一句
if Msg->MessageParts->Items[intIndex] is TIdText //这一句
Memo1->Lines->Clear;
Memo1->Lines->AddStrings(TIdText(Msg->MessageParts->Items[intIndex])->Body);
////这一句

 
to cwmdelpher
不能简单的这样转换的,你的转换通不过,
if (Msg->MessageParts->Items[intIndex] is TIdAttachment) //这一句
is是delphi里的,在C++ Builder里不能使用
TIdAttachment(Msg->MessageParts->Items[intIndex])->Filename;

这一句也是delphi里的语法,在C++ Builder里也不能使用
 
for intIndex := 0 to Pred(Msg.MessageParts.Count) do
//这一句
>for (int intIndex = 0;intIndex < Pred(Msg->MessageParts->Count);
intIndex ++) //这一句
if (Msg.MessageParts.Items[intIndex] is TIdAttachment) then
//这一句
>if (Msg->MessageParts->Items[intIndex]->ClassNameIs("TIdAttachment")) //这一句
li.Caption := TIdAttachment(Msg.MessageParts.Items[intIndex]).Filename;
////这一句
>li->Caption = (TIdAttachment)(Msg->MessageParts->Items[intIndex])->Filename;
////这一句
if Msg.MessageParts.Items[intIndex] is TIdText then
//这一句
>if (Msg->MessageParts->Items[intIndex]]->ClassNameIs("TIdText")) //这一句
Memo1.Lines.AddStrings(TIdText(Msg.MessageParts.Items[intIndex]).Body);
////这一句
>Memo1->Lines>AddStrings((TIdText)(Msg->MessageParts->Items[intIndex])->Body);
////这一句
在上面转换中,如果使用到ClassNameIs函数的语句报错,请在Msg前添加(TControl *),
如if ((TControl *)Msg->MessageParts->Items[intIndex]->ClassNameIs("TIdAttachment"))
 
谢谢chenxz
li->Caption = (TIdAttachment)(Msg->MessageParts->Items[intIndex])->Filename;
////这一句编译通不过
改为以下一句就没有问题了,现在问题解决了。
li->Caption =((TIdAttachment *)(Msg->MessageParts->Items[intIndex]))->FileName
 
后退
顶部