ivan
  • ivan
  • 100% (Exalted)
  • Administration Topic Starter
11 years ago
in EAGetMail Attachment object,
Attachment.Content property returns binary data with SafeArray Type.

Many Delphi users asked me how to convert the SafeArray to Stream in delphi,
Here is the example code:



procedure TForm1.LoadAttToStream( att: IAttachment );
var
i: integer;
lbound: integer;
ubound: Integer;
len: integer;
buffer: array of byte;
myarray: OleVariant;
stream: TMemoryStream;
begin

myarray := att.Content;
lbound := VarArrayLowBound(myarray, 1 );
ubound := VarArrayHighBound(myarray, 1 );
len := ubound - lbound + 1;
if len = 0 then
exit;

SetLength( buffer, len );
for i := VarArrayLowBound(myarray, 1 ) to ubound do
begin
buffer[i] := VarArrayGet( myarray, i );
end;

stream := TMemoryStream.Create();

stream.WriteBuffer( buffer[0], len );
stream.SaveToFile( 'c:\my folder\' + att.Name ); //save stream to file.
stream.Free();
end;

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.