procedure TForm1.mnuOleClick(Sender: TObject);
var
ole: TOleContainer;
begin
ole := TOleContainer.Create(Self);
ole.Caption := 'Test Container';
ole.SizeMode:=smStretch;
ole.BorderStyle:=bsNone;
ole.OnMouseDown:=OleMouseDown;
ole.OnMouseMove:=OleMouseMove;
RichViewEdit1.InsertControl('',ole,rvvaBaseline);
if RichViewEdit1.CurItemStyle=rvsComponent then
RichViewEdit1.SetCurrentItemExtraIntProperty(rvepResizable, 1, True);
end;
procedure TForm1.OleMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then begin
RichViewEdit1.SelectControl(TControl(Sender));
ClickedControl := Sender;
ClickPoint := Point(X, Y);
end;
end;
procedure TForm1.OleMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if (ssLeft in Shift) and (ClickedControl=Sender) and
(Sqr(ClickPoint.X-X)+Sqr(ClickPoint.Y-Y)>10) then
RichViewEdit1.BeginOleDrag;
end;
However, once the control has been dragged and dropped once, it cannot be clicked on (resize points are not displayed) and dragged again. What am I doing wrong?
On drag&drop, the selected fragment is copied in RVF format.
Events cannot be saved in RVF, so all controls lose their events.
You need to reassign them in OnControlAction event.
The example can be found in Demos\Delphi\Editors\Editor 1\, search for "ole" in the main form's unit.
Sergey Tkachenko wrote:On drag&drop, the selected fragment is copied in RVF format.
Events cannot be saved in RVF, so all controls lose their events.
You need to reassign them in OnControlAction event.
The example can be found in Demos\Delphi\Editors\Editor 1\, search for "ole" in the main form's unit.
Thanks. Adding the events for OnMouseDown and OnMouseMove to the RE's existing OnControlAction event solved the problem. I had added another OnControlAction event at the end of the program source and that was the reason the event was not firing.
Will the above code also work if I am using RTF as the format?
Controls are not saved in RTF or HTML. OnSaveComponentToFile event occurs insted. In this event you can provide code representing this control (but if cause, you need to know RTF/HTML to process it).
Saving TOleContainer in RTF is discussed here: http://www.trichview.com/forums/viewtopic.php?t=118