| View previous topic :: View next topic |
| Author |
Message |
Antti Kurenniemi
Joined: 22 May 2009 Posts: 10
|
Posted: Mon Feb 22, 2010 5:22 am Post subject: Bullets lost from bulleted lists when using FastAppendText |
|
|
I have an app in which I compose a "master" document from a bunch of smaller ones. All of these are WPTools documents. Composing the master document is done using FastAppendText.
There is a problem that if any of the smaller docs contain bulleted lists, the bullets are lost, i.e. they do not appear in the master document. Numbered lists seem to be ok. The list text is seen as expected, but just the bullet marks are not visible.
I already got advice from support to use the same RTFDataCollection for both (all) RTF engines, but I'm at loss how to do that, so I would appreciate a sample or any other "for dummies" level help.
I'm currently using WPTools version 6.05.8 and Delphi 2007.
TIA,
Antti Kurenniemi |
|
| Back to top |
|
 |
wpsupport Site Admin
Joined: 24 Oct 2003 Posts: 5658
|
Posted: Mon Feb 22, 2010 8:03 am Post subject: |
|
|
Hi,
Using "the same RTFDataCollection" requires the use of the event OnInitializeRTFData.
Please see here:
http://www.wpcubed.com/manuals/wptools5/IDH_TWPRichText_OnInitializeRTFData.htm
Here You can create a TWPRTFProps
or a TWPRTFDataCollection object and assign it to the var parameter. The defaukt is <nil> and means it will create the required object on its own.
There is a demo under tasks "GlobalStyle" which uses this technique. Alos interesting demo "MailM4".
Julian
(Edited: referred to OnInitializedRTFData which was wrong)
Last edited by wpsupport on Wed Feb 24, 2010 10:27 am; edited 3 times in total |
|
| Back to top |
|
 |
Antti Kurenniemi
Joined: 22 May 2009 Posts: 10
|
Posted: Mon Feb 22, 2010 8:47 am Post subject: |
|
|
Hiya,
thanks, I got a bit further now: it works correctly when all the editors involved are visual, created at design time, but not when there is an editor created dynamically at runtime (i.e. for reading the content from database).
I added an OnInitializedRTFData event for the dynamically created edit as well, and have checked that it gets called. It is assigning the same WPGlobalRTFProps object as for the other (visual) editors which is created in the form create event.
What should I do to create the editor dynamically? Right now (for this test anyway) I'm not doing anything except
| Code: | TempEditor := TWPRichText.Create(nil);
TempEditor.OnInitializedRTFData := Initialize_Temp; |
And in the Initialize_Temp
| Code: | | RTFPropsObject := WPGlobalRTFProps; |
|
|
| Back to top |
|
 |
Antti Kurenniemi
Joined: 22 May 2009 Posts: 10
|
Posted: Wed Feb 24, 2010 7:36 am Post subject: |
|
|
I have further information about this. Seems the problem comes from where I load the editor content from the database. I load it from a Blob field and assign it to my "temp" editor (non-visual, created dynamically) using AsString - after this the formatting is wrong.
I tested assigning the text to the "temp" editor using FastAppendText, and then from there on to the "master" editor, and that worked just fine.
So now the problem is that I need to load the content from a database and assign it to a temp editor, after which the styles formatting is lost.
The whole thing is like this:
| Code: | procedure TForm1.FormShow(Sender: TObject);
var
TempEditor: TWPRichText;
begin
// Copying via a temporary editor created on the fly doesn't work:
TempEditor := TWPRichText.Create(nil);
TempEditor.OnInitializedRTFData := Initialize_Temp;
// Simply calling FastAppendText between two visible editors works correctly:
Editor3.FastAppendText(Editor1);
TempEditor.AsString := Editor2.AsString; // This doesn't work - it causes the styles to be lost
// TempEditor.FastAppendText(Editor2); // This would work correctly, but I
// need to use AsString when loading the
// content from database
Editor3.FastAppendText(TempEditor);
end; |
There are Editor1 and Editor2, both containing a small piece of text with a bulleted list. Editor3 is empty at design time, and these two are merged into it. If I just do FastAppendText with both Editor1 and Editor2, it's ok, but not when the TempEditor is loaded from database using AsString.
Any ideas? Sorry to nag on about this, but it's pretty important for me to get this working somehow. |
|
| Back to top |
|
 |
