I have this code that only runs twice with the variables
DateStart := 27-01-2013
DateStop := 31-03-2013
I think it should run with the results of 31-01-2013, 28-02-2013 and 31-3-2013
But I only get 2 results
I am quite sure I have been gazing to much and can’t see the problem
begin
DateStart := EndOfTheMonth(DateStart);
while DateStart <= DateStop do
begin
FsFutureCreate(DateStart, cxDebit.Value, cxKredit.Value, aAccount, aType, aStore, aCity, txtText.Text, lRecord);
DateStart := EndOfTheMonth(IncMonth(DateStart));
end;
end;
Either
FsFutureCreate(which you never told us what it is) has some side-effects, or you have some issue with floating-point fuzz. As you know, date and time values are doubles, and so comparisons like<=are dangerous. (Especially if you disregard the time part, as my analysis below shows.)The second one is the more likely one. I just tried
and got
false, as one would expect. Hence, the problem, in this case, is that theEndOfTheMonthfunction also sets the time to the last second (or millisec) of the day. But even if this wasn’t the case, doing comparisons using = is dangerous when it comes to floating-point values.To fix your comparison, do
instead of
I leave it as an exercise to find out, using the documentation, why this works and is robust.