Recent

Author Topic: [SOLVED] TStringgrid at runtime *Thanks*  (Read 2525 times)

guywest

  • New member
  • *
  • Posts: 8
[SOLVED] TStringgrid at runtime *Thanks*
« on: March 15, 2020, 02:20:12 pm »
Good day,

Yesterday I spent almost a whole afternoon to get TStringgrid to do what I want (which works very easy and well in Delphi but not in Lazarus 2.0.2.

I want to create a grid on a form at runtime.

Several code examples found, nothing works.

Example:
Code: Pascal  [Select][+][-]
  1. MyGrid := TStringGrid.Create(Self);
  2.   MyGrid.Parent := Self;
  3.   MyGrid.Visible := true;
  4.   MyGrid.left := 20;
  5.   MyGrid.top := 20;
  6.   MyGrid.rowcount := 5;
  7.   MyGrid.colcount := 5;
  8.   MyGrid.width := 100;
  9.   MyGrid.height := 100;
  10.   MyGrid.Enabled := true;
  11.   MyGrid.cells[1, 1] := 'hi';
  12.  

NOTHING visible on the form. Changing parent to form name or create on form name in stead of Self does not change anything: always empty form.

Tried also with an empty grid at design time and then changing rows and columns (yes: with the columns.add, not by only changing colcount) at runtime but changes are not visible: the design time version is always displayed. No refresh, repaint, invalidate, ... helps.

Why does this not work?

As the stringgrid works very easily under Delphi but is a REAL pain in the ass in Lazarus (a lot of stupid error messages in other applications also), I really think the Stringgrid component of Lazarus really sucks. I'm a wrong?

Is there an important item that I don't know to make the Stringgrid of Lazarus work as easily as the Stringgrid of Delphi?

Thanks!
« Last Edit: March 21, 2020, 05:41:45 pm by guywest »

Bart

  • Hero Member
  • *****
  • Posts: 5573
    • Bart en Mariska's Webstek
Re: TStringgrid at runtime
« Reply #1 on: March 15, 2020, 02:24:15 pm »
Self is the form you try to place it on?

Bart

jamie

  • Hero Member
  • *****
  • Posts: 6960
Re: TStringgrid at runtime
« Reply #2 on: March 15, 2020, 02:50:00 pm »
This works for me....
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. Var
  3.   G:TstringGrid;
  4. begin
  5.   G :=TStringGrid.Create(Self);
  6.   G.Parent := Self;
  7.   With G do
  8.    Begin
  9.      Bounds(0,0,200,300);
  10.      Enabled := True;
  11.      Cells[1,1] := 'Hi';
  12.    end;
  13. end;                          
  14.  
  15.  
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 12867
Re: TStringgrid at runtime
« Reply #3 on: March 15, 2020, 03:24:06 pm »
TStringgrid to do what I want (which works very easy and well in Delphi but not in Lazarus 2.0.2. [...] Several code examples found, nothing works. [...] NOTHING visible on the form.
Are you sure that your code is really called? The code itself is correct and works if called for example from a button OnClick event handler.
In fact, the Lazarus StringGrid is much superior to that of Delphi, if offers many features for which the Delphi grid requires a third-party grid.

RAW

  • Hero Member
  • *****
  • Posts: 870
Re: TStringgrid at runtime
« Reply #4 on: March 15, 2020, 05:30:44 pm »
Quote
This works for me....
ME TOO ...  ;D

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: TStringgrid at runtime
« Reply #5 on: March 15, 2020, 07:55:26 pm »
Hi!

Yes - works with no problem.

But RAW: nobody talked about ClLIME! Outsch!

Winni

RAW

  • Hero Member
  • *****
  • Posts: 870
Re: TStringgrid at runtime
« Reply #6 on: March 15, 2020, 09:10:00 pm »
I fell into the clLime-Potion when I was a little boy ...  :D

guywest

  • New member
  • *
  • Posts: 8
Re: TStringgrid at runtime
« Reply #7 on: March 21, 2020, 05:37:16 pm »
Thanks to you all.

The code of Jamie works. VERY strange.

guywest

  • New member
  • *
  • Posts: 8
Re: TStringgrid at runtime
« Reply #8 on: March 21, 2020, 05:38:47 pm »
TStringgrid to do what I want (which works very easy and well in Delphi but not in Lazarus 2.0.2. [...] Several code examples found, nothing works. [...] NOTHING visible on the form.
Are you sure that your code is really called? The code itself is correct and works if called for example from a button OnClick event handler.
In fact, the Lazarus StringGrid is much superior to that of Delphi, if offers many features for which the Delphi grid requires a third-party grid.

Is possible but with Delphi Grid I sometimes had an error, with the Lazarus Grid it RAINS errors.

jamie

  • Hero Member
  • *****
  • Posts: 6960
Re: [SOLVED] TStringgrid at runtime *Thanks*
« Reply #9 on: March 21, 2020, 08:08:12 pm »
I think Bart was on the correct path, where does "SELF" come from?
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018