Recent

Author Topic: Change cell value through objects  (Read 844 times)

pmesquita

  • Jr. Member
  • **
  • Posts: 53
Change cell value through objects
« on: November 18, 2021, 05:03:05 pm »
Folks...
How can I change the value of a cell through a function of an object contained in it?
What I have in mind so far is the attached unit...
I don't know if I'm on the right path... but that's what I have so far...

Change cell's value..
Code: Pascal  [Select][+][-]
  1. StringGrid1.Cell[3, 3].AsString:= TimeToStr(Now);
  2.  

Any tips or not how to do this...?

« Last Edit: November 18, 2021, 05:55:30 pm by pmesquita »

jamie

  • Hero Member
  • *****
  • Posts: 5129
Re: Change cell value through objects
« Reply #1 on: November 18, 2021, 05:37:33 pm »
Cells not cell
The only true wisdom is knowing you know nothing

pmesquita

  • Jr. Member
  • **
  • Posts: 53
Re: Change cell value through objects
« Reply #2 on: November 18, 2021, 05:40:49 pm »
It's actually Cells because my idea is to use another property where I can access all the properties of the TStrinGridCell object.
Because there was a simple example, but there will be other information that I will have to "inject" into the cell besides the text...

pmesquita

  • Jr. Member
  • **
  • Posts: 53
Re: Change cell value through objects
« Reply #3 on: November 18, 2021, 05:50:53 pm »
I found the solution...
And the ITStringGridInterface interface is not required...

Code: Pascal  [Select][+][-]
  1. procedure TStringGridCell.AddValue(ACol, ARow: Integer; AValue: String);
  2. begin
  3.   TStringGrid(Owner).Cells[ACol, ARow]:= AValue;
  4. end;  
  5.  

wp

  • Hero Member
  • *****
  • Posts: 9157
Re: Change cell value through objects
« Reply #4 on: November 18, 2021, 05:51:26 pm »
But why does TStringGridCell inherit from TStringGrid? Looks wrong...
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

pmesquita

  • Jr. Member
  • **
  • Posts: 53
Re: Change cell value through objects
« Reply #5 on: November 18, 2021, 05:55:19 pm »
Until then, it was the only way that, inside the TStringGridCell object, I could edit the value of the cell that I passed as a parameter in the Cell... property.

The other idea I have is: For each object of each cell I pass the canvas of the TStringGrid and when the value changes I use the canvas to draw...

But is there a better solution...? since i don't usually create and edit components so my knowledge in this area is zero..kkk

wp

  • Hero Member
  • *****
  • Posts: 9157
Re: Change cell value through objects
« Reply #6 on: November 18, 2021, 06:40:15 pm »
I see the problem how to create the TStringGridCell at an arbitray location in the grid. So far you only create it at col=3/row=3. Initially you do not know where the user will add information, and on the other hand it's an overkill to add a TStringGridCell everywhere.

 
 
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

pmesquita

  • Jr. Member
  • **
  • Posts: 53
Re: Change cell value through objects
« Reply #7 on: November 18, 2021, 06:54:20 pm »
Quote
I see the problem how to create the TStringGridCell at an arbitray location in the grid. So far you only create it at col=3/row=3.

In this case it was just an example because the grid has 8 rows/columns...
Because the grid will start RowCount = 1 so when the user calls the AddRows procedure it will automatically create objects for each cell..

Because the idea is the same as TStringGrid.Cells[Col, Row] but instead of accepting only String, it is to have more information in the referenced cell, for example: Code/Hint... only specific for that cell...

But why do I have to make a TypeCast of "Objects" to access the object in question, if I can create a property that already does this for me and that facilitates reading/writing the code

Basically the idea is this...

 

TinyPortal © 2005-2018