Forum > LCL
TDBDateTimePicker and ISO8601...?
(1/1)
Sieben:
@Zoran - I thought it would be nice to have TDBDateTimePicker read and write ISO8601 date and time formats when connected to a ftString field, especially when working with a database like SQLite3 which doesn't offer a dedicated date/time data type but functions to operate on ISO string representations (cf here). This would integrate quite seamlessly with TDBDateTimePicker itself like this (plus conversion routines, of course):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TDBDateTimePicker.DataChange(Sender: TObject);var ADateTime: TDateTime; //rkmodbegin if (FChangingCount = 0) then begin Inc(FDataChangeCount); try if Assigned(FDataLink.Field) and not FDataLink.Field.IsNull then begin if FISOMode and (FDataLink.Field.DataType = ftString) then //rkmod ADateTime := ISOToDateTime(FDataLink.Field.AsString) else ADateTime := FDataLink.Field.AsDateTime; // Using the SetTheDateJumpMinMax procedure, instead of property SetDateTimeJumpMinMax(ADateTime); // assignment allows // this control to display dates from database whose value falls // outside of MinDate and MaxDate interval. // Note that user still cannot enter such values in the control. end else DateTime := NullDate; finally Dec(FDataChangeCount); end; end;end; //... procedure TDBDateTimePicker.UpdateData(Sender: TObject);begin if Assigned(FDataLink.Field) then begin if DateIsNull then FDataLink.Field.AsVariant := Null else begin if FISOMode and (FDataLink.Field.DataType = ftString) then //rkmod FDataLink.Field.AsString := DateTimeToISO(DateTime) else FDataLink.Field.AsDateTime := DateTime; end; end;end;
Or it might as well be done with a descendant, of course. However, to share it this would require to move some fields and procs of TDBDateTimePicker from private section to protected, namely FDataLink, FChangingCount, FDataChangeCount and of course procs DataChange and UpdateData which would also have to be declared as virtual. I'm including my working copy of said descendant here, maybe you might want to have a look...?
Edit - sorry, I thought I had included the attachment...
Zoran:
I have just seen this topic. I will take a look when I have time.
Thank you, Sieben.
Navigation
[0] Message Index