• Hello

    My application adds each 10 seconds a table to a wprichtext component which contains an image with aprox 100 Kb. The problm is that after several minutes and because of adding so many images the Memusage reaches more than 50 MBytes which is too much for my users.
    Ive two questions regarding this:

    1) Is there any way of adding an image without spending so much memory on my application? (maybe the image would be on a file and would be read when needed)?

    2) If not and supposing I have 1000 tables on my wprichtext how can I delete the first table added to the component? (anytime I would add a new table I would delete the first one).

    Thanks in advance.
    Andre

    • Offizieller Beitrag

    >>1) Is there any way of adding an image without spending so much memory on my application? (maybe the image would be on a file and would be read when needed)? <<

    Add an empty image with a streamname as reference. Load it on demand. The image objects have varios procedures you can override to draw when required.

    >>2) If not and supposing I have 1000 tables on my wprichtext how can I delete the first table added to the component? (anytime I would add a new table I would delete the first one). <<

    Insert hidden markers and find the first marker then delete the text including this marker.

    Julian

  • Julian

    "Please see unit WPExtObj for examples about embedded objects. WPEmOBJ is also a good source."

    Where can I visit that? On the Help menu? On the Demos folder?

    "Insert hidden markers and find the first marker then delete the text including this marker. "

    Where can I find examples on how to do this?
    Tks, Andre

  • Hello again Julian

    On your last email you wrote:

    "WPExtObj etc belong to WPTools Standard. See the directory \Dx"

    I cannot see any Dx folder inside my WpTools installation and after 3 emails I'm exactly on the same confition I was on the start of this thread.

    Wouldn't it be easier if you write here an example on how to add images to the WpRichText which are written in realtime from a file and not added to the component (to avoid spending memory)?

    Imagine I want to add an image that when drawn would look for file "d:\myimage.jpg" and draw it on the screen?

    Thanks. Andre

    • Offizieller Beitrag

    With Dx I meant of course D4 for Delphi 4, D5 for Delphi 5 etc.

    The example to create a linked image is
    WPRichText1.InsertGraphicAsLinkDialog('Graphic Files|*.BMP;*.WMF');

    Please look through this file WPEmOBJ.PAS and also at the procedure I mentione above (in WPRich.PAS)

    Please note that images which are not embedded use the property 'StreamName' - If this property is a file name which can be found by the RTF Engine it will be loaded automatically, otherwise you need to load it yourself in the OnTextObjectLoadStream event.

  • Julian

    Thanks for your reply.

    I've both used the WPRichText1.InsertGraphicAsLinkDialog('Graphic Files|*.BMP;*.WMF') and the below code (both add the image with success).
    Anyway my problem persists: everytime I add, for example, a 1 Mbytes image, 1 Mbytes mem usage is added to my application total mem usage. At the end if I add 200x 1 Mbytes images, my application crashes because of too much RAM being used. Basically I want to add a link to the image without adding the image itself (I want it to be drawn only). What is wrong with the below code?

    Thanks, Andre

    with wprichtext1 do begin
    tablecolnumber:=1;
    obj:=TWPOImage.create(wpRichText1);
    obj.fileextension:='BMP';
    obj.streamname:='d:\ext.bmp';
    obj.WidthTW := round(obj.ContentsWidth/2);
    obj.HeightTW := round(obj.ContentsHeight/2);
    TextObjects.Insert(obj);
    end;