Recent

Author Topic: Problem TDBGrid input -+ and number in ftInteger  (Read 465 times)

benohb

  • Full Member
  • ***
  • Posts: 213
Problem TDBGrid input -+ and number in ftInteger
« on: November 25, 2020, 04:32:03 pm »

I have a database TBufDataset linked to  TDBGrid
In database I have  a Tfield as ftInteger
Everything here is normal and works when I type numbers
But in the edit mode of TDBGrid You can write like this format (11+26-57) and this his is considered as String !!
because you can write plus and minus
This showing raised exception

Is there a way to restrict writing in  TDBGrid ?
« Last Edit: November 25, 2020, 04:33:58 pm by benohb »

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Problem TDBGrid input -+ and number in ftInteger
« Reply #1 on: November 25, 2020, 05:06:42 pm »
You can code in the event TdbGrid.OnKeyPress: if you detect that the typed char (passed as variable parameter) is '+', then you can replace it with nothing (i.e. Chr(0)), e.g.:

Code: Pascal  [Select][+][-]
  1. if Key='+' then
  2.     Key:= Chr(0);
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

benohb

  • Full Member
  • ***
  • Posts: 213
Re: Problem TDBGrid input -+ and number in ftInteger
« Reply #2 on: November 25, 2020, 05:36:18 pm »

devEric69 … Thank you
I found another way
Code: Pascal  [Select][+][-]
  1. TdbGrid.FieldByName('int').OnSetText:=@TFieldSetTextEvent
  2.  
The procedure can check entries before placing them in the database
But your way I will use it ... :)

 

TinyPortal © 2005-2018