Create Multi View in Code

<< Click to Display Table of Contents >>

Navigation:  Programming > User Interface > Layoutmodes > Multiple Editors for the Same Text >

Create Multi View in Code

You need an event handler for the event OnInitializeRTFDataObject of the TWPRichText object. This event is executed when the text data is needed the first time. In the event handler you assign a RTFDataCollection which has been created 'outside'. You will need two variables in the TForm class:

 

TForm1 = class(TForm)

...

public

 RTFData: TWPRTFDataCollection;

 RTFDataProps: TWPRTFProps

end;

 

The event handler now initializes the variables and assigns them to any TWPRichText which is using this event handler.

 

procedure TForm1.OnInitRTFData(Sender: TObject;

var RTFDataObject: TWPRTFDataCollection;

var RTFPropsObject: TWPRTFProps);

begin

if RTFData = nil then

begin

   RTFData := TWPRTFDataCollection.Create(TWPRTFDataBlock);

   RTFDataProps := TWPRTFProps.Create;

   RTFData.RTFProps := RTFDataProps;

end;

 RTFDataObject := RTFData;

end;

 

 

Important:

 

Since you created the RTFData objects you maybe want to free those later.

Please make sure the attached TWPRichText and TWPPreview components do not use them anymore to avoid an AV.

 

procedure TWPMiniEd.FormDestroy(Sender: TObject);

begin

 WPPreview1.WPRichText := nil;

 WPRichText1.SetRTFData(nil);

 WPRichText2.SetRTFData(nil);

 RTFData.Free;

 RTFDataProps.Free;

end;