Search the Community
Showing results for tags 'if statements'.
Found 1 result
Hey guys, so for this program I'm writing I want to check a string grid for empty rows/rows with just spaces in them and then subsequently deleting them to clean the grids up a bit. I made a procedure that reads the fields from a specific table in a DB and into a corresponding string grid. While 13 of the 14 grids I have, read the records like they're supposed to from the DB, one single table doesn't read correctly, it reads the same amount of records again as empty rows when displayed on the grid. For example, let's say I have 3 records in the table in the DB and I read it into the grid, the records display properly but then they add 3 more rows with just spaces in them. My code for this so far: procedure TfrmPuntehou.IncreaseRowCount(grid: TStringGrid); begin //increases rows in grid grid.RowCount:= grid.RowCount+1; end; procedure TfrmPuntehou.WriteToList(tbl: TADOTable;grid:TStringGrid); var Row: Integer; i: Integer; begin tbl.Active:= True; Row := 1; // Populate cells Tbl.First; while not (Tbl.Eof) do begin grid.Cells[0,Row]:= IntToStr(Row); grid.Cells[1,Row]:= tbl.fields.AsString; grid.Cells[2,Row]:= tbl.fields.AsString; grid.Cells[3,Row]:= tbl.fields.AsString; Inc(Row); IncreaseRowCount(grid); Tbl.Next; end; tbl.Active:=false; //what I'm planning to do to alleviate this but I'm not sure to use in the conditions of the if // because if I say grid.Rows[i] = ''/grid.Rows[i] = ' ' then I get an error // for i := 1 to grid.RowCount - 1 do // begin // if () OR () then // begin // grid.Rows[i].Delete; // end; // end; end; Illustration of what I'm talking about: What is supposed to happen: What's happening (the records are inserted correctly, but there are unnecessary rows here for only 3 records. When exported to a CSV the empty rows are filled with spaces"): Thanks in advance for any help on this! Kind Regards PrimeMinister