How to save graphic and text?

  • Here is the procedure I wrote:

    procedure TForm.InsertPic(Sender: TObject);
    var
    obj : TWPOImage;
    Resp : Integer;
    se : String;
    begin
    OpenDialog.Filter := 'Bitmap/Jpeg/Gif/Wmf|*.bmp;*.jpg;*.gif;*.wmf';
    OpenDialog.FileName := '';
    If OpenDialog.Execute then
    begin
    se := Lowercase(ExtractFileExt(OpenDialog.FileName));
    if (se = '.bmp') or (se = '.jpg') or (se = '.gif') or (se = '.wmf') then
    begin
    obj := TWPOImage.Create(VolgaEd.Memo.RTFData);
    obj.LoadFromFile(OpenDialog.Filename);
    obj.StreamName := OpenDialog.Filename;
    obj.WriteRTFMode := wobBoth;
    RichText1.TextObjects.Insert(obj);
    end;
    end;
    end;

    The graphic appears at the cursor, but only the text is saved. What am I missing?

    BTW, essentially the same code worked nicely in WPTools3.

    --Bill

    • Offizieller Beitrag

    Hi,

    Zitat

    The graphic appears at the cursor, but only the text is saved. What am I missing?
    BTW, essentially the same code worked nicely in WPTools3.

    WPTools 5 can save bitmaps (also JPEG and PNG) using binary data. So the created data stream can contain \0 characters. Some databases interpret this as EOF and so the rest of the text is not loaded.

    To avoid binary data change the property WPRichText.WriteObjectMode = wobRTFNoBinary. But maybe you can also find the reason why the binary data is not supported and fix it (string handling, such as strlen?). Saving binary data reduces size and improves performance.

    Regards,
    Julian

  • Frankly, I don't know how to implement your suggestion. Besides, I am beginning to wonder if I am looking in the right place.

    Is it possible that my file-saving code is the problem. I am using a line like this after the insertion:
    RichText1.SaveToFile(RTFFilename, false, 'RTF-alwaysembed');

    Again- this worked in early WPTools versions.

    --Bill

    • Offizieller Beitrag

    Hi,

    >>Frankly, I don't know how to implement your suggestion. Besides, I am beginning to wonder if I am looking in the right place. <<

    I was talking about a property of the TWPRichText class. You can change that in the IDE.

    Zitat

    Is it possible that my file-saving code is the problem. I am using a line like this after the insertion:
    RichText1.SaveToFile(RTFFilename, false, 'RTF-alwaysembed');

    Again- this worked in early WPTools versions.

    Youre code is fine. You may mail me the created RTF file - I can probably than see whats missing or if the problem is the loading code.

    I would expect that the latter is the case.

    And, instead of your procedure TForm.InsertPic(Sender: TObject); you can use
    WPRichText1.InsertGraphicDialog

    that is implemented in WPRich.PAS if you want to check it out as coding example.

    Julian

  • Using "InsertGraphicDialog" certainly simplifies my code to:

    Code
    procedure TVolgaForm.InsertPicItemClick(Sender: TObject);var    InsWay : Boolean;    Resp : Integer;begin  Resp := MessageDialog('Insert graphic at cursor.',           mtConfirmation, [mbIgnore, mbAll], 0);       Case Resp of         mrAll : InsWay := false;         mrIgnore : InsWay := True;        end;   OpenDialog.Filter := 'Bitmap/Jpeg/Gif/Wmf|*.bmp;*.jpg;*.gif;*.wmf';   RichText1.InsertGraphicDialog('', InsWay, []);end;

    But the graphic is still not saved, and this is the code I used:

    What am I missing?

    --Bill