Cloning line from the table that is inside another table
Posted: Wed Mar 24, 2021 6:58 pm
Hi Sergey,
I have the following function:
How to use:
But when you have a table inside another table, it replicates wrong. Look (In green it would be correct):
How can I adapt my role?
Thanks!
I have the following function:
Code: Select all
procedure ReplicaLinhasTabela ( Editor : TSRichViewEdit; Data : TStringListArray; ShowProgress : Boolean = False; lblProgress : TLabel = nil ) ;
var
ItemNo : Integer;
IndexVar : Integer;
PossuiVar : Boolean;
PrimaryIndex : Integer;
count : Integer;
j , i , k , b : Integer;
table : TRVTableItemInfo;
VariablesEx : string;
columns : array of TMemoryStream;
begin
try
VariablesEx := '';
for i := Low ( Data ) to High ( Data ) do
begin
if Assigned ( Data[ i ] ) = True then
begin
for j := 0 to ( Data[ i ] .Count - 1 ) do
VariablesEx := iif ( VariablesEx = '' , '{' + Data[ i ] .Names[ j ] + '}' , VariablesEx + ',' + '{' + Data[ i ] .Names[ j ] + '}' ) ;
end;
end;
Editor.Format;
for ItemNo := ( Editor.RichViewEdit.ItemCount - 1 ) downto 0 do
begin
if Editor.RichViewEdit.GetItemStyle ( ItemNo ) = rvsTable then
begin
table := TRVTableItemInfo ( Editor.RichViewEdit.GetItem ( ItemNo ) ) ;
IndexVar := -1;
PossuiVar := False;
{ COPIA AS INFORMAÇÕES DA LINHA ONDE FOI ACHADO AS VARIÁVEIS }
for j := 0 to ( table.Rows.Count - 1 ) do
begin
PossuiVar := False;
for i := 0 to ( table.Rows[ j ] .Count - 1 ) do
begin
if table.Cells[ j , i ] <> nil then
begin
if table.Cells[ j , i ] .GetRVData <> nil then
begin
if VarInTable ( table.Cells[ j , i ] .GetRVData , VariablesEx ) = True then
begin
IndexVar := j;
PossuiVar := True;
Break;
end;
end;
end;
end;
if PossuiVar = True then
begin
SetLength ( columns , table.Rows[ j ] .Count ) ;
for i := 0 to ( table.Rows[ j ] .Count - 1 ) do
begin
if table.Cells[ j , i ] <> nil then
begin
columns[ i ] := TMemoryStream.Create;
table.Cells[ j , i ] .Edit ( ) ;
Editor.RichViewEdit.TopLevelEditor.SaveRVFToStream ( columns[ i ] , False ) ;
end;
end;
Break;
end;
end;
{ FIM }
if PossuiVar = True then
begin
k := 0;
PrimaryIndex := IndexVar;
if ( ShowProgress = True ) and ( Assigned ( lblProgress ) = True ) then
count := Length ( Data )
else
count := 0;
for b := Low ( Data ) to High ( Data ) do
begin
if ( ShowProgress = True ) and ( count > 0 ) then
begin
lblProgress.Caption := 'Replicando linhas (' + IntToStr ( b ) + '/' + IntToStr ( count ) + ') ...';
Application.ProcessMessages;
end;
if ( IndexVar >= 0 ) and ( k > 0 ) then
begin
table.InsertRows ( ( IndexVar + 1 ) , 1 , PrimaryIndex , False ) ;
for j := 0 to ( table.Rows[ ( IndexVar + 1 ) ] .Count - 1 ) do
begin
if table.Cells[ ( IndexVar + 1 ) , j ] <> nil then
table.Cells[ ( IndexVar + 1 ) , j ] .Clear;
end;
{ REPLICAR OS VALORES E O ESTILO DA PRIMEIRA LINHA }
for j := Low ( columns ) to High ( columns ) do
begin
if ( Assigned ( columns[ j ] ) = True ) and ( table.Cells[ ( IndexVar + 1 ) , j ] <> nil ) then
begin
columns[ j ] .Position := 0;
table.Cells[ ( IndexVar + 1 ) , j ] .Edit ( ) ;
Editor.RichViewEdit.TopLevelEditor.RVFOptions := Editor.RichViewEdit.TopLevelEditor.RVFOptions - [ rvfoLoadDocProperties ] ;
Editor.RichViewEdit.TopLevelEditor.LoadRVFFromStream ( columns[ j ] ) ;
Editor.RichViewEdit.TopLevelEditor.RVFOptions := Editor.RichViewEdit.TopLevelEditor.RVFOptions + [ rvfoLoadDocProperties ] ;
end;
end;
{ - }
Inc ( IndexVar ) ;
end;
Editor.Format;
CustomFillFields ( Editor.RichViewEdit.RVData , Data[ b ] ) ;
Editor.Format;
Inc ( k ) ;
end;
end;
for j := Low ( columns ) to High ( columns ) do
begin
if Assigned ( columns[ j ] ) = True then
begin
columns[ j ] .Free;
columns[ j ] := nil;
end;
end;
SetLength ( columns , 0 ) ;
end;
end;
Editor.Format;
finally
ClearArrayList ( Data ) ;
end;
end;
Code: Select all
ReplicaLinhasTabela ( SRichViewEdit , QueryToArrayList ( memTextoTeste , 'descricao=TITULO_VARIAVEL|variavel=VARIAVEL' ) , False , nil ) ;
How can I adapt my role?
Thanks!