WPCubed Product Support

SaveToStream with a custom writer

In version 4 you had methods SaveToStreamWithWriter and LoadFromStreamWithReader

Now you seem to need to use SaveToStream(stream, classNameOfWriter)

Do you have to have registered this writer in some way?

Later...

Yes it seems you do - here's the bit of code that does this from WPIOHTML.pas

if GlobalWPToolsCustomEnviroment <> nil then
begin
GlobalWPToolsCustomEnviroment.RegisterReader([TWPHTMLReader]);
GlobalWPToolsCustomEnviroment.RegisterWriter([TWPHTMLWriter]);
end;

The problem I have now is - how do I set any properties of the writer at runtime if I don't create it? I can't see any events that would let me do this.

#1 ♥ 0
7.8k Views 3 users read 3 min
support

Hi,

The problem I have now is - how do I set any properties of the writer at runtime if I don't create it? I can't see any events that would let me do this.<<

I could add an event which lets you do this, sonmething like BeforeLoadWithReader

Julian Ziersch

#2 ♥ 0

@wpsupport:
I could add an event which lets you do this, sonmething like BeforeLoadWithReader

A BeforeSaveWithReader event would also be helpful since I have the same problem. I need to set some properties to my custom reader and writer.

Will this change be included in the upcoming release 10?

/Fredrik

#4 ♥ 0
support

This has been already added but it is no event of the TWPRichText.

It is an event of the TWPRTFDataCollection (= WPRichText1.HeaderFooter) and must be assigned in code:

The event definitions are:

TWPIOLoadWithReader = procedure(
    RTFData: TWPRTFDataCollection;
    Stream: TStream;
    Reader: TWPCustomTextReader;
    OnlyBodyText: Boolean;
    var Abort: Boolean) of object;

  TWPIOAfterLoadWithReader = procedure(
    RTFData: TWPRTFDataCollection;
    Stream: TStream;
    Reader: TWPCustomTextReader;
    OnlyBodyText: Boolean;
    var LoadedText: TWPRTFDataBlock) of object;

  TWPIOSaveWithWriter = procedure(
    RTFData: TWPRTFDataCollection;
    Writer: TWPCustomTextWriter;
    Stream: TStream;
    DisplayedRTFBlock: TWPRTFDataBlock;
    par_s, par_e: TParagraph; pos_in_par_s, pos_in_par_e:
    Integer) of object;

The TWPRTFDataCollection event properties are:

property BeforeLoadFromStream: TWPIOLoadWithReader;
property AfterLoadFromStream: TWPIOAfterLoadWithReader;
property BeforeSaveToStream: TWPIOSaveWithWriter;

Julian

#5 ♥ 0
support

Hi,

WPTools 5.10 now allows appending of options for the reader and writer to the format string, example: "WPTOOLS-onlybody"

The additional parameters are parsed by the procedure SetOptions(optstr: string) which can be overriden in the reader and writer classes.

This is the default implementation:

procedure TWPToolsReaderWriter.SetOptions(optstr: string);
var i: Integer;
begin
  i := Pos('-', optstr);
  if i > 0 then
  begin
    optstr := lowercase(Copy(optstr, i, Length(optstr) - i)) + ',';
    if Pos('-onlybody,', optstr) > 0 then
      FOptOnlyBody := TRUE;
    if Pos('-nostyles,', optstr) > 0 then
      FOptNoStyles := TRUE;
    if Pos('-nonumstyles,', optstr) > 0 then
      FOptNoNumStyles := TRUE;
    if Pos('-noimages,', optstr) > 0 then
      FOptNoImages := TRUE;
    if Pos('-basetext,', optstr) > 0 then
      FOptBaseText := TRUE;
    if Pos('-novariables,', optstr) > 0 then
      FOptNoVariables := TRUE;
    if Pos('-nopageinfo,', optstr) > 0 then
      FOptNoPageInfo := TRUE;
  end;
end;

Julian Ziersch

#6 ♥ 0
This category is archived. No new posts are possible.