View Issue Details

IDProjectCategoryView StatusLast Update
0001625JEDI VCL00 JVCL Componentspublic2004-04-22 23:34
ReporterhamiltonAssigned Touser72 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0001625: TJvDBSpinEdit does not handle null fields
DescriptionNull field values produce a runtime error.
Error still exists in JVCL3-Latest.zip from 12-Apr-2004.
Additional InformationThanks to Peter3 for his recent work on this component :) It is almost complete now.
TagsNo tags attached.

Activities

user72

2004-04-12 08:50

  ~0003815

What should be shown when the value is NULL, 0 or nothing? If nothing, what should happen when the user clicks the up arrow, 0 or 1? Should it be possible to save a NULL value (i.e remove the previous value)?

hamilton

2004-04-12 14:33

reporter   ~0003821

* IHMO I think it would be safest to display nothing when the field is null. Displaying a value other than that in the dataset means misrepresenting the database or enforcing an edit (both of which are bad ideas). Empty datasets must never have null values 'editted'.
* I think UpClick from null should be 1.
* Null values may be allowed by the business rules for the dataset. You could add bAllowNull as a property of the control, then the programmer can link the business rules to the control. NB blocking null is a bit tricky anyway because you don't want to interfere with editting - ie backspacing from '1' should not raise an error message so you have to add events for OnExit (which i've always found to be tricky because of the order in which Delphi executes events when focus changes between controls).

user72

2004-04-14 03:50

  ~0003830

Please try the attached file and let me know the results. I've added a new AllowNull property to control the behavior.

hamilton

2004-04-15 10:35

reporter   ~0003880

Almost there!

The remaining problem is that displaying an empty dataset with an integer field in a TJvDBSpinEdit puts the dataset in insert mode.

How to replicate
* Query an empty table with 1 string and 1 integer field
* Add a button to show the dataset state
* Add a DBEdit to display the string field
* Run the app and notice that the state is always dsBrowse
* Add a TJvDBSpinEdit to display the integer field
* Run the app and notice that the state is dsInsert

Suggestion
* Currently UpClick from Null goes to 1. Personally, I would like to see DownClick go to 0 rather than -1. Zero sometimes has a significant importance.

Fixed
* OnScroll no longer puts the dataset in edit mode when the value displayed in a TJvDBSpinEdit changes.
* OnClick when there is null field value no longer produces a runtime error.
* UpClick/DownClick from null no longer produces error

user72

2004-04-15 13:06

  ~0003888

>The remaining problem is that displaying an empty dataset with
>an integer field in a TJvDBSpinEdit puts the dataset in insert mode.
Hm, I can't reproduce this but I am using a ClientDataset. Could that be important?

> * Currently UpClick from Null goes to 1.
Is this good or bad?

hamilton

2004-04-15 17:53

reporter   ~0003896

> Hm, I can't reproduce this but I am using a ClientDataset.
> Could that be important?
I have been primarily using a ClientDataSet myself, though I did try TADOQuery as well and see the same behaviour. I will run some more tests to help isolate the error in a few hours.

> * Currently UpClick from Null goes to 1.
> Is this good or bad?
I like UpClick to 1. I was suggesting DownClick should be to 0 rather than -1.

hamilton

2004-04-15 22:09

reporter   ~0003899

I just realized that I didn't include some important information in my previous bugnote, sorry Peter.

Under the heading 'How to Replicate' I should have included:
* Add a DBGrid to display the dataset

Having the DBGrid 'inserts' a new record when there is an empty dataset. Delphi DB aware controls don't put the dataset in insert mode to handle this but the TJvDBSpinEdit does.

The consequence for me is that my DB forms prompt to save changes when the dataset is empty.

Many apologies for this omission. I hope I haven't wasted too much of your time.

user72

2004-04-16 02:59

  ~0003904

No waste, but using a DBGrid I can reproduce the problem and think I have found a solution as well. Try the attached file

2004-04-16 02:59

 

