Solved

Searching Empty Date in Dataset

Posted on 1998-10-21
13
290 Views
Last Modified: 2010-04-06
I am having great difficulty finding the function in Delphi 4 that can search the Empty DateField.
In Foxpro ( or xBase ) dialect it works like this :

USE Customer
LOCATE FOR Customer.Code = 'A0001' AND Customer.DateField = {}

OR
LOCATE FOR Customer.Code = 'A0001' AND EMPTY(Customer.DateField)

Your help would be greatly appreciated.

Sincerely
Ir. Pintiawan Cahyadi



0
Comment
Question by:apin
  • 7
  • 2
  • 2
  • +2
13 Comments
 

Author Comment

by:apin
ID: 1343735
There is no bookstore in my town ( bandung, indonesia ) that sell any books about programming in Delphi 4
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343736
Apin,

what about :

 .... AND customer.datefield = null
 
or AND customer.Datefield = 0

ps. perhaps, it's possible that you've to look at the format of the datefield and use the null-value of this format!

Regards, Zif
0
 

Author Comment

by:apin
ID: 1343737
The question is that I can't use the locate function in Delphi 4 to search an empty date

IF MyTable.Locate('StringField;DateField',['C-0001',''],[]) then
   ShowMessage('Found.......')

This won't work, please tell me why, thank you very much !
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:itamar
ID: 1343738
Hi apin,

use the filter property like in this example (perhaps you can apply the same trick to the locate method, but I didn´t try)

      Const
            FIRST_DATE = #39'01/01/1900'#39;
          begin
            Table1.Filter := '(SaleDate> ''20/05/1988'') or (SaleDate < ' + FIRST_DATE + ')';
            Table1.Filtered := True;
          end;

IHTH,
Itamar
0
 

Author Comment

by:apin
ID: 1343739
It's because the Foxpro can search empty date, so I am sure that Delphi is much smarter than Foxpro.
I've already tried to use the 'WHILE NOT EOF' syntax and do the sequential search, and of course it works !
Anyway, thank's for your help, but it is not good to use dummy data to replace the empty date field.
0
 
LVL 1

Expert Comment

by:Romanian
ID: 1343740
Try to use TQuery component. In SQL field you must input:
SELECT *
FROM Customer
WHERE (Customer.Code ="A0001") and (Customer.DateField IS NULL)

In run-time you must call Open method of TQuery component and you'll get dataset with all records which have empty date field.
0
 

Author Comment

by:apin
ID: 1343741
Please use MyTable.Locate() function, thank's !
0
 

Accepted Solution

by:
gaona earned 100 total points
ID: 1343742
Dear Apin  
 
The one that you want, is impossible. The sintax of the function Locate is:  
 
function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean;  
 
The parameter KeyValues is of the Variant type that cannot be transformed in NULL without generating a raise exception error.  
The solution of its problem, is to create a new field type boolean and to keep in him, a value True or False case variable DateField has or non value. In this case, the function locate will verify in the database variable Code and the variable that you created to locate the registration.  
Another solution, is to build a Query to determine the location of the wanted registration exactly in case DateField is empty. As I was a programmer in Clipper and standard XBase, I can guarantee that this solution is much more practical and comfortable.  
This Query can be built as it was indicated by Romanian:  
 
SELECT *  
FROM Customer  
WHERE (Customer.Code = A0001 ") and (Customer.DateField IS NULL)  
 
Regards  
 
Gaona
0
 

Author Comment

by:apin
ID: 1343743
Thank's for your answer, I'm very satisfied !
0
 

Author Comment

by:apin
ID: 1343744
After I discussed with my pals, we found that the solution given by 'Mr Zifnab' actually is much better.
The right answer should be :

IF MyTable.Locate('String_Field;Date_Field',VarArrayOf(['A-001',NULL],[]) THEN ShowMessage('Found....')

Actually, Mr Gaona's answer is acceptable when we use Delphi 3, but not Delphi4, since the latest version of Delphi accepts NULL variant type without generating any error at all.

Please accept my apologize !

Sincerely,

Ir. Pintiawan Cahyadi

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343745
aaaaaaaarghhhhhhh ....... no problem. :-)
0
 

Expert Comment

by:gaona
ID: 1343746
Dear Apin  
 
After reading the comment added by you to its presented subject as the answer given by ZifNab's, I tested the solution proposal in Delphi 4, and she presented the same mistake of conversion of types for Variant. That is, continues being impossible to transform a variable type Null for a variable DateTime, since this conversion generates the following mistake in time of execution:  
 
" Project MyProgram.exe raised exception class EVariantError with message ' Invalid variant type conversion'. Process stopped. Use Step or Run to coninue ".  
 
If Delphi 4 accepts this conversion, because my compiler accused this mistake?  
 
Tankfull  
 
Gaona
0
 

Author Comment

by:apin
ID: 1343747
Dear Gaona,

    Since I'm new in Delphi 4, I don't know how to answer your question. Please accept my apologize.

Best regards,
apin

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 57
Tviruailstringtree sort multi columns on header click 1 76
enhance the following code 3 37
DBCtrlGrid, Delphi, Scroll 7 26
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question