Recent

Author Topic: DBEdit control  (Read 5382 times)

Mando

  • Full Member
  • ***
  • Posts: 181
DBEdit control
« on: August 06, 2015, 12:53:04 pm »
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

  • Hero Member
  • *****
  • Posts: 6171
Re: DBEdit control
« Reply #1 on: August 06, 2015, 01:59:14 pm »
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

  • Full Member
  • ***
  • Posts: 181
Re: DBEdit control
« Reply #2 on: August 06, 2015, 03:20:35 pm »
thanks, rvk:

but, what can i do?
Desinstall 1.4.2, and return to an older version?



regards

rvk

  • Hero Member
  • *****
  • Posts: 6171
Re: DBEdit control
« Reply #3 on: August 06, 2015, 05:03:53 pm »
but, 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

  • Full Member
  • ***
  • Posts: 181
Re: DBEdit control
« Reply #4 on: August 06, 2015, 07:07:50 pm »
rvk, thank you again.

I dediced to reinstall version 1.4.0 and it is working again.



regards.

donaldklopper

  • Newbie
  • Posts: 5
Re: DBEdit control
« Reply #5 on: September 01, 2015, 02:34:56 pm »
+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

  • Hero Member
  • *****
  • Posts: 6171
Re: DBEdit control
« Reply #6 on: September 01, 2015, 03:06:06 pm »
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.
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

  • Newbie
  • Posts: 5
Re: DBEdit control
« Reply #7 on: September 02, 2015, 09:44:54 am »
+10 rvk

Thanks again. Great idea! Thanks for responding, being friendly and helpful and comprehensive. That's very rare.

 

TinyPortal © 2005-2018