Lazarus

Programming => Packages and Libraries => KOL => Topic started by: JohnvdWaeter on March 04, 2008, 05:04:34 pm

Title: How to set a date in TKoldateTimePicker?
Post by: JohnvdWaeter on March 04, 2008, 05:04:34 pm
Hi, using KOL-CE,

DateTimePicker1.Date:=date+10

does not seem to work

DateTimePicker1.DateTime:=date+10

does not seem to work either

How to?

tia!
John
Title: RE: How to set a date in TKoldateTimePicker?
Post by: OnixJr on March 04, 2008, 06:36:34 pm
Try this:
Put DateUtils in uses clauses, and after do:

DateTimePicker1.Date := IncDay(DateTimePicker1.Date, 10);

See too: IncMonth, IncYear...

I don't know if it's work with Time too...
Title: Re: RE: How to set a date in TKoldateTimePicker?
Post by: JohnvdWaeter on March 04, 2008, 07:10:38 pm
Quote from: "OnixJr"
Try this:
Put DateUtils in uses clauses, and after do:

DateTimePicker1.Date := IncDay(DateTimePicker1.Date, 10);

See too: IncMonth, IncYear...

I don't know if it's work with Time too...


Hi OnyxJr,

I don't think that is the problem.   I think the problem is in the procedure DateTime2SystemTime in KOL.pas.

If I use this procedure to convert today (march 4, 2008),
I get ST.wYear=109, ST.wMonth=3 and ST.wDay=6

where it *should* read wYear=2008, wMonth=3 and wDay=4

That procedure is wrong, but I just cannot figure out why... have to do some more digging....

John
Title: Re: RE: How to set a date in TKoldateTimePicker?
Post by: JohnvdWaeter on March 04, 2008, 09:57:04 pm
I think, in KOL.PAS, one line should be added in the procdurebody of DateTime2SystemTime:

Code: [Select]

begin
  Days := Trunc( DateTime);
  MSec := Round((DateTime - Days) * MSecsPerDay);
 
  Days := Days+693594; // <-- add this line

  Result := False;  
  ......



It seems to work, but I'm not sure if this is the right way...

John
Title: Re: RE: How to set a date in TKoldateTimePicker?
Post by: JohnvdWaeter on March 04, 2008, 10:13:35 pm
And in the last line of SystemTime2Datetime:

Code: [Select]

   DateTime := I * 365 + I div 4 - I div 100 + I div 400 + _Day -693594  // <-- number added
             + (LongInt(wHour) * 3600000 + LongInt(wMinute) * 60000 + LongInt(wSecond) * 1000 + LongInt(wMilliSeconds)) / MSecsPerDay;



To get a proper value back from DateTimePicker1.Date


But again, I'm not sure... this might break other code? Could it be that the Date-property of TKolDateTimepicker actually is treated like TTimestamp instead of TDateTime?
Title: RE: Re: RE: How to set a date in TKoldateTimePicker?
Post by: JohnvdWaeter on March 04, 2008, 10:51:43 pm
And then, suddenly, the penny drops...
I had SysUtils in the uses-clause... mixing up different date and time types....

Time for a beer....
TinyPortal © 2005-2018