trichview.support
Re: Move Caret to Line/Col |
Author |
Message |
Sergey Tkachenko |
Posted: 08/07/2004 16:57:02 It's possible to implement this using undocumented methods. The most of code related to formatting is hidden in private or protected sections of classes. Line/Column pair depends on formatting - when you resize window, lines may wrap differently (if no-wrap option is not set for the paragraph), and the same Line/Column values will correspond to different location in the document. Nevertheless, this is the code: function MoveToLineCol(rve: TCustomRichViewEdit; Line, Col: Integer): Boolean; var i, DItemNo, DOffs: Integer; function GetDItemLength(i: Integer): Integer; begin if rve.RVData.GetItemStyle(rve.RVData.DrawItems[i].ItemNo)<0 then Result := 1 else Result := rve.RVData.DrawItems[i].Length; end; begin Result := False; DItemNo := -1; DOffs := -1; for i := 0 to rve.RVData.DrawItems.Count-1 do if rve.RVData.DrawItems[i].FromNewLine then begin dec(Line); if Line=0 then begin DItemNo := i; break; end; end; if DItemNo<0 then exit; if rve.RVData.GetItemStyle(rve.RVData.DrawItems[DItemNo].ItemNo)=rvsListMarker then inc(DItemNo); if GetDItemLength(DItemNo)+1>=Col then begin DOffs := rve.RVData.GetOffsBeforeDrawItem(DItemNo)+Col-1; Result := True; end else begin dec(Col, GetDItemLength(DItemNo)+1); for i := DItemNo+1 to rve.RVData.DrawItems.Count-1 do begin if rve.RVData.DrawItems[i].FromNewLine then exit; if GetDItemLength(i)>=Col then begin DItemNo := i; DOffs := rve.RVData.GetOffsBeforeDrawItem(DItemNo)+Col; Result := True; break; end; dec(Col, GetDItemLength(i)); end; end; rve.RVData.DrawItem2Item(DItemNo, DOffs, DItemNo, DOffs); rve.SetSelectionBounds(DItemNo, DOffs, DItemNo, DOffs); rve.Invalidate; end; > > Hello, > I would like to jump to a specific text location inside a RichViewEdit. > The location would be "line, column", not coordinates of the RichViewEdit. > Something like a function "Goto (line, column)". > I found a function to obtain the current line and column (GetCurrentLineCol), > but nothing to set them. > Is this possible? > Thank you! > Holger |
Powered by ABC Amber Outlook Express Converter