Solved

Searching Empty Date in Dataset

Posted on 1998-10-21
13
286 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use Hashing sha1 in Delphi 2010 4 203
Using idhttp to login to instagram 2 76
Delphi XE10 Round Image 2 78
how to update exe applicatio from internet ? 6 67
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now