Julian,
Is there a WPTools 5 way do the same functionality as CallForCurrentParagraphs provided in previous versions?
diamond
Julian,
Is there a WPTools 5 way do the same functionality as CallForCurrentParagraphs provided in previous versions?
diamond
Hi, the procedure WPRichText1.TextCursor.CallForSelectedText can be used. It is able to report the paragraphs, the characters and the different text attributes:
procedure CallForSelectedText( Sender: TObject; Options: TWPCallForSelectedTextOptions; ParCallback: TWPParCallback; CharAttCallback: TWPCharAttrCallback; CharCallBack: TWPCharCallback; TextObjCallback: TWPTextObjectCallback; spar: TParagraph = nil; epar: TParagraph = nil; spos: Integer = 0; epos: Integer = 0);
It expects 4 call-back procedures (or nil).
TWPParCallback = procedure( Sender: TObject; par: TParagraph; IsParent: Boolean; FromChar, ToChar: Integer; var Abort: Boolean) of object; TWPCharAttrCallback = procedure(Sender: TObject; var CharAttrIndex: Cardinal; par: TParagraph; posinpar: Integer; var Abort: Boolean) of object; TWPCharCallback = procedure(Sender: TObject; var CharItem: WideChar; par: TParagraph; posinpar: Integer; var Abort: Boolean) of object; TWPTextObjectCallback = procedure(Sender: TObject; TxtObj: TWPTextObj; par: TParagraph; posinpar: Integer; var Abort: Boolean) of object;
'Sender' is the object which will be used for the callbacks.
The 'Options' will be usually []
spar, epar are optional. The engine will fill in the current selection pointers if they are missing. Otherwise they are the start and the end position.
Example: Create a string from the current selection:
procedure TForm1.DoAddCharCallback(Sender: TObject;
var CharItem: WideChar;
par: TParagraph;
posinpar: Integer;
var Abort: Boolean);
begin
TWPStringBuilder(Sender).Append(CharItem);
end;
procedure TForm1.DoAddParCallback(
Sender: TObject;
par: TParagraph;
IsParent: Boolean;
FromChar, ToChar: Integer;
var Abort: Boolean);
begin
TWPStringBuilder(Sender).Append(#13);
end;
function TForm1.GetSelectedText : String;
var str : TWPStringBuilder;
begin
str := TWPStringBuilder.Create;
try
WPRichText1.TextCursor.CallForSelectedText(
str,
[],
DoAddParCallback,
nil,
DoAddCharCallback,
nil);
Result := str.GetString;
finally
str.Free;
end;
end;
Alles anzeigen