PrepareImageForSaving not called when dynamically assigned

  • Hi,

    I'm experiencing problems with the SaveToFile procedure of the TWPRichText. When I place an editor on a form and I place some code in the OnPrepareImageForSaving event everything works perfect!

    Now when I create an editor in runtime (using editor := TWPRichText.Create(nil) and then assign the PrepareImageForSaving procedure dynamically in runtime (editor.OnPrepareImageforSaving := MyPrepareImageForSaving), ofcourse after the creation of the editor, for some reason this event is not triggered?!

    Is this a bug or am I doing something wrong?

  • Hi Julian,

    I don't exactly understand what you mean. Can you tell me what the Loaded procedure is supposed to do? I'm now using the following code:

    Code
    fDocument := TWPRichText.Create(nil);  fDocument.Loaded;  fDocument.OnPrepareImageforSaving := wpPrepareImageforSaving;

    Still the OnPrepareImageforSaving is not triggered when saving the document.
    What do you mean with assigning the data manually?
    I am using this code for an e-mail application.
    The code of the send procedure is as following:

    Code
    procedure TEmailTest.Send(document: TWPRichText; relation: TRelation; subject,
      from_address: string);
    begin
      fDocument := document;
      fSubject := subject;
      fFromAddress := from_address;
      fRelation := relation;
      SaveToFile;
      Send
    end;

    As you can see I'm passing a TWPRichText with the procedure. After this I assign this to the previously created fDocument (TWPRichText) field.

    • Offizieller Beitrag

    Hi,

    'Loaded' is called by the VCL after the form (DFM) was loaded. It is usually good to call it if you create objects in code.

    >> What do you mean with assigning the data manually?

    ... when you use MultiView for example:
    http://www.wpcubed.com/manuals/wp5man…iviewincode.htm

    The OnPrepareImageforSaving is an event of the TWPRTFDataCollection - you can ssign it there:

    fDocument.HeaderFooters.OnPrepareImageforSaving := wpPrepareImageforSaving;

  • Hi,

    I create the TWPRichText without a form (in the e-mail class) TWRichText.Create(nil).

    But you mean I neet to put the data from the editor (which is passed by another form to this unit) in a TWPRTFDataCollection and then pass this TWPRTFDataCollection to my e-mail class, assign the OnPrepareImageforSaving event and then save the document? A TWPRTFDataCollection doens't have a SaveToFile function so what should I do?

    • Offizieller Beitrag

    If you don't use a form use CreateDynamic - as the demo ThreadSave suggest.

    I didn't mean to use the data collection and SaveToFile (although SaveToStream is possible)

    What I suggested was to assign your event handler to the TWPRTFDataCollection which is referenced by the 'HeaderFooter' property.

    See the description of the TWPRTFDataCollection - it does have the OnPrepareImageforSaving event.