DBEdit control lazarus / 16-Databases ---------------------------------------------------------------------- Mando · 2015-08-06 10:53 Hi, all: I updated lazarus to 1.4.2 and I have noticed the following behavior: I stood at DBEdit control. I'm at the end of content and press a key. Then the cursor is placed at the beginning of the text and then the character is written down . For instance: I have a record with the following value in a field DESCRIPTION Set the caret behind the N and write (without quotes) : "1". The text should be Description1 but it is 1Description because the caret is at the beginning of the text. I guess it's because the dataset is put in edit mode when the key is pressed. It happens with any database connector . ZEOS , SQLdb , TDbf ... Windows XP/7 Lazarus 1.4.2 svn 49524 - FPC 2.6.4 ZEOS 7.1.4-stable Does anyone have a solution? Regards... ---------------------------------------------------------------------- rvk · 2015-08-06 11:59 Not a solution but this seems to be fixed somewhere between Lazarus 1.5 r49541M FPC 3.1.1 i386-win32-win32/win64 and Lazarus 1.5 r49604 FPC 3.1.1 i386-win32-win32/win64 or FPC 31205 and FPC 31291 ---------------------------------------------------------------------- Mando · 2015-08-06 13:20 thanks, rvk: but, what can i do? Desinstall 1.4.2, and return to an older version? regards ---------------------------------------------------------------------- rvk · 2015-08-06 15:03 Quote from: Mando on August 06, 2015, 03:20:35 pmbut, what can i do? Desinstall 1.4.2, and return to an older version? I'm not sure who fixed this in the latest trunk. You could go back to 1.4.You could fix it by yourself and recompile 1.4 (but you need to know what was done to fix it)You could, temporarily, set the dataset to "edit" yourself in the keydown event of your TDBEdit and restore the cursor position. For method 3 you could also redeclare TDBEdit above your form and change the KeyDown. In that case it will be automatically done for all your TDBEdit's on your form. This above the form declaration: Code: [Select]type   TDBEdit = class(DbCtrls.TDBEdit)   protected     procedure KeyDown(var Key: word; Shift: TShiftState); override;   end; type   { TForm1 }   TForm1 = class(TForm) .... And this in the implementation: Code: [Select]procedure TDBEdit.KeyDown(var Key: word; Shift: TShiftState); var   Ps: integer; begin   if not(DataSource.DataSet.State in [dsInsert, dsEdit]) then   begin     Ps := SelStart;     DataSource.DataSet.Edit;     SelStart := Ps;   end;   inherited; end; (Ugly and untested for any other special circumstances but might work for you until this is fixed in a stable release) ---------------------------------------------------------------------- Mando · 2015-08-06 17:07 rvk, thank you again. I dediced to reinstall version 1.4.0 and it is working again. regards. ---------------------------------------------------------------------- donaldklopper · 2015-09-01 12:34 +1 for rvk Thank you ... your tip was spot on for me. I am repanelling a frame into another form, and the code doesn't work if I place it on the parent form's source code, but it works for each frame... slightly more frustrating, but still works really well. Also, my first post on the forum. I'm REALLY impressed by where Lazarus is at the moment. Tried it YEARS ago for the last time before now. Little bugs like these will crop up. ---------------------------------------------------------------------- rvk · 2015-09-01 13:06 Quote from: donaldklopper on September 01, 2015, 02:34:56 pmI am repanelling a frame into another form, and the code doesn't work if I place it on the parent form's source code, but it works for each frame... slightly more frustrating, but still works really well. You could also create a sort of helper-unit. You just need to make sure the unit is at the end of the uses clause in the interface section. Because it is in the end, your source will always take the last defined instance of TDBEdit (which is the one declared in this unit). That way you don't have to declare it in all your different frames. fix_tdbedit_temp.pas Code: [Select]unit fix_tdbedit_temp; {$mode objfpc}{$H+} interface uses Classes, DbCtrls, DB; type   TDBEdit = class(DbCtrls.TDBEdit)   protected     procedure KeyDown(var Key: word; Shift: TShiftState); override;   end; implementation procedure TDBEdit.KeyDown(var Key: word; Shift: TShiftState); var   Ps: integer; begin   if not(DataSource.DataSet.State in [dsInsert, dsEdit]) then   begin     Ps := SelStart;     DataSource.DataSet.Edit;     SelStart := Ps;   end;   inherited; end; end. Use like this in your frame-source (or other unit-source where you need this): Code: [Select]interface uses   Classes, SysUtils, sqlite3conn, sqldb, DB, FileUtil, Forms, Controls,   Graphics, Dialogs, StdCtrls, DBGrids, ComCtrls, DbCtrls, fix_tdbedit_temp;   //                                                       ^^^^^^^^^^^^^^^^   //                                                       this at the end When you upgrade to a newer version you could delete the fix_tdbedit_temp references ---------------------------------------------------------------------- donaldklopper · 2015-09-02 07:44 +10 rvk Thanks again. Great idea! Thanks for responding, being friendly and helpful and comprehensive. That's very rare.