Re: [Lazarus] DateDif function needed
On 08.11.2013 21:35, John Landmesser wrote: Hi List, i'm searching a pascal datetime function that simulates an Excel function: DateDif Excel for example knows the function DateDif that returns the number of Years, month and days between Date1 and date2. Date1 := 21.12.2012 Date2 := 01.01.2013 Result would be: 0 years, 0 moths, 11 days I tried to do it on my own, but without success. But i think there is a function out there but i don't know its name :-(( Thanks for your tipps John -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus Hi list, This discussion seems to be finished ( 92 posts ) and i want to make a proposal as solution: Use the function DateDiff from Jedi ( RxLib ) ( JvJCLUtils.pas ). It's not perfect, but it works for me: ** procedure DateDiff(Date1, Date2: TDateTime; var Days, Months, Years: word); var DtSwap: TDateTime; Day1, Day2, Month1, Month2, Year1, Year2: word; begin if Date1 Date2 then begin DtSwap := Date1; Date1 := Date2; Date2 := DtSwap; end; DecodeDate(Date1, Year1, Month1, Day1); DecodeDate(Date2, Year2, Month2, Day2); Years := Year2 - Year1; Months := 0; Days := 0; if Month2 Month1 then begin Inc(Months, 12); Dec(Years); end; Inc(Months, Month2 - Month1); if Day2 Day1 then begin // von mir auskommentiert Inc(Days, DaysPerMonth(Year1, Month1)); Inc(Days, DaysInAMonth(Year1, Month1)); if Months = 0 then begin Dec(Years); Months := 11; end else Dec(Months); end; Inc(Days, Day2 - Day1); end; ** Hope that statement is usefull for somebody reading this thread. I couldn't find any bug report on Project JEDI - Issue Tracker. Thanks for this discussion! John -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] Photos in Windows Mobile
Hi! I would like to develop the feature of take pictures from windows mobile handelds and save them in SQLite databases. May someone tell me how to implement this feature in Lazarus? Greetings from Sao Paulo - Brazil Ricardo -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] DateDif function needed
On 11/16/2013 5:08 AM, John Landmesser wrote: This discussion seems to be finished ( 92 posts ) and i want to make a proposal as solution: Use the function DateDiff from Jedi ( RxLib ) ( JvJCLUtils.pas ). that routine is actually a procedure... the one i posted is a function that returns the sought values ;) It's not perfect, but it works for me: ** procedure DateDiff(Date1, Date2: TDateTime; var Days, Months, Years: word); you have to feed this one with 5 variables... the one i posted you feed only 3 variables and you get back a three field record... i've been working on also adding 3 more fields for hour, minutes and seconds ;) plus, the name should be more in line with the actual process... CalendarDateDiff or CalendarDiff... just my two cents, for what they're worth... -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Photos in Windows Mobile
Hi Ricardo, Use SHCameraCapture in unit aygshell. You have to get it saved as a file first by the Windows API. I would have preferred to get a pointer to memory. uses aygshell; function CameraCapture(Folder, FileName: WideString; Width, Height: Integer; Video: Boolean): Boolean; var SI: SIPINFO; CC: TSHCAMERACAPTURE; R: HRESULT; begin FillChar(CC, SizeOf(CC), 0); CC.cbSize:=SizeOf(CC); CC.hwndOwner:=MainForm.Handle; CC.pszInitialDir:=PWideChar(Folder); CC.pszDefaultFileName:=PWideChar(FileName); CC.pszTitle:='Camera'; CC.VideoTypes:=CAMERACAPTURE_VIDEOTYPE_ALL; if Video then CC.Mode:=CAMERACAPTURE_MODE_VIDEOWITHAUDIO else CC.Mode:=CAMERACAPTURE_MODE_STILL; CC.StillQuality:=CAMERACAPTURE_STILLQUALITY_NORMAL; CC.nResolutionWidth:=Width; CC.nResolutionHeight:=Height; CC.nVideoTimeLimit:=60; SetLastError(0); R:=SHCameraCapture(CC); Result:=R=S_OK; end; Regards, Paul. On Sat, Nov 16, 2013 at 2:54 PM, Arí Ricardo Ody ar...@gmx.com wrote: Hi! I would like to develop the feature of take pictures from windows mobile handelds and save them in SQLite databases. May someone tell me how to implement this feature in Lazarus? Greetings from Sao Paulo - Brazil Ricardo -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] DateDif function needed
On 11/16/2013 5:08 AM, John Landmesser wrote: This discussion seems to be finished ( 92 posts ) and i want to make a proposal as solution: Use the function DateDiff from Jedi ( RxLib ) ( JvJCLUtils.pas ). It's not perfect, but it works for me: in what way do you think it is not perfect for your purposes or needs? FWIW: i copied the jedi datediff you posted and placed it in my testing project to compare my output with it... the results are exactly the same... but i still wonder if the last day of a month to the last day of another month should be counted as a full month... eg: CalendarDateDiff: 2012-01-31 to 2012-02-29 =0 yrs0 mos 29 days JediDateDiff: 2012-01-31 to 2012-02-29 =0 yrs0 mos 29 days should this actually be 2012-01-31 to 2012-02-29 =0 yrs1 mos 0 days -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] DateDif function needed
On 11/16/2013 10:09 AM, waldo kitty wrote: On 11/16/2013 5:08 AM, John Landmesser wrote: This discussion seems to be finished ( 92 posts ) and i want to make a proposal as solution: Use the function DateDiff from Jedi ( RxLib ) ( JvJCLUtils.pas ). that routine is actually a procedure... the one i posted is a function that returns the sought values ;) It's not perfect, but it works for me: ** procedure DateDiff(Date1, Date2: TDateTime; var Days, Months, Years: word); you have to feed this one with 5 variables... the one i posted you feed only 3 typo! feed only 2 variables and you get back a three field record... i've been working on also adding 3 more fields for hour, minutes and seconds ;) -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] DateDif function needed
On Fri, 15 Nov 2013, Bart wrote: On 11/15/13, Michael Schnell mschn...@lumino.de wrote: In fact I consider it a waste of bandwidth to discuss a problem that obviously is not solvable at this length. (But who am I do complain about that :-[ .) Of course it can be solved. Just add a enough options (appr. 255?) to the procedure to make it behave just like the caller wants. Do I want to do that? No. ;-) The fun part for me is the fact that a seemingly simple question, where at first glance you would think I'll just implement that, can lead to so many problems. I added a modified version of your implementation to the DateUtils unit as: Procedure PeriodBetween(Const ANow, AThen: TDateTime; Out Years, months, days : Word); I chose this name because it is more in line with the existing XXXBetween functions. I did change the algorithm so it does not do the correction for february of the leap year. It returns now the same results as the Jedi function. (which I didn't take for license reasons) Thanks for providing an implementation. Michael. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] DateDif function needed
On 16/11/2013 18:21, Michael Van Canneyt wrote: On Fri, 15 Nov 2013, Bart wrote: The fun part for me is the fact that a seemingly simple question, where at first glance you would think I'll just implement that, can lead to so many problems. I added a modified version of your implementation to the DateUtils unit as: Procedure PeriodBetween(Const ANow, AThen: TDateTime; Out Years, months, days : Word); I chose this name because it is more in line with the existing XXXBetween functions. I did change the algorithm so it does not do the correction for february of the leap year. It returns now the same results as the Jedi function. (which I didn't take for license reasons) Thanks for providing an implementation. A suggestion if I may: given the wide variation of possibilities of interpretation, some comments in the code about how the calculation is supposed to work would be very much appreciated, I'm sure. (Of course, that applies even more to added documentation). Just wanted to avoid another huge thread discussing PeriodBetween in future... as well as confusion on the part of possible users in general. Thanks, Reinier -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] DateDif function needed
On Sat, 16 Nov 2013, Reinier Olislagers wrote: On 16/11/2013 18:21, Michael Van Canneyt wrote: On Fri, 15 Nov 2013, Bart wrote: The fun part for me is the fact that a seemingly simple question, where at first glance you would think I'll just implement that, can lead to so many problems. I added a modified version of your implementation to the DateUtils unit as: Procedure PeriodBetween(Const ANow, AThen: TDateTime; Out Years, months, days : Word); I chose this name because it is more in line with the existing XXXBetween functions. I did change the algorithm so it does not do the correction for february of the leap year. It returns now the same results as the Jedi function. (which I didn't take for license reasons) Thanks for providing an implementation. A suggestion if I may: given the wide variation of possibilities of interpretation, some comments in the code about how the calculation is supposed to work would be very much appreciated, I'm sure. (Of course, that applies even more to added documentation). Just wanted to avoid another huge thread discussing PeriodBetween in future... as well as confusion on the part of possible users in general. When documenting, all will be explained. I think it's fairly simple, really. Start with D1. Call this D. Keep adding 1 to year of D till your jumps over D2. If you jumped over, substract 1 from year. Keep adding 1 to month of D till D jumps over D2. If you jumped over, substract 1 from month. Keep adding 1 to day of D till D reaches D2. The number of years, months, days you thus added is the period. I may fiddle a bit with the definition of jumps over and reaches, but essentially that is it. Michael. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] DateDif function needed
On 11/16/2013 11:07 AM, waldo kitty wrote: [...] but i still wonder if the last day of a month to the last day of another month should be counted as a full month... eg: CalendarDateDiff: 2012-01-31 to 2012-02-29 =0 yrs0 mos 29 days JediDateDiff: 2012-01-31 to 2012-02-29 =0 yrs0 mos 29 days should this actually be 2012-01-31 to 2012-02-29 =0 yrs1 mos 0 days to this end, i now have my routine doing this... note *'s below... CalendarDateDiff: 2012-01-31 to 2012-01-31 =0 yrs0 mos0 days JediDateDiff: 2012-01-31 to 2012-01-31 =0 yrs0 mos0 days CalendarDateDiff: 2012-01-31 to 2012-02-29 =0 yrs1 mos0 days* JediDateDiff: 2012-01-31 to 2012-02-29 =0 yrs0 mos 29 days CalendarDateDiff: 2012-01-31 to 2012-03-31 =0 yrs2 mos0 days JediDateDiff: 2012-01-31 to 2012-03-31 =0 yrs2 mos0 days CalendarDateDiff: 2012-01-31 to 2012-04-30 =0 yrs3 mos0 days* JediDateDiff: 2012-01-31 to 2012-04-30 =0 yrs2 mos 30 days CalendarDateDiff: 2012-01-31 to 2012-05-31 =0 yrs4 mos0 days JediDateDiff: 2012-01-31 to 2012-05-31 =0 yrs4 mos0 days CalendarDateDiff: 2012-01-31 to 2012-06-30 =0 yrs5 mos0 days* JediDateDiff: 2012-01-31 to 2012-06-30 =0 yrs4 mos 30 days CalendarDateDiff: 2012-01-31 to 2012-07-31 =0 yrs6 mos0 days JediDateDiff: 2012-01-31 to 2012-07-31 =0 yrs6 mos0 days CalendarDateDiff: 2012-01-31 to 2012-08-31 =0 yrs7 mos0 days JediDateDiff: 2012-01-31 to 2012-08-31 =0 yrs7 mos0 days CalendarDateDiff: 2012-01-31 to 2012-09-30 =0 yrs8 mos0 days* JediDateDiff: 2012-01-31 to 2012-09-30 =0 yrs7 mos 30 days CalendarDateDiff: 2012-01-31 to 2012-10-31 =0 yrs9 mos0 days JediDateDiff: 2012-01-31 to 2012-10-31 =0 yrs9 mos0 days CalendarDateDiff: 2012-01-31 to 2012-11-30 =0 yrs 10 mos0 days* JediDateDiff: 2012-01-31 to 2012-11-30 =0 yrs9 mos 30 days CalendarDateDiff: 2012-01-31 to 2012-12-31 =0 yrs 11 mos0 days JediDateDiff: 2012-01-31 to 2012-12-31 =0 yrs 11 mos0 days -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] DateDif function needed
On 11/16/2013 12:27 PM, Reinier Olislagers wrote: On 16/11/2013 18:21, Michael Van Canneyt wrote: On Fri, 15 Nov 2013, Bart wrote: The fun part for me is the fact that a seemingly simple question, where at first glance you would think I'll just implement that, can lead to so many problems. I added a modified version of your implementation to the DateUtils unit as: Procedure PeriodBetween(Const ANow, AThen: TDateTime; Out Years, months, days : Word); I chose this name because it is more in line with the existing XXXBetween functions. I did change the algorithm so it does not do the correction for february of the leap year. It returns now the same results as the Jedi function. (which I didn't take for license reasons) Thanks for providing an implementation. i have not received Michael's post quoted above... was it posted to the list or only in private to a few individuals? -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] DateDif function needed
After all, what would the optimum solution? Em 16-11-2013 14:40, Michael Van Canneyt escreveu: On Sat, 16 Nov 2013, Reinier Olislagers wrote: On 16/11/2013 18:21, Michael Van Canneyt wrote: On Fri, 15 Nov 2013, Bart wrote: The fun part for me is the fact that a seemingly simple question, where at first glance you would think I'll just implement that, can lead to so many problems. I added a modified version of your implementation to the DateUtils unit as: Procedure PeriodBetween(Const ANow, AThen: TDateTime; Out Years, months, days : Word); I chose this name because it is more in line with the existing XXXBetween functions. I did change the algorithm so it does not do the correction for february of the leap year. It returns now the same results as the Jedi function. (which I didn't take for license reasons) Thanks for providing an implementation. A suggestion if I may: given the wide variation of possibilities of interpretation, some comments in the code about how the calculation is supposed to work would be very much appreciated, I'm sure. (Of course, that applies even more to added documentation). Just wanted to avoid another huge thread discussing PeriodBetween in future... as well as confusion on the part of possible users in general. When documenting, all will be explained. I think it's fairly simple, really. Start with D1. Call this D. Keep adding 1 to year of D till your jumps over D2. If you jumped over, substract 1 from year. Keep adding 1 to month of D till D jumps over D2. If you jumped over, substract 1 from month. Keep adding 1 to day of D till D reaches D2. The number of years, months, days you thus added is the period. I may fiddle a bit with the definition of jumps over and reaches, but essentially that is it. Michael. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] DateDif function needed
Am 2013-11-16 16:09, schrieb waldo kitty: plus, the name should be more in line with the actual process... CalendarDateDiff or CalendarDiff... Yes, that sounds good. It makes it clear that the calculation is different to diff-function that use average values. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] *** GMX Spamverdacht *** Re: DateDif function needed
Am 2013-11-16 18:40, schrieb Michael Van Canneyt: Start with D1. Call this D. Keep adding 1 to year of D till your jumps over D2. If you jumped over, substract 1 from year. Keep adding 1 to month of D till D jumps over D2. If you jumped over, substract 1 from month. Keep adding 1 to day of D till D reaches D2. The number of years, months, days you thus added is the period. I may fiddle a bit with the definition of jumps over and reaches, but essentially that is it. That sounds very reasonable and is actually the rationale behind this kind of calendar diff function. I don't thing that anything needs to be changed to this algorithm. So from 28.2. of a year to 29.2. of the next (leap) year is then 1 year plus 1 day and from 29.2. to 28.2. is not a full year (11 months + 28 days)! That's how it would be defined and I can't think of anything that makes more sense here. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] Noobie - Interface problem in Windows
Hi, I am a bit of a noobie to Lazarus and I have been designing an app with Lazarus running under Linux. It all seemed to be going well. Tonight I booted into Windows and decided to quickly compile the app to see what it looked like and there is a problem with a blue background that I don't get compiling under Linux. See these screenshots as an example: Running under Windows 7, Lazarus 1.0.12 fpc 2.6.2 https://dl.dropboxusercontent.com/u/3940444/laz_windows%201.0.12%20fpc%202.6.2.png Running under Linux (LMDE), Lazarus 1.0.10 fpc 2.6.2 gtk https://dl.dropboxusercontent.com/u/3940444/laz_linux%201.0.10%20fpc%202.6.2.png Running under Linux (LMDE), Lazarus 1.3 svn fpc 2.6.2 Qt https://dl.dropboxusercontent.com/u/3940444/laz_linux%201.3%20fpc%202.6.2.png The tabs are a TTabControl rather than a TPageControl. My thinking behind using a TabControl was that only minor UI changes will be required when the tab changes and I could do this with code. If I used a PageControl I would have had to make copies of all the UI items for each page, which would mean a lot of time, effort and probably a bigger binary. Not sure why I am getting a blue background only in Windows, when it looks fine in Linux? All the UI elements below the TabControl appear to be it's children in the object inspector. Should I have placed a panel before placing the other UI elements? I very much appreciate any help or guidance you can offer me. Thanks best regards, Martin -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Noobie - Interface problem in Windows
On 16/11/2013 23:22, Martin wrote: Hi, I am a bit of a noobie to Lazarus and I have been designing an app with Lazarus running under Linux. It all seemed to be going well. Tonight I booted into Windows and decided to quickly compile the app to see what it looked like and there is a problem with a blue background that I don't get compiling under Linux. See these screenshots as an example: Running under Windows 7, Lazarus 1.0.12 fpc 2.6.2 https://dl.dropboxusercontent.com/u/3940444/laz_windows%201.0.12%20fpc%202.6.2.png Running under Linux (LMDE), Lazarus 1.0.10 fpc 2.6.2 gtk https://dl.dropboxusercontent.com/u/3940444/laz_linux%201.0.10%20fpc%202.6.2.png Running under Linux (LMDE), Lazarus 1.3 svn fpc 2.6.2 Qt https://dl.dropboxusercontent.com/u/3940444/laz_linux%201.3%20fpc%202.6.2.png The tabs are a TTabControl rather than a TPageControl. My thinking behind using a TabControl was that only minor UI changes will be required when the tab changes and I could do this with code. If I used a PageControl I would have had to make copies of all the UI items for each page, which would mean a lot of time, effort and probably a bigger binary. Not sure why I am getting a blue background only in Windows, when it looks fine in Linux? All the UI elements below the TabControl appear to be it's children in the object inspector. Should I have placed a panel before placing the other UI elements? I very much appreciate any help or guidance you can offer me. Thanks best regards, Martin Martin, FWIW, I /prefer/ the blue background! It may be worth checking on Windows themes support (I'm new to Lazarus as well). By the way, it's MSNs, and not MSN's. Cheers -- David Web: http://www.satsignal.eu -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus