Recent

Author Topic: (SOLVED) How to Filter Date in Blank?  (Read 10786 times)

InfoMan

  • New Member
  • *
  • Posts: 49
(SOLVED) How to Filter Date in Blank?
« on: March 18, 2012, 01:41:20 am »
Good evening, folks! I'm using the component TDbf to create my program because I need to read DBF files in Lazarus. Please help me. How do I create a filter to find all records that have blank date? I've tried several ways and failed. Thank you very much all who respond.
« Last Edit: March 24, 2012, 04:31:38 pm by InfoMan »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: How to Filter Date in Blank?
« Reply #1 on: March 18, 2012, 12:30:35 pm »
InfoMan, give us some more info ;)

What Lazarus version, operating system?
What exactly have you tried? How did it fail?
Have you read the tdbf wiki page:
http://wiki.lazarus.freepascal.org/Lazarus_Tdbf_Tutorial

Note: while I can get tdbf working to the point of showing stuff in a grid, I don't know how to filter things, so I'd be interested in getting an answer into the wiki page.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

InfoMan

  • New Member
  • *
  • Posts: 49
Re: How to Filter Date in Blank?
« Reply #2 on: March 18, 2012, 02:35:09 pm »
I am creating a program that accesses and displays files DBF ready reports from it. Necessarily have to use DBF as the program from which data is read only exports in this format. I think in the future to convert the DBFs imported into another format (Paradox, Firebird, etc.), but the moment I have to maintain compatibility in DBF format.

I'm using version 0.9.31 (03/03/2012) in Windows 7. Like the original program (which exports the data in DBF) only works on Windows, I can not do it in Linux.

Use the component TDbf 6.9 with the name "dados". Filter tried in different ways such as:

dados.filter: = 'DT_ENCERRA ='';
dados.fitlered: = true;

I tried also:

dados.filter: = 'DT_ENCERRA = '01 / 01/1900;
dados.fitlered: = true;

01/01/1900 is the standard for dates blank

and yet another way that I can not remember now.

I need the program in one of his reports display all records that have DT_ENCERRA blank. A failure that occurs is that it displays a blank report with no records in the report, and I know there are records that satisfy this condition. Other times he ignores the filter and displays all records in the report.

The reports are displayed through component LazReport version 0.9.8 that came with Lazarus.


Thank you very much all who respond and sorry for the size of the question, but tried to be as clear as possible this time.
« Last Edit: March 18, 2012, 03:28:56 pm by InfoMan »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to Filter Date in Blank?
« Reply #3 on: March 18, 2012, 11:11:44 pm »
You have to use the DTOS function to convert the date to a string, use double quotes around the string and write the datestring in the YYYYMMDD format. This means:

dados.Filter := 'DTOS(DT_ENCERRA)="19000101"'

InfoMan

  • New Member
  • *
  • Posts: 49
Re: How to Filter Date in Blank?
« Reply #4 on: March 19, 2012, 12:03:17 am »
Thanks for the reply. I managed to solve part of the problem. To filter by date is working properly.

I would like to help me filter blank values ​​at the date. How do I know if the date is blank, ie, the field is not populated DT_ENCERRA?

Thank you very much all who respond.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to Filter Date in Blank?
« Reply #5 on: March 19, 2012, 04:16:37 pm »
One way to do it would be to have a function based on the date field in question. Say it is called davosTblDT_ENCERRA. As you scroll through the table you can check

function IsDateBlank: boolean;
begin
 result := trunc(davosTblDT_ENCERRA.AsDateTime) = 0;
end;

InfoMan

  • New Member
  • *
  • Posts: 49
Re: How to Filter Date in Blank?
« Reply #6 on: March 19, 2012, 04:38:09 pm »
OK. Thanks for the reply. But how do I apply this filter function in my table? Thank you.

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: How to Filter Date in Blank?
« Reply #7 on: March 19, 2012, 05:22:19 pm »
One way to do it would be to have a function based on the date field in question. Say it is called davosTblDT_ENCERRA. As you scroll through the table you can check

