TFloatField not accept comma as decimal separator lazarus / 13-General ---------------------------------------------------------------------- Silvio Clécio · 2010-03-13 18:28 Hello everyone, The Zeos uses TFloatField type in the numeric fields, and this type does not accepted comma (my decimal separator) in DBEdit, but in DBGrid accepted. I checked the ValidChars, but on Lazarus this property is read-only, not allowing me to edit it at runtime. I send a demo in attached to reproduce the error. How do I solve this? ---------------------------------------------------------------------- Silvio Clécio · 2010-03-13 20:23 I discovered that the error it's in DBEdit, but it seems that is the class TFloatField that is not passing the list of valid characters. Test (line 166 of the dbedit.inc): Code: [Select]procedure TDBEdit.KeyPress(var Key: char);   function CanAcceptKey: boolean;   begin     Result := // Field.IsValidChar(Key) and <<-- Here!       (Field.DataType<>ftAutoInc);   end; var   SavedKey: Char; begin How do I solve this in IsValidChar? ---------------------------------------------------------------------- Silvio Clécio · 2010-03-13 22:31 I solved, the 'powerfull' solution: Code: [Select]procedure TDBEdit.KeyPress(var Key: char);   function CanAcceptKey: boolean;   begin     case Field.DataType of       ftFloat..ftBCD: Result := Key in ['0'..'9', '+', '-', DecimalSeparator];     else       Result := Field.IsValidChar(Key);     end;     Result := Result and (Field.DataType <> ftAutoInc);   end; var   SavedKey: Char; begin Thanks! ---------------------------------------------------------------------- bobo · 2010-03-13 23:57 Good job! ---------------------------------------------------------------------- Lacak2 · 2010-03-24 05:43 Hi Silvio, at a first step please check if DecimalSeparator is really not included in ValidChars: Somewhere (may be at onClick Event) perform: if DecimalSeparator in DBEdit1.Field.ValidChars then  showmessage(DecimalSeparator+' is included in ValidChars) else  showmessage(DecimalSeparator+' is NOT included in ValidChars); I expect, that 'NOT included' will be reported. Then check if FieldClass is really TFloatField ... may be, that Zeos overrides basic field classes ? ---------------------------------------------------------------------- Silvio Clécio · 2010-03-25 01:19 I did this, please see the result: http://imagebin.org/90244 Source code in attached. ----------------------------------- Lazarus-0.9.29 - rv23335 FPC-2.2.4-3 Zeos 7 - Actual copy from SVN Ubuntu-9.10 ----------------------------------- ---------------------------------------------------------------------- Lacak2 · 2010-03-25 12:21 Because I have only Windows OSes (not *nix) I can not test and debug directly. So as a next step test please this code in onClick Event: procedure TForm1.DBEdit1Click(Sender: TObject); var i:integer; c: char; s:string; begin     s:='';     for i:=32 to 255 do //for c in DBEdit1.Field.ValidChars do       if chr(i) in DBEdit1.Field.ValidChars then          s:=s+ansitoutf8(chr(i));     showmessage(DBEdit1.Field.ClassName + s); end; In my case is showed: "TFloatField+,-0123456789Ee" (which is correct, because "," is included) --- But IMHO the root of problem is in this: ZQuery1anyvalue: TFloatField is created BEFORE FormCreate event occurs, so TFloatField.FValidChars is already set (before you set DecimalSeparator:=','). So global varible DecimalSeparator is "incorrectly" initialised in SysUtils (I guess, that is initialised to "." not to ",") Try move "DecimalSeparator := ',';" into "project1.lpr" before "Application.CreateForm(TForm1, Form1); " ---------------------------------------------------------------------- Silvio Clécio · 2010-03-25 22:07 You're right , please see: http://imagebin.org/90390 Also worked with: initialization   {$I Unit1.lrs}   ShortDateFormat := 'dd/MM/yyyy';   CurrencyString := 'R$';   CurrencyFormat := 0;   NegCurrFormat := 14;   ThousandSeparator := '.';   DecimalSeparator := ',';   CurrencyDecimals := 2;   DateSeparator := '/';   TimeSeparator := ':';   TimeAMString := 'AM';   TimePMString := 'PM';   ShortTimeFormat := 'hh:mm:ss'; So, where's the error (Lazarus/Zeos)? :/ I thank you in advance, for here was working perfectly now. ---------------------------------------------------------------------- Lacak2 · 2010-03-26 05:48 Quote from: silvioprog on March 25, 2010, 11:07:45 pmSo, where's the error (Lazarus/Zeos)? :/ Error is not in Lazarus also not in Zeos, but in FPC (FreePascal). In your environment is global variable DecimalSeparator (which is defined in sysinth.inc) not inicialized properly (or you have not setup correctly locale in your OS). As I am not export for Linux, I am not able comment more. Can somebody else comment on this? But it seems to me like bug, so you should modify your original bug report: http://bugs.freepascal.org/view.php?id=15988 (Bug is definitely not in TFloatField, also not in TDBEdit) ---------------------------------------------------------------------- jesusr · 2010-03-26 17:04 Under linux, global locale variables are not initialized, to initialize internationalization settings unit clocale need to be added to uses clause. ---------------------------------------------------------------------- Silvio Clécio · 2010-03-27 22:43 So it's not a mistake (Just declare clocale)? ---------------------------------------------------------------------- Lacak2 · 2010-03-29 05:11 Quote from: silvioprog on March 27, 2010, 11:43:12 pmSo it's not a mistake (Just declare clocale)? It seems so. Try add in your project into USES clause "clocale" and remove assigments like DecimalSeparato:=... If it will work, then please report it in your bug report and close it. ---------------------------------------------------------------------- Silvio Clécio · 2010-03-29 05:26 LacaK2 and jesusr and all, thanks for everything, now everything is working perfectly I have reported in the bugtracker, I asked them to close the report Thxs