🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #673

Re: Simple Create Attachment() question

#673
From: Remy Lebeau (TeamB)
Date: Mon, 24 Dec 2007 22:27
48 lines
2640 bytes
"CharlesLeggette" <charlesleggette@earthlink.net> wrote in message
news:477023a5$1@newsgroups.borland.com...

> I'm trying to attach a file and send it....but the C++ syntax
> is not very intuitive..

That is because you are going about it all wrong.  You need to instantiate a
TIdAttachmentFile object instead, for example:

    TIdAttachmentFile *attachment = new TIdAttachmentFile(msg->MessageParts,
"C:\\Ada\\Src\\plan.cpp");
    // set attachment's properties as needed...

> catch(Exception *e)

Always catch exceptions by (preferrably const) reference, never by pointers:

    catch(const Exception &e)

> void __fastcall TForm1::msgCreateAttachment(const TIdMessage *AMsg, const
> TStrings *AHeaders, TIdAttachment *&AAttachment)
> {
> AAttachment->ContentLocation= "C:\\Ada\\Src\\plan.cpp";
> AAttachment->ContentDescription = "C:Ada.Src.plan.cpp";
> }

The purpose of the OnCreateAttachment event is for you to instantiate your
own instance of a suitable TIdAttachment-derived class (TIdAttachmentFile,
TIdAttachmentMemory, or custom class) for a particular file when
receiving/loading a message, not when sending a message.  TIdMessage uses
TIdAttachmentFile by default for all inbound attachments.  For example:

    void __fastcall TForm1::msgCreateAttachment(const TIdMessage *AMsg,
const TStrings *AHeaders, TIdAttachment *&AAttachment)
    {
        // analyze AHeaders as needed...
        AAttachment = new TIdAttachmentMemory(AMsg->MessageParts);
        // or:
        // AAttachment = new TIdAttachmentFile(AMsg->MessageParts);
        // or whatever you need...
    }

The inbound attachment data will then be loaded into the object after the
event handler exits.


Gambit
Technical Details
Message-ID: <4770320d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!62.111.101.3.MISMATCH!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <477023a5$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,131c53c1624cdd7c
X-Google-Attributes: gid11508e,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <477023a5$1@newsgroups.borland.com>
Subject: Re: Simple Create Attachment() question
Date: Mon, 24 Dec 2007 14:27:13 -0800
Lines: 50
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.83.29.61
Message-ID: <4770320d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1198535181 75.83.29.61 (24 Dec 2007 14:26:21 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!62.111.101.3.MISMATCH!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail