Board index » delphi » IPicture assigment problem

IPicture assigment problem

All,

I am using the 'MS Forms 2.0 Image' activeX control dynamically added to a
HTML page viewed in the MS DHTML ActiveX control and want to assign a user
selected image to the control so I can save the resultant HTML page,
(including images) as a single file.
The image activeX has an IImage interface which has a Set_Picture method
that takes an IPictureDisp interface. I create an object with an
IPictureDisp interface via the API call OleLoadPicturePath, (more on that
later), but when I try and assign this to the image control via the
Set_Picture method I always get a floating point exception.

I thought I had found the problem when I found and old news group repy from
Danny Thorpe that the OleLoadPicture functions that were implemented in
OlePro32.dll had been superseeded by functions in OleAut32.dll and this
certainly seems to be the case as functions documented in MSDN are not
implemented in OLEPRO32.DLL. However in Delphi 5s ActiveX unit you will see
that these functions  are still linking to OLEPRO32.DLL and not
OLEAUT32.DLL, (Dannys message was dated 1997 so it looks like these have
slipped throuh the net). All this was related to some floating point errors.
Anyway i redeclared the OLE... calls as MyOle... from OLEAUT32.DLL but still
get the error.

Some same code follows but this is driving me nuts at the moment and I would
really appreciate some ideas.

Cheers,
Norm.
P.S you will need to generrate the typelib from the MS forms library to get
the IImage interface etc.

var
  TheObject  : IHTMLObjectElement;
  TheImg       : IImage;
  ThePicture   : IPicture;
  ThePictureDisp : IPictureDisp;
begin
  { Find the control on the HTML page }
  TheObject := DHTMLEdit1.Dom.all.item('Image1', EmptyParam) as
IHTMLObjectElement;
  { Get its IImage interface }
  OleCheck(TheObject.QueryInterface(IImage, TheImg));
  { Create a picture COM object and get its IPicture interface using my
version of the API call }
  OleCheck(MyOleLoadPicturePath('c:\winnt\winnt256.bmp', TheObject, 0, 0,
IPicture, ThePicture));
  { Get the IPictureDisp interface }
  OleCheck(ThePicture.QueryInterface(IPictureDisp, ThePictureDisp));
  { Try and assign but get the error }
  TheImg.picture := ThePictureDisp;

 

Re:IPicture assigment problem


<<Norman Hadfield:
I create an object with an IPictureDisp interface
via the API call OleLoadPicturePath

Quote

Is there some reason not to use a TPicture?
var
  IPicDisp: IPictureDisp;
  IImg: IImage;
  Pic: TPicture;
begin
  Pic := TPicture.Create;
  try
    Pic.LoadFromFile('E:\Images\Splash\16Color\athena.bmp');
    GetOlePicture(Pic, IPicDisp);
    IImg := MSImg.ControlInterface;
    IImg.Picture := IPicDisp;
    MSImg.Refresh;
  finally
    Pic.Free;
  end;

--
Deborah Pate

Re:IPicture assigment problem


Thanks - I had in fact tried a twist on what you suggested already.

I have now however found the cause of my problem - The version of
MSForms_TLB.PAS generated by Delphi 4 which I was still using with Delphi 5
caused the problem. I reimported the type library and all my attempts
including yours worked.

NOW how do I get the activeX to stream out its data in a form that I can
insert as HTML text? Inserting the control as Text, i.e an '<OBJECT>' tag
creates the control and I can set its properties - now including picture -
however the HTML when you read it back has the properties in a <PARM ...>
format and not a ' DATA="DATA:application/x-oleobject;BASE64,QZJZTCZpGxC...'
format.

I suspect the only way will be to create the Img control independently of
the HTML page, load its picture and other properties, get to stream itself
via its IPersistStream interface, convert this to base64, then compose the
HTML for the object tag and insert it into the HTML text.

Any ideas?

Norman.

Quote
"Deborah Pate" <d.p...@cableinet.co.not-this-bit.uk> wrote in message

news:8fjvo6$k5m1@bornews.borland.com...
Quote
> <<Norman Hadfield:
> I create an object with an IPictureDisp interface
> via the API call OleLoadPicturePath

> Is there some reason not to use a TPicture?
> var
>   IPicDisp: IPictureDisp;
>   IImg: IImage;
>   Pic: TPicture;
> begin
>   Pic := TPicture.Create;
>   try
>     Pic.LoadFromFile('E:\Images\Splash\16Color\athena.bmp');
>     GetOlePicture(Pic, IPicDisp);
>     IImg := MSImg.ControlInterface;
>     IImg.Picture := IPicDisp;
>     MSImg.Refresh;
>   finally
>     Pic.Free;
>   end;

> --
> Deborah Pate

Re:IPicture assigment problem


Additional Info

The file I get from asking the control to stream itself to a stream via
IPersistStreamInit and then convert to Base64 is very close to but not
exactly the same as the data produced when setting the properties to the
same values in 'ActiveX control pad', (which is essentially what I am trying
to emulate).

If I take the encoded data produced by ActiveX control pad and decode it the
last part of the stream is identical to mine, probably the picture data, but
the preamble is different.

Clues most welcome? Does anyone know if the source for the ActiveX control
pad is available anywhere?

Norman.

Other Threads