many thanks.
Your procedure runs very fine.
But only in the same table. But I want to copy to another table too.
For this reason I splitted your procedure in 2 procedures:
- in a copying procedure (SpalteKopierenClick) and
- in a pasting procedure (SpalteEinfuegenClick)
My splitted procedure work.
So I can copy the 2. column of Table and/or pasting in the 5. column.
Only one little thing is wrong :
The 2. procedure copies either all cell-contents of source-col into each cell of dest-col
or only the last cell-content of source-col into each cell of dest-col.
No wonder. You selects a cell and write her immediately into the dest-cell of the same rveTable then you freed Stream1(.free) and creates stream1 new (stream1:= TMemoryStream.create). Stream1 contains only the contents of one cell.
Can you correct my mistake ?
Jürgen
Code: Select all
procedure TForm1.SpalteKopierenClick(Sender: TObject);
var r: integer;
UnusedColor: TColor;
oldps, oldts:TRVFReaderStyleMode;
begin
if (not memo.CanChange) or (not memo.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(rveTable))) then begin
ShowMessage('Tabelle hat nicht den Focus.');
exit;
end;
rveTable.GetEditedCell(r, rveTspalte);
{ private:
rveTspalte: integer;
rveTable: TRVTableItemInfo;
stream1: TMemoryStream;
}
UnusedColor := clNone;
oldps := memo.RVFParaStylesReadMode;
oldts := memo.RVFTextStylesReadMode;
memo.RVFParaStylesReadMode := rvf_sIgnore;
memo.RVFTextStylesReadMode := rvf_sIgnore;
SendMessage(memo.Handle, WM_SETREDRAW, 0, 0);
try
stream1.Clear; //--> all cell-contents of source-col shall copied to each cell of selected dest-col
for r := 0 to rveTable.Rows.Count-1 do
if rveTable.Cells[r, rveTspalte]<>nil then begin
//stream1.clear; //only the cell-content of last source-col shall copied to each cell of selected dest-col
rveTable.Cells[r, rveTspalte].GetRVData.SaveRVFToStream(Stream1, False, UnusedColor, nil, nil);
end;
finally
memo.RVFParaStylesReadMode := oldps;
memo.RVFTextStylesReadMode := oldts;
SendMessage(memo.Handle, WM_SETREDRAW, 1, 0);
if memo.InplaceEditor<>nil then memo.InplaceEditor.Invalidate;
//while memo.InplaceEditor<>nil do memo.InplaceEditor.Invalidate; //loop without exit
end;
end;
procedure TForm1.SpalteEinfuegenClick(Sender: TObject);
var r, rveTspalte2: integer;
begin
if (not memo.CanChange) or (not memo.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(rveTable))) then begin
ShowMessage('Tabelle hat nicht den Focus.');
exit;
end;
rveTable.GetEditedCell(r,rveTSpalte2);
SendMessage(memo.Handle, WM_SETREDRAW, 0, 0);
try
for r := 0 to rveTable.Rows.Count-1 do
if rveTable.Cells[r, rveTspalte2]<>nil then begin
Stream1.Position := 0;
rveTable.Cells[r, rveTspalte2].Edit;
memo.TopLevelEditor.SelectAll;
memo.TopLevelEditor.InsertRVFFromStreamEd(Stream1);
end;
finally
SendMessage(memo.Handle, WM_SETREDRAW, 1, 0);
end;
if table1.state in [dsEdit, dsInsert] then table1.post;
end;