Jamier
Joined: 28 May 2009 Posts: 6
|
Posted: Wed Feb 24, 2010 9:19 am Post subject: |
|
|
I'm pretty much trying to do the same thing as you be haven't gotten as far. My situation is a bit simpler.
I hav two editors Editor1 and Editor2. Editor2 has some text with bullet points in it. I want to copy editor Editor2 in to Editor1 using FastAppendText and keep the bullet points.
I have hooked both controls up to OnInitializedRTData but I'm not sure what code to put in the event handler.
Any chance you could post your code for that handler?
Thanks,
Jamie |
|
| Back to top |
|
 |
Antti Kurenniemi
Joined: 22 May 2009 Posts: 10
|
Posted: Wed Feb 24, 2010 9:35 am Post subject: |
|
|
Jamier,
just this one thing:
| Code: | | RTFPropsObject := WPGlobalRTFProps; |
The WPGlobalRTFProps object is of type TWPRTFProps and is a public variable in my unit. I initialize it in the form create event as
| Code: | WPGlobalRTFProps := TWPRTFProps.Create;
WPGlobalRTFProps.Locked := TRUE; |
and then assign the same object to each editor. |
|
| Back to top |
|
 |
wpsupport Site Admin
Joined: 24 Oct 2003 Posts: 5658
|
Posted: Wed Feb 24, 2010 10:16 am Post subject: |
|
|
I am sorry,
I made this mistake myself.
please do not use
OnInitializedRTFData
(OnInitializedRTFData is called later. It can be used to read and modify the objects but not suitable to exchange the RTFDataProps)
use
InitializeRTFDataObject
I posted a demo here:
http://www.wpcubed.com/ftp/ex/ShareRTFProps.zip
If the following event handler is used for all TWPRichText (source and destination) the numbering should survive the FastAppendText call and the bullet dialog should display the same list for all editors.
| Code: | var glRTFPropsObject: TWPRTFProps;
procedure TForm1.WPRichText1InitializeRTFDataObject(Sender: TObject;
var RTFDataObject: TWPRTFDataCollection;
var RTFPropsObject: TWPRTFProps);
begin
if glRTFPropsObject=nil then
glRTFPropsObject := TWPRTFProps.Create;
RTFPropsObject := glRTFPropsObject;
end; |
Regards,
Julian Ziersch |
|
| Back to top |
|
 |
Jamier
Joined: 28 May 2009 Posts: 6
|
Posted: Wed Feb 24, 2010 11:03 am Post subject: |
|
|
| Thanks very much guys, I got it working. |
|
| Back to top |
|
 |
