Recent

Author Topic: DBDateTimePicker component error  (Read 4506 times)

jimbill

  • New Member
  • *
  • Posts: 11
DBDateTimePicker component error
« on: August 30, 2015, 02:14:15 am »
Hello Everyone,

I cant speak very well.
Lazarus is very good tool.
Congratulations to the developers. And so forth

Object inspector: Kind: dtkDate
 
DBDateTimePicker1.Field.AsDateTime does not work properly if I change the value from program. (GUI)
 
DBDateTimePicker1 DataSource, Datafield is set correctly.

with Kind: dtkTime it working perfectly refresh the DBDateTimePicker1.Field.AsDateTime
but with Kind: dtkDate it doesnt.
   (with two different DBDateTimePicker with same DataSource,Datafield)


    Form9.Button3ellenoriz.Enabled:=true;
    Form9.Label11nap.Caption:=Days[DayOfTheWeek(Form9.DBDateTimePicker1datum.Field.AsDateTime)];
    showmessage(IntToStr(DayOfTheWeek(Form9.DBDateTimePicker1datum.Field.AsDateTime)));
    showmessage(Form9.DBDateTimePicker1datum.Field.Text)

Any help welcome :).

Thanks,
Jimbill   

sqlite3
ZEOSDBO-7.1.4-stable

windows 7/32 bit
lazarus 1.4.2  i386-win32-win32/win64
« Last Edit: August 30, 2015, 02:44:49 am by jimbill »

derek.john.evans

  • Guest
Re: DBDateTimePicker component error
« Reply #1 on: August 30, 2015, 06:58:42 am »
I cant reproduce any issues. Maybe write a quick test using TDataSource and TBufDataset.

It may be the underlining database. What is the field type? ie: ftTime/ftDate/ftDateTime?

jimbill

  • New Member
  • *
  • Posts: 11
Re: DBDateTimePicker component error
« Reply #2 on: August 31, 2015, 03:06:39 am »
in sql the field:

 ... DATETIME NOT NULL,

the important thing would be to write to a label (next to DBDateTimePicker1) which day was selected.

In the OnChange event of DBDateTimePicker1 (Object inspector: Kind: dtkDate) I'd like to print the new value of DBDateTimePicker1.Field.AsDateTime (with convert to day) but its showing the old one it doesnt refresh immediately after I select a day on the DBDateTimePicker1.

Now I tried also in OnEditingDone event and there its working well. I select the day on calendar (DBDateTimePicker1) and press enter or click anywhere and its refreshing my day label. 

somehow in the onchange event it doesnt have the new value..

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: DBDateTimePicker component error
« Reply #3 on: August 31, 2015, 08:25:53 am »
@jimbill:
Could you please upload a project, as simple as possible, which demonstrates the problem. For example, one form which has ZConnection, ZQuery, DBDateTimePicker, Label and a Button with event which shows the problem. In code, you may add comments that describes what is done and what is expected.

Also, you should provide a "create sql" for a simple db table on which the Query is connected. For example:
Code: [Select]
create table test (id int, date1 datetime)
Tell us also which db system (Firebird, Postgresql, MySQL, sqlite...) you use. Probably it dosn't matter, but just to be complete.

Zoran

EDIT: You do not need to do this if my next post describes well your problem.
« Last Edit: August 31, 2015, 10:40:30 am by Zoran »

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: DBDateTimePicker component error
« Reply #4 on: August 31, 2015, 10:38:46 am »
Oh, I see now what you mean. By design, the OnChange event does not update the underlying database field, which gets actually updated only when EditingDone is fired.

I will think about the solution. I wouldn't like updating the field at every display change. I wouldn't like to publish Date and Time properties either. I'm afraid these workarounds could lead to other unwanted side effects.

As a temporary workaround, you could alter the code of DBDateTimePicker yourself, by adding the line
Code: [Select]
property DateTime; under public section of TDBDateTimePicker. Then, use this property in your OnChange event, instead of the field's value.

But, better consider using OnEditingDone. Why do you think it is not good enough for you?
« Last Edit: August 31, 2015, 10:44:02 am by Zoran »

jimbill

  • New Member
  • *
  • Posts: 11
Re: DBDateTimePicker component error
« Reply #5 on: August 31, 2015, 06:10:09 pm »
Thanks for your help :)

Finally I choose your solution:
 
"you could alter the code of DBDateTimePicker yourself, by adding the line
Code: [Select]

property DateTime;

under public section of TDBDateTimePicker. Then, use this property in your OnChange event, instead of the field's value. "

I choose this because I need to refresh immediately my own day label (Monday,Tuesday.. etc) next to DbDateTimePicker to look well.
If I use OnEditingDone that do the job too but refresh later when I press enter or click anywhere in the form. (when I select a date in dbdatetimepicker the old day value was there on my own label not the new what was selected until I click anywhere....)


So property DateTime helped me in this problem.
And I use Onchange event to refresh day on my label (Monday,Tuesday.. etc).


 

TinyPortal © 2005-2018