Recent

Author Topic: ZVDateTimeCtrls 1.3 is released  (Read 27452 times)

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: ZVDateTimeCtrls 1.3 is released
« Reply #15 on: April 07, 2011, 11:02:07 pm »
But if I use DBZVDateTimePicker then how can I substring (which propertie)?
I need to do some arithmatics with the hour and the minutes part and the Time property was perfect to use. Is there something like DBZVDateTimePicker.time or DBZVDateTimePicker.text I can operte on?

My point is that if you use DB-aware control, you have a DB field object to which this control is connected and you can use this field itself.

So, if you have DBZVDateTimePicker named DB_Vluchtduur which is tied to field object named Field_Vluchtduur, you can read what you need from this field. This way for example:

Code: [Select]
strVluchtduur := TimeToStr(Field_Vluchtduur.AsDateTime);


JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: ZVDateTimeCtrls 1.3 is released
« Reply #16 on: April 08, 2011, 12:42:18 am »
That's a new one for me, I always work with the DB-aware edit and control fields on my form directly.
Tried your suggestion but TimeToStr(Field_Vluchtduur.AsDateTime) gives a compile error 'Field_Vluchtduur not found'. As my form uses data from more than one table should the fieldname be prefixed with a table name or a datasource name?
The DBZVDateTimePicker element is tied to a datasource and the datasource to a table, so doesn't the field object name be prefixed?
 
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: ZVDateTimeCtrls 1.3 is released
« Reply #17 on: April 08, 2011, 10:25:55 am »
That's a new one for me, I always work with the DB-aware edit and control fields on my form directly.
Tried your suggestion but TimeToStr(Field_Vluchtduur.AsDateTime) gives a compile error 'Field_Vluchtduur not found'. As my form uses data from more than one table should the fieldname be prefixed with a table name or a datasource name?
The DBZVDateTimePicker element is tied to a datasource and the datasource to a table, so doesn't the field object name be prefixed?
 

The DB controls have DataField property. This is used to tie the control to particular field object of the underlying database. This field object can be persistent field (you take care of it in design time), or dinamic (created automaticaly by Lazarus in run time).

From your question, I can tell that you do not use persistent fields. Anyway, you can do this:
Code: [Select]
strVluchtduur := TimeToStr(DB_Vluchtduur.DataSource.DataSet.FieldByName(DB_Vluchtduur.DataField).AsDateTime);

Does it work?

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: ZVDateTimeCtrls 1.3 is released
« Reply #18 on: April 08, 2011, 12:33:07 pm »
Jan, I see that maybe I should explain the previous code more detailed.

First, we know that there is a field object. I see that you didn't use persistent field, but nevertheless you can use DataSet's FieldByName function to get the field object, so you can access it by:

(Note that here I'll assume that your dataset is named "Query1" and the column in the underlying dataset is named "Vluchtduur", of course you should change these to what they actually are)
Code: [Select]
Query1.FieldByName('Vluchtduur');

You can access the field's value by its "AsDateTime" property. That is you can use
Code: [Select]
var
  F: TField;
  strVluchtduur: String;
...
  F := Query1.FieldByName('Vluchtduur');
  strVluchtduur := TimeToStr(F.AsDateTime);

or simpler (without declaring the TField variable explicitelly):
Code: [Select]
strVluchtduur := TimeToStr(Query1.FieldByName('Vluchtduur').AsDateTime);
Okay? You can see that you didn't need to use the DBZVDateTimeControl for this.

In my previous post, as I don't know the actual name of your Query component, I used what must work -- DB_Vluchtduur.DataSource.DataSet and you can use it (as you said, the DB_Vluchtduur is tied to a DataSource and it is tied to DataSet, so it must work).
Also, I don't know what the literal name of the underlying column is, but I can use DB_Vluchtduur.DataField, because you surely did set that property, otherwise the control wouldn't work.

That is how I came to the code from my previous post:
Code: [Select]
strVluchtduur := TimeToStr(DB_Vluchtduur.DataSource.DataSet.FieldByName(DB_Vluchtduur.DataField).AsDateTime);
Apart from this, if you are interesting in using persistent field objects, I found these links which can help:

http://www.podgoretsky.com/ftp/docs/Delphi/D5/dg/7_fields.html

http://flylib.com/books/en/2.37.1.139/1/

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: ZVDateTimeCtrls 1.3 is released
« Reply #19 on: April 08, 2011, 12:56:01 pm »
Works like a charm!
But I had to manualy edit some lfm files as Lazarus continued to complain about the .Time member not found. But after removing the .Time references from my lfm files all was running smoothly again. Really like the more modern look of the calendar display.
Great job Zoran and thanks for your patience and help!

 ;D
Jan
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: ZVDateTimeCtrls 1.3 is released
« Reply #20 on: April 08, 2011, 08:14:10 pm »
Works like a charm!
But I had to manualy edit some lfm files as Lazarus continued to complain about the .Time member not found. But after removing the .Time references from my lfm files all was running smoothly again.

I am sorry for this inconvinience.
Alternativly, you could ignore Lazarus' complaining when opening the form and after the form opens change something (some property of the form or move slightly some control on the form, then move it back), then save. Then the Time property disapears from lfm file.

Really like the more modern look of the calendar display.
Great job Zoran and thanks for your patience and help!

 ;D
Jan

You are welcome! I am glad to hear that everything works! :)

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: ZVDateTimeCtrls 1.3 is released
« Reply #21 on: June 13, 2011, 06:02:51 pm »
Zoran,

Maybe a strange question, but would it be possible for you to also release a Delphi version of ZVDateTimeCtrls. I like it so much I also want to use it outside Lazarus in Delphi (2007).
Especially the combination of db and non-db controls and the ability to show just dates or times is so great.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: ZVDateTimeCtrls 1.3 is released
« Reply #22 on: June 13, 2011, 10:02:17 pm »
Zoran,

Maybe a strange question, but would it be possible for you to also release a Delphi version of ZVDateTimeCtrls. I like it so much I also want to use it outside Lazarus in Delphi (2007).
Especially the combination of db and non-db controls and the ability to show just dates or times is so great.
I can surely try... :)

Trying to compile zvdatetimepicker unit in Delphi gives a lot of errors. I will look more into it.

nicke85

  • Jr. Member
  • **
  • Posts: 92
  • #13#10
Re: ZVDateTimeCtrls 1.3 is released
« Reply #23 on: June 13, 2011, 11:24:58 pm »
Just tried your package..Excellent job my friend :)
ArchLinux X64 (XFCE) & Windows 7 SP1 Ultimate X64
FPC 2.7.1 / Lazarus 1.1 / ZeosDBO / fortes4lazarus -- all svn

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: ZVDateTimeCtrls 1.3 is released
« Reply #24 on: June 13, 2011, 11:36:21 pm »
Thanks Zoran.
Take your time it's not a paid job and I am a patient man  ;)
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

 

TinyPortal © 2005-2018