Solved

Searching Empty Date in Dataset

Posted on 1998-10-21
13
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 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