trichview.support
Re: Copying image to clipboard |
Author |
Message |
Sergey Tkachenko |
Posted: 04/06/2003 21:42:49 AName is a string passed in InsertControl (or AddControlEx) as a first parameter. A name of control is Actrl.Name (but it is empty if you create it at run time (and it recommended to leave it empty to avoid several controls with the same name)). About the original question. First, if you use item indices (x in your code below), work not with RVEdit1 itself, but with RVEdit1.TopLevelEditor (otherwise this code will work incorrect if the control is in table). But is simpler just to use GetCurrentControlInfo. Second, about copying. Image should be copied if it is selected (it may be current if caret is to the right of it, but not selected). This code copied TImage to the Clipboard, if only this TImage is selected. Assign it to OnCopy event procedure TForm1.RichViewEdit1Copy(Sender: TObject); var ItemNo1, ItemNo2, Offs1, Offs2: Integer; rve: TCustomRichViewEdit; AName:string; Actrl:TControl; AValign:TRVValign; ATag:integer; begin rve := RichViewEdit1.TopLevelEditor; // retrieving selection bounds rve.GetSelectionBounds(ItemNo1, Offs1, ItemNo2, Offs2, True); if ItemNo1<0 then exit; // adjusting selection bounds if (Offs1>=rve.GetOffsAfterItem(ItemNo1)) and (ItemNo1<rve.ItemCount-1) then begin inc(ItemNo1); Offs1 := rve.GetOffsBeforeItem(ItemNo1) end; if (Offs2<=rve.GetOffsBeforeItem(ItemNo2)) and (ItemNo2>0) then begin dec(ItemNo2); Offs2 := rve.GetOffsAfterItem(ItemNo2) end; // checking and copying if (ItemNo1=ItemNo2) and (Offs1=0) and (Offs2=1) and (rve.GetItemStyle(ItemNo1)=rvsComponent) then begin rve.GetControlInfo(ItemNo1,Aname,Actrl,AVAlign,ATag); if Actrl is TImage then Clipboard.Assign(TImage(Actrl).Picture.Graphic); end; end; > > Hi Sergey, > I use the following codes but it does not returns the name of the component,e.g > Image1 Image2 etc. There was just blank. > > ======================================================== > procedure TForm1.SpeedButton3Click(Sender: TObject); > var x : integer; > AName:string;Actrl:TControl;AValign: TRVValign;ATag:integer; > begin > x:= RVEdit1.CurItemNo; > > RVEdit1.GetControlInfo(x,Aname,Actrl,AVAlign,ATag); > > {The Aname should be the control name is not it?} > Form1.Caption := Aname; //Returns EMPTY spaces!!!; > > end; > |
Powered by ABC Amber Outlook Express Converter