<< Click to Display Table of Contents >> Navigation: Programming > WPTools Premium > Text boxes > Make the text box editable |
By default the contents of textboxes cannot be edited by the user.
This can be enabled by calling "Edit" in the event OnTextObjectDblClick:
procedure TForm1.WPRichText1TextObjectDblClick(Sender: TWPCustomRtfEdit;
pobj: TWPTextObj; obj: TWPObject; var Ignore: Boolean);
begin
// Only call Edit if the text box is not in edit mode
if (obj<>nil) and (obj.GetRTFDataBlock<>Sender.ActiveText) then
begin
obj.Edit;
// optional: obj.SelectAll;
Ignore := true;
end;
end;
Screenshot of the created box in edit mode (after double click):
But how does the engine knows which text block belongs to which text box?
For this connection the property ObjName is used. The value of this property is used by function GetRTFDataBlock to locate the correct RTF Data block. (Of course, other solutions are thinkable)
function TWPORTFTextBox.GetRTFDataBlock : TWPRTFDataBlock;
begin
if (FDataCollection<>nil) and (ObjName<>'') then
Result := FDataCollection.Find(wpIsOwnerSelected, wpraNamed, ObjName)
else Result := nil;
end;
Here you see that the 'Kind' of the RTFDataBlock which is used for text boxes is wpIsOwnerSelected, the 'Range' is wpraNamed and of course it has a name.
From the code above you also can see that the RTFDataBlock is not automatically created when the function GetRTFDataBlock is used. It must be created by code such as FDataCollection.Get(wpIsOwnerSelected, wpraNamed, ObjName). This is automatically done by procedure
TWPORTFTextBox.SetAsString.
Note: Do not expect the names to be the same after a file was saved and loaded in RTF format. Only the WPTools format will preserve the object names.