Entering text and seeking information
Entering text and seeking information
Hello Sergey.
Everything good?
I'm having a hard time and need your help. First explain what happens. Srichviewedit I use as a component for printing from a register, or seek information from a database and insert the srichview in the form of a text, ok. So I need to know:
1) What is the position of the last valid character (blank space can not count) in row and column?
2) How many characters still fit within that page?
3) How many lines there are still empty from the last character to the end of the page?
4) How to get text input from the line (x) and column (y)?
I need these data apart from the cursor position. I need this information in time for the automatic insertion of text in srichviewedit.
Why is this .. I will use a method where I will give a "InsertText" from "x" and "y " and need to know how many characters can I enter to the final page.
Thank you for listening.
Graciously Ceprotec.
Everything good?
I'm having a hard time and need your help. First explain what happens. Srichviewedit I use as a component for printing from a register, or seek information from a database and insert the srichview in the form of a text, ok. So I need to know:
1) What is the position of the last valid character (blank space can not count) in row and column?
2) How many characters still fit within that page?
3) How many lines there are still empty from the last character to the end of the page?
4) How to get text input from the line (x) and column (y)?
I need these data apart from the cursor position. I need this information in time for the automatic insertion of text in srichviewedit.
Why is this .. I will use a method where I will give a "InsertText" from "x" and "y " and need to know how many characters can I enter to the final page.
Thank you for listening.
Graciously Ceprotec.
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Code: Select all
var i, j, l, c: Integer;
rve: TCustomRichViewEdit;
s: String;
begin
rve := SRichViewEdit1.RichViewEdit;
for i := rve.ItemCount-1 downto 0 do
if (rve.GetItemStyle(i)>=0) then begin
s := rve.GetItemText(i);
for j := Length(s) downto 1 do
if s[j]<>' ' then begin
rve.SetSelectionBounds(i, j, i, j);
rve.GetCurrentLineCol(l, c);
Caption := Format('(%d %d)', [l, c]);
exit;
end;
end;
Caption := 'no characters';
end;
It moves the caret before this character. If you need version without moving the caret, let me know.
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
I can write this function, but it would require using some undocumented methods.
But do you really need using (line, column) kind of coordinates for defining position in the document? They are not native for TRichViewEdit/TSRichViewEdit, so using them require additional efforts that better to be avoided.
The most simple and efficient for TRichViewEdit is using (Item index, offset in item) pair of coordinate.
Or there are functions allowing working with "position from the beginning" coordinate (i.e. richedit-like SelStart).
But do you really need using (line, column) kind of coordinates for defining position in the document? They are not native for TRichViewEdit/TSRichViewEdit, so using them require additional efforts that better to be avoided.
The most simple and efficient for TRichViewEdit is using (Item index, offset in item) pair of coordinate.
Or there are functions allowing working with "position from the beginning" coordinate (i.e. richedit-like SelStart).
Actually I only need the line, it will always be in column 0 (zero).
Example:
With the formula above I know that line is the last character. Now I need a formula to insert text from the line (l). Like a InsertText ('', l). Would do that?
That also would direct the cursor to the line (l) / column (c) and use a InsertText () normal.
Example:
With the formula above I know that line is the last character. Now I need a formula to insert text from the line (l). Like a InsertText ('', l). Would do that?
That also would direct the cursor to the line (l) / column (c) and use a InsertText () normal.
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Lines depend on word wrapping. When you insert something at the beginning of line that is not the beginning of paragraph, this line may be wrapped differently. You may insert at the beginning of line, but after the insertion it may become not a beginning.
Are you sure that you mean "lines", not "paragraphs"?
Are you sure that you mean "lines", not "paragraphs"?
Yesterday you gave me a formula that took the position of the last character, right?
Suppose that the last character is on the line ( 18 ) and column ( 58 ), right?
so I need a command that will insert a string line (19) and column (0), which would be the beginning of the paragraph within the margin set, for example.
Suppose that the last character is on the line ( 18 ) and column ( 58 ), right?
so I need a command that will insert a string line (19) and column (0), which would be the beginning of the paragraph within the margin set, for example.
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Than function returns the position of the last non-space character. So there may be some lines after this line (empty text or spaces, or pictures), or may be not.
So, in your example, the line #19 may exist or may not exist.
Ok, below is the function that works in all cases:
So, in your example, the line #19 may exist or may not exist.
Ok, below is the function that works in all cases:
Code: Select all
uses DLines;
procedure GoToLine(LineNo: Integer; rve: TCustomRichViewEdit);
var i: Integer;
begin
// moving before existing line, if possible
for i := 0 to rve.RVData.DrawItems.Count-1 do
if rve.RVData.DrawItems[i].FromNewLine then begin
dec(LineNo);
if LineNo=0 then begin
rve.SetSelectionBounds(rve.RVData.DrawItems[i].ItemNo,
rve.RVData.DrawItems[i].Offs,
rve.RVData.DrawItems[i].ItemNo,
rve.RVData.DrawItems[i].Offs);
exit;
end;
end;
// adding new lines
i := rve.ItemCount-1;
rve.SetSelectionBounds(i, rve.GetOffsAfterItem(i), i, rve.GetOffsAfterItem(i));
while LineNo>0 do begin
rve.InsertText(#13#10);
dec(LineNo);
end;
end;
...
GoToLine(SRichViewEdit1.RichViewEdit, 19);
SRichViewEdit1.RichViewEdit.InsertText('Hi!');