Board index » delphi » IPicture(disp) problems !!

IPicture(disp) problems !!

hello com-experts,

i tried to use the IPicture(Disp) to transfer a picture from a client to
a server application or vice versa. It does't work, crashing every time
with the strange message 'unexcepted failure'.
Is is somehow possible that the IPicture transfer is not bugfree (Delphi
side) ? All books (including 'Delphi COM programming' from Eric Harmon)
mention the three types IStrings, IFont and IPicture, but none of them
implements the IPicture (using SetOlePicture and GetOlePicture) ! Isn't
this strange ?
Is anyone knows what the problem is in this issue ; I warmly welcome you
and your advice !

yves.

some excerpts out of my code (different units) ;

 type
   TListServer = class(TAutoObject, IListServer)
     private
       FPicture : TPicture;
     protected
       function Get_Picture: IPicture; safecall;
       procedure Set_Picture(const Value: IPicture); safecall;
       property Picture: IPicture read Get_Picture write Set_Picture;
     public
       destructor Destroy; override;
       procedure  Initialize; override;
   end;

 implementation

 destructor TListServer.Destroy;
 begin
   FPicture.Free;
   inherited;
 end;

 procedure TListServer.Initialize;
 begin
   inherited;
   FPicture := TPicture.Create;
 end;

// ListServerForm is the mainform of my serverapplication -
// just to check the transfer of the picture (dumping it in a TImage
component)

 function TListServer.Get_Picture: IPicture;
 var
   TmpIPicDisp : IPictureDisp;
 begin
   FPicture.Assign(ListServerForm.Image1.Picture);

   GetOlePicture(FPicture,TmpIPicDisp);
   Result := TmpIPicDisp as IPicture;
 end;

 procedure TListServer.Set_Picture(const Value: IPicture);
 begin
   SetOlePicture(FPicture, Value as IPictureDisp);
   ListServerForm.Image1.Picture.Assign(FPicture);
 end;

 

Re:IPicture(disp) problems !!


<<Yves De Pauw:
i tried to use the IPicture(Disp) to transfer a picture
from a client to a server application or vice versa.

Quote

Get- and SetOlePicture don't work for out-of-process
servers, if that's what you're trying to do - you need to
stuff the picture into a variant array of bytes to pass it
in that case.

--
Deborah Pate (TeamB)
http://delphi-jedi.org
Sorry, no email please.

Re:IPicture(disp) problems !!


Yves

I had exactly the same problem as you. In the end I opted for streaming the
picture as follows:

{**********************************************************************
**
** BitmapToIStream ;
**
** This method returns an IStream interface from a TBitmap.
**
**  PARAMS
**    - [IN]  pPicture : Bitmap to be streamed.
**    - [OUT] pIStream : IStream interface pointer.
**
**********************************************************************}
procedure BitmapToIStream( pPicture : TBitmap; var pIStream : IStream);
var
  lStream        : TMemoryStream;
  lStreamAdapter : TStreamAdapter;
begin
  lStream        := TMemoryStream.Create;
  pPicture.SaveToStream( lStream );
  { Instatiate with 'soOwned' so the lStream is automatically destroyed
    when the client releases the IStream interface.}
  lStreamAdapter := TStreamAdapter.Create( lStream, soOwned );
  pIStream       := lStreamAdapter as IStream;
end;

{**********************************************************************
**
** IStreamToBitmap ;
**
** This method loads a bitmap from an IStream interface.
**
**  PARAMS
**    - [IN]  pIStream : IStream interface with the bitmap information.
**    - [IN]  pBitmap  : Bitmap to be updated.
**
**********************************************************************}
procedure IStreamToBitmap( pIStream : IStream; pBitmap : TBitmap );
var
  lOleStream : TOleStream;
begin
  lOleStream := tOleStream.Create( pIStream );
  lOleStream.Seek( 0, soFromBeginning );
  pBitmap.LoadFromStream( lOleStream );
end;

I hope it helps.
Paulo

Quote
> hello com-experts,

> i tried to use the IPicture(Disp) to transfer a picture from a client to
> a server application or vice versa. It does't work, crashing every time
> with the strange message 'unexcepted failure'.

Re:IPicture(disp) problems !!


dear paulo

thank you for your time and your code. I think I'll have to use your code,
since there's definitly something wrong with the marshalling support of
IPicture ! According to Deborah, it doesn't work in an out-of-process
automation server ... for which it is designed, according to my humble opinion
:-)