JvDBSpinEdit.zip (2,447 bytes)

hamilton

2004-04-20 12:58

reporter   ~0003969

Hi Peter,

The latest file fixes the bugs to date but introduces 2 new problems:

* Typing a number in the edit does not put the dataset in edit mode.
  - The buttons correctly put the dataset in edit mode

* Sometimes you are prevented from typing numbers in the edit altogether.
  This behaviour can be demonstrated as follows:
   1. Edit the value in the SpinEdit (by typing numbers or clicking the buttons)
   2. Call ClientDataSet.UndoLastChange.
  Voila, the edit no longer accepts numbers - though the buttons still work and after clicking the buttons the edit works again.

user72

2004-04-22 00:30

  ~0003988

This change should fix both problems:

procedure TJvDBSpinEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
  inherited KeyDown(Key, Shift);
  if (Key = VK_DELETE) or (Key = VK_BACK) or ((Key = VK_INSERT) and (ssShift in Shift))
    or IsValidChar(Char(Key)) then
    FFieldDataLink.Edit;
end;

hamilton

2004-04-22 06:53

reporter   ~0004003

The last snippet of code fixed both bugs. Great work Peter!

I discovered 1 additional bug that I have fixed. After making the small correction outlined below I was unable to fault the control. :D

In GetValue and SetValue the current code:
  if (Text = '') and (Result/NewValue = 0.0) then FIsNull := true;
should be replaced with:
  FIsNull := (Text = '') and (Result/NewValue = 0.0);

This change was necessary because deleting text in the JvDBSpinEdit then undoing the change did not update the text displayed.

Steps to reproduce:
1. Select the data displayed in the edit portion of the JvDBSpinEdit
2. Press delete
3. Call ClientDataSet.UndoLastChange
-> The edit still displays no value
=> Scrolling to another record then back again shows the original value displayed.

hamilton

2004-04-22 06:58

reporter   ~0004005

PS The latest version of JvDBSpinEdit also fixes the minor bug described in bugnote 0001626 ie that 'TJvDBSpinEdit OnClick event puts the dataset in edit mode'. Bugnote 0001626 still has a status of 'feedback' (though I did respond).

user72

2004-04-22 23:34

  ~0004019

Updated in CVS.

Thanks for your help, perserverance and detailed reports.

Issue History

Date Modified Username Field Change
2004-04-12 08:21 hamilton New Issue
2004-04-12 08:50 user72 Note Added: 0003815
2004-04-12 14:33 hamilton Note Added: 0003821
2004-04-14 03:49 user72 Status new => assigned
2004-04-14 03:49 user72 Assigned To => user72
2004-04-14 03:49 user72 File Added: JvDBSpinEdit.zip
2004-04-14 03:50 user72 Note Added: 0003830
2004-04-15 10:35 hamilton Note Added: 0003880
2004-04-15 13:06 user72 Note Added: 0003888
2004-04-15 17:52 anonymous Note Added: 0003895
2004-04-15 17:52 anonymous Note Deleted: 0003895
2004-04-15 17:53 hamilton Note Added: 0003896
2004-04-15 22:08 anonymous Note Added: 0003898
2004-04-15 22:08 anonymous Note Deleted: 0003898
2004-04-15 22:09 hamilton Note Added: 0003899
2004-04-16 02:58 user72 File Deleted: JvDBSpinEdit.zip
2004-04-16 02:59 user72 Note Added: 0003904
2004-04-16 02:59 user72 File Added: JvDBSpinEdit.zip
2004-04-20 12:58 hamilton Note Added: 0003969
2004-04-22 00:30 user72 Note Added: 0003988
2004-04-22 00:30 user72 Status assigned => feedback
2004-04-22 06:53 hamilton Note Added: 0004003
2004-04-22 06:58 hamilton Note Added: 0004005
2004-04-22 23:34 user72 Status feedback => resolved
2004-04-22 23:34 user72 Resolution open => fixed
2004-04-22 23:34 user72 Note Added: 0004019