When trying to remove rows that have a required column being empty, I thought to use the following:
for i := AdvStringGrid1.TotalRowCount-1 downto 1 do
if Trim(AdvStringGrid1.Cells[2,i]) = '' then
MyRowList.Add(i);
if MyRowList.Count > 0 then
AdvStringGrid1.RemoveRowList(MyRowList);
This fails to compile, as the RemoveRowList says the MyRowList is the wrong type of TIntList.
What is the correct syntax to do this, please?
The correct creation of a class is:
MyRowList := TIntList.Create(-1,-1);
First error came back, too many parameters. When I type the () after the create, the hint says no parameters are expected.
Changing the create to
MyRowList := TIntList.Create;
removes that error, but then the statement:
AdvStringGrid1.RemoveRowList(MyRowList);
Errors with:
E2010 Incompatible types: 'AdvObj.TIntList' and 'AdvMemo.TIntList'
prefix TIntList class with its proper namespace: AdvObj
MyRowList: AdvObj.TIntList;
MyRowList := AdvObj.TIntList.Create(-1,-1);
OK, this compiles, but does not remove the rows with no data:
MyRowList : ADVObj.TIntList;
MyRowList := ADVObj.TintList.Create(-1,-1);
for i := AdvStringGrid1.TotalRowCount-1 downto 1 do
if Trim(AdvStringGrid1.Cells[2,i]) = '' then
MyRowList.Add(i);
if MyRowList.Count > 0 then
AdvStringGrid1.RemoveRowList(MyRowList);
MyRowList.Free;
OK, changing the for loop to be
for i := 1 to TotalRowCount-1 do
instead of the downto, now it works.
I assumed working backwards through the loop was the correct method to prevent removing the wrong rows as they repositioned.