Hello,
let me explain, what I'm going to do:
My RVEdit will load any RichText files with or w/o tables. Each document contains macro names like "{$name}", which will be replaced by the program with certain strings. So far so good.
Now, it's necessary to determin, if a specific macro name is inside a table cell or not. If it is inside a table cell, the whole table row should be duplicated instead of only relpacing the macro name with a text string.
So - How can I implement this feature? There are the following things to do for me (as far as I think):
1) Determin, if a text item (or the current selection or the caret) is inside a table cell.
2) Select and copy the whole row, this determinde cell belongs to
3) Inserting the copied row after this row.
Can anybody help me? Especially how to realize 1)
Thank you for any hints!
How to determin, if selected text is inside a table cell?
-
- Site Admin
- Posts: 17520
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
If you are really asking for the location of the SELECTED text, it's easy: the selected text is in the cell if table.InplaceEditor<>nil.
This table can be found by GetCurrentItemEx method, for example.
Saving row: table.SaveRowsToStream.
Loading row: InsertRows, then (undocumented) LoadFromStreamEx.
table.LoadFromStreamEx(Stream: TStream; StartRow: Integer);
StartRow - the top row where the stream content will be loaded.
This table can be found by GetCurrentItemEx method, for example.
Saving row: table.SaveRowsToStream.
Loading row: InsertRows, then (undocumented) LoadFromStreamEx.
table.LoadFromStreamEx(Stream: TStream; StartRow: Integer);
StartRow - the top row where the stream content will be loaded.
Thank you, this hint helped me a lot!
Now, trying to replace the copied cell text with another string, I get some problems. The cell text is selected but inserting a new text, does not overwrite the selected cell text but inserts the new text to the top if the document. Have a look to my code, please:
What do I wrong?
Now, trying to replace the copied cell text with another string, I get some problems. The cell text is selected but inserting a new text, does not overwrite the selected cell text but inserts the new text to the top if the document. Have a look to my code, please:
Code: Select all
var Item: TCustomRVItemInfo;
RV: TCustomRichViewEdit;
Row, Col: Integer;
Stream: TStream;
begin
RVEdit.GetCurrentItemEx(TRVTableItemInfo, RV, Item);
if Item is TRVTableItemInfo then
begin
(Item as TRVTableItemInfo).GetEditedCell(Row, Col);
Stream := TMemoryStream.Create;
with Item as TRVTableItemInfo do
try
SaveRowsToStream(Stream, Row, 1);
InsertRowsBelow(1);
Stream.Position := 0;
LoadFromStreamEx(Stream, Row+1);
RV.Format;
Cells[Row+1, Col].SelectAll;
RV.InsertText('Sample Text');
finally
Stream.Free;
end;
end;
end;
-
- Site Admin
- Posts: 17520
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Call Cells[Row+1, Col].Edit before Cells[Row+1, Col].SelectAll;
Calling cell.Edit is necessary in the editor before selecting in this cell.
Note 1: Calling BeginItemModify before SaveRowsToStream and EndItemModify may be faster than calling Format.
Note 2: Please call RV.ClearUndo after this code, because this code is a mix of viewer-style and editing-style methods, so it cannot be undone correctly.
Calling cell.Edit is necessary in the editor before selecting in this cell.
Note 1: Calling BeginItemModify before SaveRowsToStream and EndItemModify may be faster than calling Format.
Note 2: Please call RV.ClearUndo after this code, because this code is a mix of viewer-style and editing-style methods, so it cannot be undone correctly.
-
- Site Admin
- Posts: 17520
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
These are methods of RichViewEdit, not of the table class.
They must be called for the editor that directly contains the table (it is returned by GetCurrentItemEx, in RV in your code).
The purpose of BeginItemModify-EndItemModify is replacing Format.
They try to reformat only the table, not the whole document, so they are faster.
The meaning of the parameter is not so important. It is something calculated in BeginItemModify and used in EndItemModify for more efficient processing.
They must be called for the editor that directly contains the table (it is returned by GetCurrentItemEx, in RV in your code).
The purpose of BeginItemModify-EndItemModify is replacing Format.
They try to reformat only the table, not the whole document, so they are faster.
The meaning of the parameter is not so important. It is something calculated in BeginItemModify and used in EndItemModify for more efficient processing.