Solved

Searching Empty Date in Dataset

Posted on 1998-10-21
13
288 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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