trichview.support
Re: copy lines to clipboard |
Author |
Message |
Sergey Tkachenko |
Posted: 02/04/2004 19:49:34 Hello, Below are some procedures that I think will be useful for you. All these procedures have input paramaters: FirstParaIndex - index of the first paragraph to choose (I hope considering paragraphs as lines is ok for you). Paragraph indices are counted from 0. ParaCount - count of paragraphs to choose. GetParagraphItemRange is an internal procedure used by other procedures. SelectParagraphs selects the specified paragraphs. After calling SelectParagraphs you can call rv.CopyDef, and they will be copied to the Clipboard. GetParagraphsText returns contents of the specified paragraphs as text (without selecting them). Specifically to your questions 1) Use SelectParagraphs, then CopyDef 2) It's not possible. In order to copy lines in the Clipboard, you need to select them. But you can copy lines in plain text format: Clipboard.SetTextBuf(PChar(GetParagraphsText(...))); 3) Which position do you want to get? Use Paste method to paste from the Clipboard. You can copy document from one trichview to another without using the Clipboard procedure CopyDoc(Source, Dest: TCustomRichView); var Stream: TMemoryStream; begin Stream := TMemoryStream.Create; Source.SaveRVFToStream(Stream, False); Stream.Position := 0; Dest.LoadRVFFromFile(Stream); Stream.Free; Dest.Format; end; This procedure copied the complete document. If you want to copy only the selection, pass True instead of False in SaveRVFToStream. procedure GetParagraphItemRange(rv: TCustomRichView; FirstParaIndex, ParaCount: Integer; var FirstItemNo, EndItemNo: Integer); var i: Integer; begin FirstItemNo := -1; EndItemNo := -1; if ParaCount<=0 then exit; // searching for the FirstParaIndex-th paragraph start for i := 0 to rv.ItemCount-1 do if rv.IsParaStart(i) then begin dec(FirstParaIndex); if FirstParaIndex<0 then begin FirstItemNo := i; break; end; end; if FirstItemNo<0 then exit; // searching for the (FirstParaIndex+ParaCount-1)-th paragraph end for i := FirstItemNo to rv.ItemCount-1 do if rv.IsParaStart(i) then begin dec(ParaCount); if ParaCount<0 then begin EndItemNo := i-1; break; end; end; if EndItemNo<0 then EndItemNo := rv.ItemCount-1; end; procedure SelectParagraphs(rv: TCustomRichView; FirstParaIndex, ParaCount: Integer); var FirstItemNo, EndItemNo: Integer; begin GetParagraphItemRange(rv, FirstParaIndex, ParaCount, FirstItemNo, EndItemNo); if FirstItemNo<0 then exit; rv.SetSelectionBounds(FirstItemNo, rv.GetOffsBeforeItem(FirstItemNo), EndItemNo, rv.GetOffsAfterItem(EndItemNo)); rv.Invalidate; end; function GetParagraphsText(rv: TCustomRichView; FirstParaIndex, ParaCount: Integer): String; var FirstItemNo, EndItemNo, i: Integer; begin Result := ''; GetParagraphItemRange(rv, FirstParaIndex, ParaCount, FirstItemNo, EndItemNo); if FirstItemNo<0 then exit; Result := rv.GetItemTextA(FirstItemNo); for i := FirstItemNo+1 to EndItemNo do begin if rv.IsFromNewLine(i) then Result := Result+#13#10; Result := Result+rv.GetItemTextA(i); end; end; > > Hello, > > I'm a beginner of RVE and naturally need help. > > 1. I want to mark the lines 6 up to 11 (by speedButton). Then I want to copy > them (with all attributes) to clipboard. > 2. How can I copy the lines 6 up to 11 directly to clipboard (without marking > them) ? > 3. How can I get the positon in RichViewEdit and insert text (with attributes) > from clipboard or another RichEdit-memo to RVE-memo ? |
Powered by ABC Amber Outlook Express Converter