WPTools losing ImageObjects

  • Hey Julian,

    Our customers are complaining about WPTools v4.22b. It loses (forget to save) HTML-imageobjects when writing html-page (wpxmlwriter).

    So i just test it out. And they're right. I create an HTML-page. Put some text on it, insert two JPG images and save the page as HTML.
    First time it's okay, but after a while of testing, suddenly images are not any more saved...!

    You can imagine... Customers creating a photo gallery page on their company site.. just inserting fifth image, save, and lose (all | some of) their imageobjects...

    Some more information:
    * It doesn't make sens if you have JPG/GIF images inserted. Tested only JPG / GIF and combinations.
    * It's accidently and irritating.
    * It happens with both resized and not resized images.
    * It doesn't make sense if page is having tables / links or not.. I got it with the simpliest pages too...
    * Sometimes random(x) of x images are saved.
    * I have already installed new wpxmlint422b patch. this doesn't make any sense...

    I've reached end of my mind with this problem now...

    Thanks,
    Janno

    Janno de Wit
    DNA services B.V.

    • Offizieller Beitrag

    Hi,

    It makes a big difference HOW the images have been inserted. In your application should only allow to it to insert the images using a link to an extern file.

    The code which then write the object is

    begin
    if TWPObject(p^.obj).URL <> '' then fXML.WriteNative('<a href="' + TWPObject(p^.obj).URL + '">');
    oa := TWPObject(p^.obj).AliasTextObj;
    TWPObject(p^.obj).AliasTextObj := p;
    TWPObject(p^.obj).XML_Mode := not FHTMLMode;
    try
    TWPObject(p^.obj).WriteHTMLCode(fXML.MemoryStream, FWritePath);
    finally
    TWPObject(p^.obj).XML_Mode := FALSE;
    end;
    TWPObject(p^.obj).AliasTextObj := oa;
    if TWPObject(p^.obj).URL <> '' then fXML.WriteNative('</a>');
    end;

    The means the work is actually done by
    TWPOImage.WriteHTMLCode
    in unit WPEmOBJ.

    If you check out this code you will see the influence the CreatImage option and event has on the creation of the code. I expect that showmow the image is not created or the file name is not used. It would also help to see the created HTML code to check IF there is an empty img object.

    I suggest to place a breakpoint into TWPOImage.WriteHTMLCode and see what happens in concrete in your application.

    Julian

  • Julian,

    First, I'll test this today.
    Then, the problem exist with already saved images too.. It''s not only with new images you want to save to the html-page..

    My LoadStreamEvent code is as follows:

    Code
    procedure TfSiteAlgemeen.WPRichText1TextObjectLoadStreamEvent(  Sender: TObject; const sname: String; State: TWPOCurrState;  var Done: Boolean);var   cImage:     String;   MyFormat:     Word;   AData:        Cardinal;   APalette:     HPALETTE;   Bitm:         TBitmap;   cActiveImage: String;   cImageKaal :  String; // kale imagenaam, dus bijv 'as400' ipv '/files/images/as400.gif'   I: Integer;   TempImg:      TImage;   bImgFound:    Boolean;begin  try    cImageKaal := Copy( sname, 15, Length( sname ) );                        // kale imagenaam, 'add' bijv.    cImage     := fDSBS2.cImagePath + Copy( sname, 15, Length( sname ) );    // full local path naar image *including* extension    // check database    DSBS.qryImages.First;    DSBS.qryImages.Locate( 'Name', cImageKaal, [loPartialKey, loCaseInSensitive] );    // check of hij wel *EXACT* dezelfde naam heeft als wat ik nodig heb.    cActiveImage := DSBS.qryImages.FieldByName( 'Name' ).asString;    if cActiveImage = cImageKaal then begin      bImgFound := True;    end else begin      bImgFound := False;    end;    if bImgFound then begin // yes! hij is in de db gevonden      // load image in a TImage      try        TempImg := TImage.Create( WPRichText1 );        TempImg.Picture.LoadFromFile( cImage );      except        try          TempImg             := TImage.Create( WPRichText1 );          TempImg.Stretch     := True;          TempImg.Picture.Assign( fDSBS2.Image1.Picture.Graphic ); // error image, red cross        finally		// [..]                end;      end;    end else begin // not found      try        TempImg             := TImage.Create( WPRichText1 );        TempImg.Stretch     := True;        TempImg.Picture.Assign( fDSBS2.Image1.Picture.Graphic ); // error image, red cross      finally      end;    end;    try      (Sender as TWPOImage).Picture.Assign( TempImg.Picture );    except    end;//    (Sender as TWPOImage).ObjName := DSBS.qryImages.FieldByName( 'ImgID' ).asString;//    showmessage('senderojname: '+ (Sender as TWPOImage).ObjName);    Done := True;//    TempImg.Free;  except  end;

    Normally users insert code as follows:

  • Julian,

    Restructured the TextObjectLoad event.
    To test WPTools I made it very simple:

    Code
    try    cImageSource := Copy( sname, 15, Length( sname ) ); // Image naam, dus bijv: test.jpg    cImagePath   := fDSBS2.cImagePath + cImageSource;   // Path + Image, dus: c:\dcms\cache\site.nl\images\test.jpg    {*     * Search in the database for the image     *}    DSBS.qryImages.First;    if DSBS.qryImages.Locate( 'Name', cImageSource, [loCaseInSensitive] ) then begin      {*       * Gevonden! Vul het WPImage object       *}      (Sender as TWPOImage).FileExtension := ExtractFileExt( cImagePath );      (Sender as TWPOImage).LoadFromFile( cImagePath );      Done := True;    end else begin      {*       * Image niet gevonden!       *}       ShowMessage( 'Image not found!' );    end;  except    MessageDlg( 'Someting goes wrong!!', mtError, [mbOk], 0 );  end;

    It is very strange. I decided to add a showmessage in the try-except statement in WriteHTMLCode of wpembobj:

    Code
    [~line 1959]   // to execute the OnHTMLCreateImageEvent event again{$IFDEF WPALWAYSCREATEIMAGEEVENT}    FHTMLImgName := '';{$ENDIF}  except    // Better save text than nothing !    showmessage( 'failed to save image!!! exception!' );  end;

    Any idea what goes wrong?

    After a while of working i get these showmessages().

    Statement which explodes:

    Code
    if soCreateImageEventForAllImages in FMemo.Header.HTMLStoreOptions then
          FHTMLImgName := ''
        else

    fmemo seems to be 'nil' at errortime, and procedure parameters too... s is () and filename =''...