Recent

Author Topic: Is there a way to take the Text of an specific cell from a TString?  (Read 2285 times)

AfootDesert41

  • New Member
  • *
  • Posts: 15
How do I take the text of an specific cell on a TStringGrid to store it in a variable?

jamie

  • Hero Member
  • *****
  • Posts: 6995
Re: Is there a way to take the Text of an specific cell from a TString?
« Reply #1 on: January 01, 2019, 01:02:03 am »
Cells [ x,y ]

MyString := Cells [ Column, Row ];

Note:

 Fixed cells are part of the indexing..

Oh Wait, you want to take that from a Tstring... Hmmm.
I think that is comma delimited but I would need to check that..

« Last Edit: January 01, 2019, 01:03:39 am by jamie »
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Is there a way to take the Text of an specific cell from a TString?
« Reply #2 on: January 01, 2019, 01:02:37 am »
The same way you set them, but contrarywise:
Code: Pascal  [Select][+][-]
  1. MyString := MyGrid.Cells[Column, Row];

ETA: Well, Jamie beat me to it  :P

BTW, Happy new year! :D
« Last Edit: January 01, 2019, 01:05:33 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6995
Re: Is there a way to take the Text of an specific cell from a TString?
« Reply #3 on: January 01, 2019, 01:05:53 am »
ah that's it, Rows returns a TstringList so you could just index them as lines.


MyStringList := Grid1.Rows;

MyStringList.Strings[?] = a string of a cell.
« Last Edit: January 01, 2019, 01:07:43 am by jamie »
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Is there a way to take the Text of an specific cell from a TString?
« Reply #4 on: January 01, 2019, 01:12:43 am »
Huh? shouldn't it be:
Code: Pascal  [Select][+][-]
  1. RowStrings := Grid1.Rows[Row];
  2. MyString := RowStrings[Column];
?

But knowing the (row,column) coordinates, I would use Grid.Cells[] directy; more intuitive.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6995
Re: Is there a way to take the Text of an specific cell from a TString?
« Reply #5 on: January 01, 2019, 01:26:06 am »
Yup it should be  >:(

Oh Well.. It wouldn't compile that way so they would figure it out! :D
The only true wisdom is knowing you know nothing

Handoko

  • Hero Member
  • *****
  • Posts: 5458
  • My goal: build my own game engine using Lazarus
Re: Is there a way to take the Text of an specific cell from a TString?
« Reply #6 on: January 01, 2019, 08:42:41 am »
@AfootDesert41

Here has a simple demo showing how to load data from TDbf and show it to TStringGrid, change the cells' color and doing searching by reading and comparing the cell content with a search keyword provided by user:

https://forum.lazarus.freepascal.org/index.php/topic,37181.msg249361.html#msg249361

AfootDesert41

  • New Member
  • *
  • Posts: 15
Re: Is there a way to take the Text of an specific cell from a TString?
« Reply #7 on: January 01, 2019, 09:47:06 am »
Thank you all for your replies!

 

TinyPortal © 2005-2018