"is" should be replaced by "=="...
Code:
if (mess->MessageParts->Items[inindex] is TIdAttachmentFile)
should be
Code:
if (mess->MessageParts->Items[inindex] == TIdAttachmentFile)