function IsDateBlank: boolean;
begin
 result := trunc(davosTblDT_ENCERRA.AsDateTime) = 0;
end;

Hi Infoman,

I think Howardpc was suggesting to put this function within a loop and process each record and to reset the blank fields to a '0'...You only need to run this 're-format loop' once on the table. Now you can filter for '0' value.

Here is pseudocode...

Code: [Select]
For each.record in table do
  begin
     Isdateblank; ///call function to reset the date field to '0' if blank
  end;

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to Filter Date in Blank?
« Reply #8 on: March 20, 2012, 09:01:09 pm »
IF you want only records WITHOUT a blank date then

table.filter := DTOS(DT_ENCERRA)>"19000101";

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: How to Filter Date in Blank?
« Reply #9 on: March 21, 2012, 07:39:49 am »
Infoman, if this solves your problem, would you mind describing how to filter data on the wiki page
http://wiki.lazarus.freepascal.org/Lazarus_Tdbf_Tutorial

Thanks!

(Naked self interest here: if I ever want to do more with tdbf, it's much easier for me to have a look at the wiki page than go trawling through forum posts... suspect that may apply to other people as well)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

InfoMan

  • New Member
  • *
  • Posts: 49
Re: How to Filter Date in Blank?
« Reply #10 on: March 22, 2012, 02:11:46 am »
I would be extremely happy and honored to be able to contribute to the Lazarus Project. Unfortunately still can not find the solution to my problem.

I was checking the database in DBF and considers the blank date as "12:00:00 PM" and not as "01/01/1900", as I said earlier. In previous versions of DBF was what I said before, but in the current release date is still blank as "12:00:00 AM".

I need to filter all records that are blank with the date so you can display them in a report to the LazReport. If you can not filter out these dates, unfortunately, my program will be unusable because it is a major part of it.

I'm on a program that checks all the cases are still pending. I do this through the field DT_ENCERRA, which when completed means that the case is closed. One of the reports which make available the program is to open cases. So I can send this report need to filter all records that are with the closing date open (Value: "12:00:00 AM").

I'm sure will be able to help me in solving this problem.
I am very grateful to everyone who gave suggestions so far, but still could not do it. I ask you to help me as soon as I will be able to publish this tip on Wiki Lazarus with pleasure.

InfoMan

  • New Member
  • *
  • Posts: 49
Re: How to Filter Date in Blank?
« Reply #11 on: March 23, 2012, 02:24:40 am »
I managed to filter through the blank records OnFilterRecord event handler. For this, I did so:

if not dados.FieldByName ('DT_ENCERRA'). IsNull then Accept: = False;

Putting up with the accept parameter value of false records are ignored.

There is a hint for those who need to do it like me, and thank you to everyone who tried to help me.

Once posível publish the Wiki TBF this tip. So long and thanks.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: How to Filter Date in Blank?
« Reply #12 on: March 23, 2012, 07:00:29 am »
Thanks for the update and promising to update the wiki - and I'm glad your problems are solved ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

InfoMan

  • New Member
  • *
  • Posts: 49
Re: How to Filter Date in Blank?
« Reply #13 on: March 25, 2012, 04:08:20 pm »
Thanks for the update and promising to update the wiki - and I'm glad your problems are solved ;)

As promised updated the wiki referring to Lazarus componetne TDbf with tips on how filtar dates and white and how to filter specific values. I made this update in both english-tions and in Portuguese.

Thank you for the opportunity to collaborate with Lazarus.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: (SOLVED) How to Filter Date in Blank?
« Reply #14 on: March 25, 2012, 04:28:40 pm »
Thanks very much, InfoMan, for helping me and other users of TDBF with documenting it!
Wish there were more of your kind... ;)

Regards,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018