Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-10

TStringGrid behaviour

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Birger Jansen

Hi all,

I have the following code that throws an error in FPC and runs fine in Delphi:

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  MyStringGrid: TStringGrid;
begin
  MyStringGrid := TStringGrid.Create(nil);
  try
    MyStringGrid.RowCount := 0;
    MyStringGrid.RowHeights[0] := 1;
  finally
    MyStringGrid.Free;
  end;
end;

Delphi checks if the grid has at least
In FPC there is no check on RowCount before the height is set, resulting in a List index(0) out of bounds exception. Although it is correct, it is annoying :-)

It can be fixed by adding something like this to the beginning of TCustomGrid.Setrowheights:

  if ARow <= FRows.Count then EXIT;

Shall I file a report for this?

Kind regards,
Birger Jansen

Reply by email

Thaddy
to Birger Jansen: I have the following code that throws an error in FPC and runs fine in Delphi: procedure…
Birger Jansen wrote 38 lines
Hi all, I have the following code that throws an error in FPC and runs fine in Delphi: procedure TForm1.BitBtn1Click(Sender: TObject); var MyStringGrid: TStringGrid; begin MyStringGrid := TStringGrid.Create(nil); try MyStringGrid.RowCount := 0; MyStringGrid.RowHeights[0] := 1; finally MyStringGrid.Free; end; end; Delphi checks if the grid has at least In FPC there is no check on RowCount before the height is set, resulting in a List index(0) out of bounds exception. Although it is correct, it is annoying :-) It can be fixed by adding something like this to the beginning of TCustomGrid.Setrowheights: if ARow<= FRows.Count then EXIT; Shall I file a report for this? Kind regards, Birger Jansen _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.864 / Virus Database: 271.1.1/3221 - Release Date: 10/26/10 20:34:00

First: It is not a good idea to create the stringgrid without a parent... or any visual control. Annoying :) and potentionally dangereous. Second: As you remarked, the behaviour is correct. Why being annoyed about making a programming mistake?

Reply by email

Birger Jansen
to Thaddy

Van: Thaddy

First: It is not a good idea to create the stringgrid without a parent... or any visual control. Annoying :) and potentionally dangereous.

True, dirty example code.

Second: As you remarked, the behaviour is correct. Why being annoyed about making a programming mistake?

I thought the Free Pascal project wanted to be compatible with Delphi where it is possible. I stumbled upon this issue while converting a Delphi project and thought it might be something to fix for the sake of compatibility.

@Graeme: sorry.

Kind regards,
Birger

Reply by email

Jesus Reyes
to Birger Jansen: I have the following code that throws an error in FPC and runs fine in Delphi: procedure…
Birger Jansen wrote 26 lines
De: Birger Jansen Asunto: [fpc-devel] TStringGrid behaviour A: Fecha: miércoles, 27 de octubre de 2010, 7:32 Hi all, I have the following code that throws an error in FPC and runs fine in Delphi:     MyStringGrid.RowCount := 0;     MyStringGrid.RowHeights[0] := 1; Delphi checks if the grid has at least In FPC there is no check on RowCount before the height is set, resulting in a List index(0) out of bounds exception. Although it is correct, it is annoying :-) It can be fixed by adding something like this to the beginning of TCustomGrid.Setrowheights:   if ARow <= FRows.Count then EXIT; Shall I file a report for this? Kind regards,   Birger Jansen

As somebody already noted, this belong to the Lazarus List.

Delphi and Lazarus grids have many similar features but not all, this is a case where they differ, and it's already reported here http://bugs.freepascal.org/view.php?id=17538 , see also related reports and feel free to add your comments there.

Jesús Reyes A.

Reply by email