[Lazarus] Filtering on date with TDbf
shoKwave
shokwave at gmx.net
Wed Feb 1 17:00:25 CET 2012
Am 30.01.2012 12:25, schrieb Koenraad Lelong:
> Hi,
>
> Lazarus 0.9.30
>
> I want to filter a TDbf. The field is a date.
> When I try in Filter in Lazarus :
> DATUM >= '1/1/2011'
> or
> DATUM >= "1/1/2011"
> or
> DATUM >= '1.1.2011'
>
> In my application :
> tblTik.Filter:='DATUM>='''+DateToStr(XferStart)+'''';
>
> I get an error :
> Index based on unknown field ">=".
>
> What am I doing wrong ?
>
> Regards,
>
> Koenraad Lelong.
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
Hi,
IIRC, first of all you need an index based on the field(s) you want to
filter. The error is shown because the index "DATUM" doesn't exists.
Here is the real problem, I don't know how to create an index of ftDate.
If I try an error is shown because only string and float fields are
allowed. But you could convert your database and store all dates as
strings. To format the date right you can use
procedure TForm1.FormCreate(Sender: TObject);
begin
DefaultFormatSettings.DateSeparator:='.';
DefaultFormatSettings.ShortDateFormat:='yyyy.mm.dd';
...
end;
With this lines DateToStr() should convert it right.
The filter property wants the name of the filter to compare with, not
the name of the field.
dbf1.Filter:='INDEXNAME>='+QuotedStr(DateToStr(XferStart));
dbf1.Filtered:=true;
If the date-field is of ftString, the dates are correctly formatted and
the index is build it should work.
Hope this helps.
regards
Ingo
More information about the Lazarus
mailing list