WPCubed Product Support

How to save custom paragraph objects when using WP.SaveToFile?

wpsupport

No, it is not since the objects itself do not contain a writing logic.

#5 ♥ 1
2.8k Views 2 users 2 ♥ read 2 min

Thank you. Would the special data be written using WPTOOLS format?

#4 ♥ 0
wpsupport

You can always use e-mail for support. We also offer reasonable priced support if you have special demands.

The TCustomParagraphObj is not used to write special data in RTF. They are mainly used be the WPReporter addon to store the band information.

#3 ♥ 1

Any feedback on this? As a workaround I've been using the TParagraph.Name property to save and load custom information.

procedure TForm1.DoSomething;
var
  par: TParagraph;
begin
  // ...
  par.Name := Format( '%s:%s:%s', [
    'my_paragraph',
    customIntProperty.ToString,
    customBoolProperty.ToString( TUseBoolStrs.True )
  ] );
  
  // ...
  WP.SaveToFile( 'C:\Temp\my.rtf', FALSE, 'RTF' );
end;

procedure TForm1.RestoreSomething;
var
  par: TParagraph;
  propertiesList: TArray<String>;
begin
  WP.LoadFromFile( 'C:\Temp\my.rtf', TRUE, 'RTF' );
  
  // ...  
  propertiesList := par.Name.Split( [ ':' ] );
  try
    customIntProperty := propertiesList[ 1 ].ToInteger;
    customBoolProperty := propertiesList[ 2 ].ToBoolean;
  finally
    Finalize( propertiesList );
  end;
end;

It works, but it doesn't feel right.

#2 ✎ ♥ 0

I'm experimenting with TCustomParagraphObj and had the impression that I could save custom information (converted to a string) when saving a WP document as a RTF file via SaveToFile

But it seems that the custom paragraph object's GetAsString function is not being called when saving the document. You recommend to attach a TCustomParagraphObj to save custom information here:

This is what I did:

unit UMyCustomParagraphObject;

interface

uses
  WPRTEDefs;

type
  TMyCustomParagraphObject = class(TCustomParagraphObj)
    constructor Create(AType: Integer; const AMyCustomObject: TObject);
  private
    FMyCustomObject: TObject;
  protected
    procedure SetAsString(const AString: String); override;
    function GetAsString: String; override;
  public
    property ParagraphObjType: Integer
      read  FParagraphObjTyp;
  end;

implementation

uses
  UMyCustomObject;

{ TMyCustomParagraphObject }

constructor TMyCustomParagraphObject.Create(AType: Integer;
  const AMyCustom: TObject);
begin
  inherited Create( WPPAROBJ_USER + AType );
  FMyCustomObject := AMyCustom;
end;

function TMyCustomParagraphObject.GetAsString: String;
begin
  Result := 'Hi Mom!';
end;

procedure TMyCustomParagraphObject.SetAsString(const AString: String);
begin
  inherited;
end;

end.

Then in another unit:

...
FParagraphObject := TMyCustomParagraphObject.Create( Ord( FMyParagraphType ), Self );

...
if not Assigned( paragraph.ParagraphObjFind( FParagraphObject.ParagraphObjType ) ) then
  paragraph.ParagraphObjAdd( FParagraphObject );

And finally:

WP.SaveToFile( 'C:\Temp\test.rtf', FALSE, 'RTF' );

When stepping through the code with the debugger I can see that the FParagraphObject is being added to the paragraph via paragraph.ParagraphObjAdd( FParagraphObject ) but when saving the document the TMyCustomPargraphObject.GetAsString function is not being called.

What am I doing wrong?

#1 ♥ 0