Colin,

Sounds like you are having a problem making up C Strings.

Try the following

function UseManyAttachments;
var
  aTemp : Array [0..MAX_LENGTH] of Char;
begin

if Attachments.Count > 0 then
    GetMem(PtrMapiFileDescs, Attachments.Count * SizeOf(MapiFileDesc));
    for i := 0 to Attachments.Count - 1 do
      StrPCpy(aTemp,Attachments[i]); //Explicitly create a null termainated
                                     //array of characters - memory
allocation
                                     //will be taken care of here for you
and will
                                     //overwrite whatever was in aTemp
before
      with PtrMapiFileDescs^[i] do begin
        ulReserved   := 0;
        flFlags      := 0;
        nPosition    := $FFFFFFFF;
        lpszPathName := @aTemp; //Address of first character in array
                                //This is the same as a C String
        lpszFileName := nil;
        lpFileType   := nil;
      end;

end;

This assumes you only need to have one attacment in the P Char at a time. if
not then
declare an array of P char (i.e an array of pointers to null terminated
strings), populate that and cycle throgh that array.

Nigel.

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Colin Fraser
> Sent: 08/10/1999 12:06
> To: Multiple recipients of list delphi
> Subject: [DUG]: Strings and Win API calls...
>
>
> Hi all,
>
> I am just wondering exactly how one should go about passing strings in
> structures to API calls...
>
> I have been mucking around with MAPI stuff and come across
> the following
> when dealing with attachments:
>
>   if Attachments.Count > 0 then
>     GetMem(PtrMapiFileDescs, Attachments.Count *
> SizeOf(MapiFileDesc));
>     for i := 0 to Attachments.Count - 1 do
>       with PtrMapiFileDescs^[i] do begin
>         ulReserved   := 0;
>         flFlags      := 0;
>         nPosition    := $FFFFFFFF;
>         lpszPathName := PChar(Attachments[i]); {Attachments
> is a TStrings
> object}
>         lpszFileName := nil;
>         lpFileType   := nil;
>       end;
>
> Now the above works when there is only 1 attachment, but if
> there are 2 then
> the end of the filename of the first one gets screwed up by
> the writing of
> the second. I can't really see why this occurs...
>
> If I explicitly create a PChar and allocate space for it and
> assign the
> attachment string to it, it all works fine...
> Just more work involved making sure that you latter free the
> space assigned
> to all the strings for each attachment...
>
> Just wondering why the first method doesn't work for multiple
> attachments.
>
> Regards
> Colin
>
> --------------------------------------------------------------
> -------------
>     New Zealand Delphi Users group - Delphi List -
> [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
>


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to