Recent

Author Topic: Select part of FieldValue in DBGrid  (Read 1113 times)

John Landmesser

  • New Member
  • *
  • Posts: 31
Select part of FieldValue in DBGrid
« on: February 21, 2024, 03:39:17 pm »
i am on Linux and i want to select per code only the hours of:

Dataset.FieldByName('Zeit_gelaufen').AsString:= '00:00:00';

Info:
Linux manjaro 6.1.71-1-MANJARO #1 SMP PREEMPT_DYNAMIC Fri Jan  5 17:36:36 UTC 2024 x86_64 GNU/Linux

Lazarus 3.99 (rev main_3_99-1363-g0d5579dc3f) FPC 3.2.2 x86_64-linux-gtk2

Lots of SendMessage i think?

Tipps are welcome !

cdbc

  • Hero Member
  • *****
  • Posts: 1933
    • http://www.cdbc.dk
Re: Select part of FieldValue in DBGrid
« Reply #1 on: February 21, 2024, 03:46:43 pm »
Hi
If you get a string value back e.g.:
Code: Pascal  [Select][+][-]
  1. S:= Dataset.FieldByName('Zeit_gelaufen').AsString;
of said format, I'd use:
Code: Pascal  [Select][+][-]
  1. hrStr:= S.Split([':'])[1];

Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

mig-31

  • Sr. Member
  • ****
  • Posts: 306
Re: Select part of FieldValue in DBGrid
« Reply #2 on: February 21, 2024, 03:49:03 pm »
Hi,
to parse a string you can use ExtractDelimited from StrUtil
Code: Pascal  [Select][+][-]
  1. ExtractDelimited(2, '00:00:00', [':']);
  2.  
« Last Edit: February 22, 2024, 02:50:11 pm by mig-31 »
Lazarus 2.2.6 - OpenSuse Leap 15.4, Mageia 8, CentOS 7

John Landmesser

  • New Member
  • *
  • Posts: 31
Re: Select part of FieldValue in DBGrid
« Reply #3 on: February 21, 2024, 03:55:05 pm »
Thanks to both of you that tried to answer my question!

But:

I don't want to extract something from Field.AsString but preselect the hours - part of the SelectedField!

cdbc

  • Hero Member
  • *****
  • Posts: 1933
    • http://www.cdbc.dk
Re: Select part of FieldValue in DBGrid
« Reply #4 on: February 21, 2024, 04:09:32 pm »
Hi
Then, I'm sorry, I haven't got the foggiest of what you're talking about  %)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Zvoni

  • Hero Member
  • *****
  • Posts: 2895
Re: Select part of FieldValue in DBGrid
« Reply #5 on: February 21, 2024, 04:14:10 pm »
At a guess (from the Subject-Title and answers here):
He wants to Display the hour-part already as "selected" in his DBGrid
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

John Landmesser

  • New Member
  • *
  • Posts: 31
Re: Select part of FieldValue in DBGrid
« Reply #6 on: February 21, 2024, 04:16:54 pm »
Think of a Field with EditMask hh:nn:ss. The user usually does not enter the hour part but minutes and seconds . So i want to preselct the minutes

Sorry i told you about hours above, that was wrong!

Zvoni

  • Hero Member
  • *****
  • Posts: 2895
Re: Select part of FieldValue in DBGrid
« Reply #7 on: February 21, 2024, 04:19:49 pm »
And how do you expect that to work in a DBGrid?
Say, your Grid shows 10 records, and for each record in that column it should preselect the minutes? So you would have 10 preselected partial "Strings" in 10 different cells?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

John Landmesser

  • New Member
  • *
  • Posts: 31
Re: Select part of FieldValue in DBGrid
« Reply #8 on: February 21, 2024, 04:23:19 pm »
I want to do that onNewRecord event:

procedure TForm1.ZQuery1NewRecord(DataSet: TDataSet); 

JWBokx

  • Newbie
  • Posts: 3
Re: Select part of FieldValue in DBGrid
« Reply #9 on: February 21, 2024, 04:33:06 pm »
depends on the used editor for the field.

THe Editor property is the currentcell editor.
But this is a wincontrol, so if a TEdit is used check the classname or classtype for e TEdit descendent.
In a TEdit the proprties to select a part is SelStart and SelLength.

Code: Pascal  [Select][+][-]
  1. var
  2.   start, len: integer;
  3.  
  4. begin
  5. start:=Pos(':',DBGrid.SelectedField.asstring,1);
  6. len:=Pos(':',DBGrid.SelectedField.asstring,2) - start;
  7.  
  8. (DBGrid.Editor as Tedit).SelStart:=start;
  9. (DBGrid.Editor as Tedit).SelLength:=len;
  10.  
  11. ...
  12.  
  13.  
  14.  

(Not tested just an idea!)

John Landmesser

  • New Member
  • *
  • Posts: 31
Re: Select part of FieldValue in DBGrid
« Reply #10 on: February 21, 2024, 04:37:07 pm »
Thank you , i will test that because i think that could be a solution :-)

John Landmesser

  • New Member
  • *
  • Posts: 31
Re: Select part of FieldValue in DBGrid
« Reply #11 on: February 21, 2024, 07:02:36 pm »
I think i try tomorrow  and hopefully learn how to do it:

See:
https://wiki.lazarus.freepascal.org/Grids_Reference_Page#procedure_InplaceEditor

If i have no success, i have to hit 0 twice to get to the minutes ... pure horror !


 

TinyPortal © 2005-2018