yves.

Quote
Paulo Pinheiro wrote:
> Yves

> I had exactly the same problem as you. In the end I opted for streaming the
> picture as follows:

> {**********************************************************************
> **
> ** BitmapToIStream ;
> **
> ** This method returns an IStream interface from a TBitmap.
> **
> **  PARAMS
> **    - [IN]  pPicture : Bitmap to be streamed.
> **    - [OUT] pIStream : IStream interface pointer.
> **
> **********************************************************************}
> procedure BitmapToIStream( pPicture : TBitmap; var pIStream : IStream);
> var
>   lStream        : TMemoryStream;
>   lStreamAdapter : TStreamAdapter;
> begin
>   lStream        := TMemoryStream.Create;
>   pPicture.SaveToStream( lStream );
>   { Instatiate with 'soOwned' so the lStream is automatically destroyed
>     when the client releases the IStream interface.}
>   lStreamAdapter := TStreamAdapter.Create( lStream, soOwned );
>   pIStream       := lStreamAdapter as IStream;
> end;

> {**********************************************************************
> **
> ** IStreamToBitmap ;
> **
> ** This method loads a bitmap from an IStream interface.
> **
> **  PARAMS
> **    - [IN]  pIStream : IStream interface with the bitmap information.
> **    - [IN]  pBitmap  : Bitmap to be updated.
> **
> **********************************************************************}
> procedure IStreamToBitmap( pIStream : IStream; pBitmap : TBitmap );
> var
>   lOleStream : TOleStream;
> begin
>   lOleStream := tOleStream.Create( pIStream );
>   lOleStream.Seek( 0, soFromBeginning );
>   pBitmap.LoadFromStream( lOleStream );
> end;

> I hope it helps.
> Paulo

> > hello com-experts,

> > i tried to use the IPicture(Disp) to transfer a picture from a client to
> > a server application or vice versa. It does't work, crashing every time
> > with the strange message 'unexcepted failure'.

Re:IPicture(disp) problems !!


Deborah, thanks for the answer, but I'll refraise my problem more
explicitly ;

I quote Eric Harmonts' book (pg 164) chapter 'Out-of-Process Automation
Servers' ;

Briefly, the datatypes that are automation compatible are Smallint, ...
and Byte.
..., Delphi also provides marshaling support for pictures, string lists
and fonts through  the interfaces IPicture, IStrings and IFonts.

the choice is either ;
    -    there's a huge error in Eric Harmonts' book
    -    there's a bug in Delphi, supporting the IPicture(disp)
interface

two questions ;
- can you indicate which one of the two fails ? (I just like to know)
- if there's a Delphi problem ; will they fix it in Delphi 6 ?

of course, thank you for your time Deborah :-)

P.S. I implemented IStrings and IFont in an out-of-process server ...
and it works !!

Quote
"Deborah Pate (TeamB)" wrote:
> <<Yves De Pauw:
> i tried to use the IPicture(Disp) to transfer a picture
> from a client to a server application or vice versa.

> Get- and SetOlePicture don't work for out-of-process
> servers, if that's what you're trying to do - you need to
> stuff the picture into a variant array of bytes to pass it
> in that case.

> --
> Deborah Pate (TeamB)
> http://delphi-jedi.org
> Sorry, no email please.

Re:IPicture(disp) problems !!


<<Yves De Pauw:
P.S. I implemented IStrings and IFont in an out-of-process
server ... and it works !!

Quote

Yes, there's no problem at all with those two. But as you have
also found, there is with IPicture. I believe the reason is that
Windows device contexts are address-space specific. It is not a
Delphi problem, as you can see from this article:
http://support.microsoft.com/support/kb/articles/Q150/0/34.asp

By the way, I just realized that you're posting in HTML.Please
don't do this, it is unreadable in many newsreaders, and against
the newgroup guidelines.

--
Deborah Pate (TeamB)
http://delphi-jedi.org
Sorry, no email please.

Re:IPicture(disp) problems !!


<<Yves De Pauw:
P.S. I implemented IStrings and IFont in an out-of-process
server ... and it works !!

deborah,
thank you for this explanation. I'm always astonished on how much
information you experts have on these questions - I suppose you're just
having an IQ of 160 :-), or you know the support groups from enterprise,
microsoft, ... all by hard.

Thank you also for the additional info on HTML-postings ; I didn't know
:-(   ... never to old to learn something !

yves.

Other Threads