Recent

Author Topic: (SOLVED) Get value of a field of a highlighted record  (Read 454 times)

Bert_Plitt

  • New Member
  • *
  • Posts: 31
(SOLVED) Get value of a field of a highlighted record
« on: November 13, 2019, 06:56:46 pm »
I'm a SQLite3 newbee working on a test project (attached).  I've got most things working as desired, but can't figure out how to do the following.  If I highlight one of the records (in the grid) and click btnSelect, I want the value of Field 3 to be copied to the static label.  After the copying is done, ALL the records in the table must remain visible in the grid.  Can anyone suggest code (for the OnClick event) that will assign the value of the highlighted record field into the str variable?

Windows 10, Laz 2.0.6, FPC 3.0.4
« Last Edit: November 15, 2019, 03:09:24 am by Bert_Plitt »
Windows 10, Lazarus 2.0.6, FPC 3.0.4

fmc

  • New Member
  • *
  • Posts: 36
Re: Get value of a field of a highlighted record
« Reply #1 on: November 13, 2019, 07:17:12 pm »
Not sure if this is what you're looking for.

Code: Pascal  [Select]
  1. var
  2.     Str: String;
  3. begin
  4.     // Assign value of highlighted record, "Field 3" to Str
  5.     Str:=Query1.Fields[2].AsString; // FIELD 3
  6.  
  7.     txtItem3.Caption:=Str;
  8.     // All Records must remain visible in "NAME" grid.
  9. end;
« Last Edit: November 14, 2019, 03:56:34 am by fmc »
Win X Pro / Lazarus 2.0.6 / FPC 3.0.4

Bert_Plitt

  • New Member
  • *
  • Posts: 31
Re: Get value of a field of a highlighted record
« Reply #2 on: November 13, 2019, 10:38:23 pm »
fmc -- YES!  That's exactly what I wanted.  Works like a charm.  I was off in the weeds trying to use SELECT and/or FieldByName.  Thanks.
Windows 10, Lazarus 2.0.6, FPC 3.0.4

fmc

  • New Member
  • *
  • Posts: 36
Re: Get value of a field of a highlighted record
« Reply #3 on: November 14, 2019, 03:26:04 am »
You can use FieldByName and get the same result:

Code: Pascal  [Select]
  1. var
  2.     Str: String;
  3. begin
  4.     // Assign value of highlighted record, "Field 3" to Str
  5.     Str:=Query1.FieldByName('Field3').AsString;
  6.  
  7.     txtItem3.Caption:=Str;
  8.     // All Records must remain visible in "NAME" grid.
  9. end;
« Last Edit: November 14, 2019, 03:56:44 am by fmc »
Win X Pro / Lazarus 2.0.6 / FPC 3.0.4

Bert_Plitt

  • New Member
  • *
  • Posts: 31
Re: Get value of a field of a highlighted record
« Reply #4 on: November 15, 2019, 02:19:51 am »
fmc -- Yes, that's how I have it in my actual project.  I tried FieldByName when I started, but for some unknown reason Str always contained an empty string.  Evidently I must have changed something in my code because now FieldByName is working.  Thanks for your help.

BTW - Do you know how to mark messages as "SOLVED"?
Windows 10, Lazarus 2.0.6, FPC 3.0.4

GAN

  • Full Member
  • ***
  • Posts: 232
Re: Get value of a field of a highlighted record
« Reply #5 on: November 15, 2019, 02:32:43 am »
Bert_Plitt to mark solved you have to edit your first message.
Use Modify button to do it.
Lazarus 1.8.4 FPC 3.0.4 Linux Mint Mate 17.2 x86_64 GTK-2
Zeos 7.1.3 - Sqlite 3.8.2

Foro Lazarus en español http://forum.lazarus.freepascal.org/index.php/board,73.0.html