Inserted Ole Container Can Only Be Dragged Once

General TRichView support forum. Please post your questions here
Post Reply
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Inserted Ole Container Can Only Be Dragged Once

Post by fchintc »

I am using the RVEditDemo program and have added the capability to add an Ole Container via the menu using the following code:-

Code: Select all

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?

Frederick
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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.
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

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?

Frederick
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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
Post Reply