Antti Kurenniemi
Joined: 22 May 2009 Posts: 10
|
Posted: Wed Feb 24, 2010 12:46 pm Post subject: |
|
|
Hi Julian,
thanks, but still no go; it works as long as all the editors are inserted on the form at design time, but not if I create one at runtime, then it just messes the formatting. It actually now fails differently: the bullets are there, but bold text "leaks", i.e. everything after a single bold line is still bold.
This is the whole unit I have, nothing else:
| Code: | unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WPRTEDefs, WPCTRMemo, WPCTRRich, ExtCtrls;
type
TForm1 = class(TForm)
Editor1: TWPRichText;
Editor2: TWPRichText;
Editor3: TWPRichText;
procedure FormShow(Sender: TObject);
procedure Editor1InitializeRTFDataObject(Sender: TObject;
var RTFDataObject: TWPRTFDataCollection; var RTFPropsObject: TWPRTFProps);
private
{ Private declarations }
public
{ Public declarations }
WPGlobalRTFProps: TWPRTFProps;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Editor1InitializeRTFDataObject(Sender: TObject;
var RTFDataObject: TWPRTFDataCollection; var RTFPropsObject: TWPRTFProps);
begin
if WPGlobalRTFProps = nil then
WPGlobalRTFProps := TWPRTFProps.Create;
RTFPropsObject := WPGlobalRTFProps;
end;
procedure TForm1.FormShow(Sender: TObject);
var
TempEditor: TWPRichText;
begin
TempEditor := TWPRichText.Create(nil);
TempEditor.OnInitializeRTFDataObject := Editor1InitializeRTFDataObject;
// Simply calling FastAppendText between two visible editors works correctly:
Editor3.FastAppendText(Editor1, False, []);
// This doesn't work - it causes the styles to be lost
TempEditor.AsString := Editor2.AsString;
Editor3.FastAppendText(TempEditor, False, []);
end;
end. |
If I change the line TempEditor.AsString to TempEditor.FastAppendText(Editor2) (obviously clear it first), then it works, but like I said I need to read the content from a database so I cannot do that. |
|
| Back to top |
|
 |
wpsupport Site Admin
Joined: 24 Oct 2003 Posts: 5658
|
Posted: Thu Feb 25, 2010 10:59 am Post subject: |
|
|
Hi,
The TWPRichText is not designed to be created dynamically. Please use the TWPCUstomRTFEdit and use the constrcutor CreateDynamic.
Please make sure ALL the editors use the same OnInitializeRTFDataObject event.
Careful with Clear or implizing Clear (AsString). Use ClearEx instead like in my demo.
If you need a working TWRichText place it on the form and set Visible to false.
Julian |
|
| Back to top |
|
 |
Antti Kurenniemi
Joined: 22 May 2009 Posts: 10
|
Posted: Sun Feb 28, 2010 2:34 pm Post subject: |
|
|
Thanks for your tips; unfortunately I still can't get this to work. I changed the dynamically created editor to be a TWPCustomRTFEdit, created using CreateDynamic, and that + the visual editor to which the combined document is created in are both using the same OnInitializeRTFDataObject event and are assigned the same TWPRTFProps object.
Bullets are still lost.
Am I doing this somehow wrong? My goal is to combine multiple (typically 50 - 100) smaller documents into one big document, and naturally I'd want all the formatting preserved. The smaller ones are created within my app, in WPRTFEdits and stored into a database.
Is there some other way I could approach this maybe? |
|
| Back to top |
|
 |
wpsupport Site Admin
Joined: 24 Oct 2003 Posts: 5658
|
Posted: Fri Mar 05, 2010 7:58 am Post subject: |
|
|
Can YOu send me Your demo, including Your test data. (There are different wasy bollets can be encoded)
Julian |
|
| Back to top |
|
 |
wpsupport Site Admin
Joined: 24 Oct 2003 Posts: 5658
|
Posted: Tue Mar 09, 2010 10:25 am Post subject: |
|
|
Thanks for Your demo.
The problem is the LoadFromFile with clear (second parameter = true).
As mentioned You need to use ClearEx.
The code should look like this:
TempDocument.ClearEx(true, false, true);
TempDocument.LoadFromFile(ExtractFilePath(Application.Exename) + 'data\' + sr.Name, False);
MasterDocument.FastAppendText(TempDocument); |
|
| Back to top |
|
 |
Antti Kurenniemi
Joined: 22 May 2009 Posts: 10
|
Posted: Tue Mar 16, 2010 5:01 pm Post subject: |
|
|
| Just an update: this was solved in an email exchange with the help from Julian (wpsupport). Turned out I was using AsString to load the contents, where I should have been using LoadFromString method. Once I changed to that, all the other help in this thread clicked into place and I'm now a happy camper :-) |
|
| Back to top |
|
 |
|