Solved

Searching Empty Date in Dataset

Posted on 1998-10-21
13
284 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

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

Accepted Solution

by:
gaona earned 100 total points
Comment Utility
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
Comment Utility
Thank's for your answer, I'm very satisfied !
0
 

Author Comment

by:apin
Comment Utility
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
Comment Utility
aaaaaaaarghhhhhhh ....... no problem. :-)
0
 

Expert Comment

by:gaona
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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