Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-08-2004, 06:17 AM
CynthiaD CynthiaD is offline
Junior Member
 
Join Date: Nov 2004
Posts: 2
Default Problem with DBGrid and floating point values

Hi,
Im having a difficulties trying to catch the exception that raises when a
'-' (minus sign) is written in a dbgrid, in a column whose Field property is
a TFloatField, do you know if there is an event or method to prevent the
exception from raising? Ive tried with OnValidate, OnColExit, OnSetText
with no luck. The exception is : '-' is not a valid floating point value for field 'NUMERO'.

Cynthia
Reply With Quote
  #2  
Old 11-08-2004, 07:05 AM
mshkolnik mshkolnik is offline
Senior Member
 
Join Date: Jul 2001
Posts: 4,195
Default RE: Problem with DBGrid and floating point values

Just validate the value in OnValidate event.
This event executed before post and there you may check a value and raise an error if value is incorrect (or change a value to another)

With best regards, Mike Shkolnik
http://www.scalabium.com
Reply With Quote
  #3  
Old 11-08-2004, 10:19 AM
rsawoseyin rsawoseyin is offline
Senior Member
 
Join Date: Nov 2001
Posts: 515
Default RE: Problem with DBGrid and floating point values

Is the '-' sign just on its own or does it precede a numeric value? '-2.56' is a valid floating-point value but '-' is not. And, why would one want to write '-' as a float value?

Raph Awoseyin
Port Harcourt, Nigeria
Reply With Quote
  #4  
Old 11-08-2004, 11:06 PM
digitiger digitiger is offline
Senior Member
 
Join Date: Jan 2001
Posts: 716
Default RE: Problem with DBGrid and floating point values

if you dont want any key to be passed to the focused control then you can easily trap it by using its keyPress event and in your case you can use the following procedure

procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if ord(key) = 45 then
begin
showmessage('you have pressed "-" minus key ');
key := #0; // this will nullify the pressed key
end;

end;


hope it helps and if it does then do accept the answere
Reply With Quote
  #5  
Old 11-09-2004, 04:22 AM
CynthiaD CynthiaD is offline
Junior Member
 
Join Date: Nov 2004
Posts: 2
Default RE: Problem with DBGrid and floating point values

Actually I want to accept the minus sign, for example the user could type -2.3, the error raises when i type just the minus sign and go down or click another column : '-' is not a valid floating point value

thanks
Cynthia
Reply With Quote
  #6  
Old 11-09-2004, 05:47 AM
pollo pollo is offline
Senior Member
 
Join Date: Jun 2002
Posts: 342
Default RE: Problem with DBGrid and floating point values

Hi!
This is what you should do:
On the OnSetText event of the TFloatField, validate and set the value of the field if it's correct.

Code:
procedure TForm1.Table1NumeroSetText(Sender: TField; Const Text: string);
begin
     if Text = '-' Then
     begin
          Sender.AsString := '';
          ShowMessage('Enter a valid float number!');
     end
     else Sender.AsString := Text;
end;
Hope it helps!

Pollo!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:31 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.