|
Images |
Top Previous Next |
|
(This screenshot shows text and a floating object in WPTools 5.)
Insert a graphic:
procedure TForm1.InsertGraphicClick(Sender: TObject); var txtobj: TWPTextObj; begin if OpenDialog2.Execute and (WPRichText1.ActiveParagraph <> nil) then begin WPRichText1.SetFocus; txtobj := WPRichText1.Memo.RTFData.TextObjects.Insert( WPLoadObjectFromFile( WPRichText1.Memo.RTFData, OpenDialog2.FileName), 1440, 1440); // Code to change the graphic, for example change width and height ot the 'PositionMode' if txtobj <> nil then begin
end; WPRichText1.Refresh; end; end;
Note: If you need to work directly with a TParagraph you can use the method TParagraph.AppendNewObject to create a new TWPTextObj object. To the ObjRef property of this object you can assign the TWPObject instance created by WPLoadObjectFromFile. (See CreateTable demo)
Modify selected object:
procedure TForm1.ChangeObjectPositionAndWrapMode(Sender: TObject); begin if WPRichText1.TextObjects.SelectedObj<>nil then begin WPRichText1.TextObjects.ChangePositionMode( WPRichText1.TextObjects.SelectedObj, wpotPar, wpwrBoth); end; end;
Load new image into object:
procedure TForm1.Loadimage1Click(Sender: TObject); begin if (WPRichText1.TextObjects.SelectedObj<>nil) and (OpenPictureDialog1.Execute) then begin WPRichText1.TextObjects.SelectedObj.LoadObjFromFile( OpenPictureDialog1.FileName); end; end;
Replace text with a graphic file
var GSFile: string; TextObject: TWPOImage; // from unit WPObj_Image begin GSFile := 'C:\testfile.jpg'; if FileExists(GSFile) then with WPRichText1 do begin Finder.ToStart; while Finder.Next('<<Graphic-Signature>>') do begin TextObject := TWPOImage.Create(WPRichText1.Memo.RTFData); // ! TextObject.LoadFromFile(GSFile); SetSelPosLen(Finder.FoundPosition, Finder.FoundLength); TextObjects.Insert(TextObject); end; end; end;
Alternative, using a graphic from an TImage object:
WPRichText1.Finder.ToStart; while WPRichText1.Finder.Next('[sig]') do begin WPRichText1.CPPosition := WPRichText1.Finder.FoundPosition; WPRichText1.Finder.FoundText := ''; WPRichText1.TextObjects.InsertCopy(Image1.Picture.Graphic); end; WPRichText1.DelayedReformat;
Hint: It would be also possible to use modify WPRichText1.TextObjects.SelectedObj.Wrap and WPRichText1.TextObjects.SelectedObj.PositionMode directly but this change is not logged for undo. |