Recent

Author Topic: DBEdit1 and DatetoStr!!! Date disappear!  (Read 5382 times)

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
DBEdit1 and DatetoStr!!! Date disappear!
« on: October 12, 2013, 05:20:28 am »
I have some datacontrols on a form and it work fine  but,
I have a DBEdit.text and a onClick event on it.   DBEdit1.text:=DateToStr(Date);

When I click the DBEdit field The onClick event shall show me a date and the date appear in the DBEdit box as it should but,

if I click an other datacontrol in the form the Date disappear in DBEdit1.text!! leaving it empty!

Anyone understand what's going on?

Best regards
Rob

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: DBEdit1 and DatetoStr!!! Date disappear!
« Reply #1 on: October 17, 2013, 07:35:26 am »
Use:
  DBEdit1.Field.AsDateTime:=Date;

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: DBEdit1 and DatetoStr!!! Date disappear!
« Reply #2 on: November 06, 2013, 12:18:17 am »
Thanks but,it don't work! I've got error messgae External sigsev when I click the onclick event for the code!
Rob

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: DBEdit1 and DatetoStr!!! Date disappear!
« Reply #3 on: November 06, 2013, 08:17:01 am »
Please create and upload a simple application which shows the problem, with the database DDL, the simplest possible (probably you only need there one table with one field).

Also tell which DBMS you use, which Lazarus and FPC version, which OS, which widgetset?

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: DBEdit1 and DatetoStr!!! Date disappear!Database work but...
« Reply #4 on: November 06, 2013, 10:39:03 pm »
I have a DBCalendar1 on form2 and a DBEdit1 on form 1. I want when a user click in the dbcalendar on a date that it will appear on the DBedit1 datafield but I can't understand how to do it! Here is the code that don't work.

form1.DBEdit1.Field.AsDateTime:=form2.DBCalendar1Click(DBcalendar1.Date);
 form2.Close;   
Rob

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: DBEdit1 and DatetoStr!!! Date disappear!
« Reply #5 on: November 07, 2013, 06:30:50 am »
How is defined "DBCalendar1Click" ?
it seems to me like event procedure ?
But then you can not assign result to DBEdit1 ?
DBCalendar1 and DBEdit1 are linked to same DataSource ?
Can you post full project ?

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: DBEdit1 and DatetoStr!!! Date disappear!
« Reply #6 on: November 07, 2013, 08:28:27 am »
I suppose that it is necessary to first determine the state of the DataSet, and then apply the values.
eg
  if (your_ds.State in [dsEdit, dsInsert]) then
    ---apply

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: DBEdit1 and DatetoStr!!! Date disappear!
« Reply #7 on: November 07, 2013, 08:32:16 am »
Also, I suggest to create dialog. Then
if(your_dlg.ShowModal = mrOk) then
  your_date_field.AsDate:= your_dlg.Calendar.Date //if state [dsEdit, dsInsert]
Regards

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: DBEdit1 and DatetoStr!!! Date disappear!
« Reply #8 on: November 07, 2013, 11:36:49 am »
You say you're clicking on another datacontrol. Are you clicking on a control that's moving to the next record ?
If you're moving to another record, your previous entry will be cleared from view of a DBEdit.

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: DBEdit1 and DatetoStr!!! Date disappear!
« Reply #9 on: November 08, 2013, 07:17:43 am »
Not so, I suggest to use the date selection dialog. After that, you can save the record(post) and go to a new record(dataSet.Next).

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: DBEdit1 and DatetoStr!!! Date disappear!
« Reply #10 on: November 08, 2013, 07:21:48 am »
You use data control(db edit) to show value of data set(current record-field).

 

TinyPortal © 2005-2018