Delphi if structure

Asked

Viewed 58 times

0

Greetings to you all

This piece of code is part of another one that I use to pull external texts concatenated is a lot and it’s working, only in the project here when in a load is taking 11 minutes to finish the execution, so I’m trying to exhume the code to see if it solves and decreasing this time.

You could wipe this code right here?

begin 
if StringGrid1.Cells[1,3]  ('')  then 
for i:=1 to 100 do memo40.Lines.add(StringGrid1.Cells[i,3]) 
end ;
begin 
if StringGrid1.Cells[1,4]  ('')  then 
for i:=1 to 100 do memo41.Lines.add(StringGrid1.Cells[i,4]) 
end ;
begin 
if StringGrid1.Cells[1,5]  ('')  then 
for i:=1 to 100 do memo42.Lines.add(StringGrid1.Cells[i,5]) 
end ;
begin if StringGrid1.Cells[1,6]  ('')  then 
for i:=1 to 100 do memo43.Lines.add(StringGrid1.Cells[i,6]) 
end ;
begin 
if StringGrid1.Cells[1,7]  ('')  then 
for i:=1 to 100 do memo44.Lines.add(StringGrid1.Cells[i,7])
end ;
begin 
if StringGrid1.Cells[1,8]  ('')  
then for i:=1 to 100 do memo45.Lines.add(StringGrid1.Cells[i,8]) 
end ;
begin 
if StringGrid1.Cells[1,9]  ('')  then 
for i:=1 to 100 do memo46.Lines.add(StringGrid1.Cells[i,9]) 
end ;
begin 
if StringGrid1.Cells[1,10] ('')  then 
for i:=1 to 100 do memo47.Lines.add(StringGrid1.Cells[i,10])
end ;
begin if StringGrid1.Cells[1,11] ('')  then 
for i:=1 to 100 do memo48.Lines.add(StringGrid1.Cells[i,11])
end ;
Begin if Stringgrid1.Cells[1,12] ('') then for i:=1 to 100 of memo49.Lines.add(Stringgrid1.Cells[i,12]) end ;

  • while posting not because it did not appear the difference sign <> I tried to hit , then all lines are in this format if Stringgrid1.Cells[x,y]<> ('') then

1 answer

3

memo40.Lines.BeginUpdate;
for j := 3 to 12 do
    if  StringGrid1.Cells[1, j]('') then
        for i := 1 to 100 do
            memo40.Lines.add(StringGrid1.Cells[i, j]);
memo40.Lines.EndUpdate;

It is necessary to declare j where you declare i.

The use of BeginUpdate and EndUpdate should substantially increase the speed of the operation. Without this, Delphi will update the element to every new line that is added, which is unnecessarily time consuming.

  • Havenard that nice, grateful ok can let that I will declare J too, truth, I was testing the program at maximum load but was consuming a lot of time, that cool did not know these two commands Beginupdate and Endupdate. .

  • Havenard ours greatly decreased the time in full charge dropped from 11 minutes to 2 minutes. Many thanks for your help and attention

  • @acs Maybe you can optimize even more using TStringBuilder instead of mounting the data directly on TMemo.Lines, but for that you will have to research a little like you use. I do not program in Delphi some 15 years ago.

  • Havenard thank you I will search yes and thank you for your tip This program so far has been all written in Lazarus I will see if it has to him if I will not have to wait a little. I have delphi7, but since the program is too big it would be a lot of work to download the code from scratch for it, because it has many components and many references between them and the variables.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.