Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TField Events and posting - Driving me nuts!

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
Hello again! I am trying to get dates to display and post correctly in a dataset. In my database table I have two fields AppearanceDate and MailDate. I have a query that returns this information into a dataset. I have a DBGrid on my form that displays the AppearanceDate and allows entry of the MailDate. I have a GetText handler for AppearanceDate that converts the database format (YYYYMMDD) and displays a proper US date format of MM/DD/YYYY (this is done by two functions DateFormat - changes to MM/DD/YYYY and ConvertDate - changes to YYYYMMDD). When the user enters a MailDate I have a Validate handler (IsValidDate). If the user has entered a Valid date I need to take the entry (MM/DD/YYYY) and convert it to YYYYMMDD before posting to the database. I have tried TField.OnGetText, but that runs prior to the validation (and continues in a loop forever!). I tried BeforePost in the query, but I couldn't get that to work either. What do I need to do to continue to display the user entered MailDate as MM/DD/YYYY but post my data in the correct YYYYMMDD format?

Thanks for any suggestions!

Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
hi

Have you looked at the DisplayFormat property in the Fields editor of the TQuery for your date fields, and setting that to the dd/mm/yyyy ?

lou
 
I've looked at that but I couldn't figure out how to rearrange the numbers. My database stores 20021028, what would I do in the displayformat to specify the moving of numbers so it displays 10/28/2002? Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Have you looked at using OnSetText to reverse any formatting you do before posting?

Is the database field actually of type DateTime or is it a string?

lou
 
Yes I have looked at OnSetText, but Text is a CONST in that procedure and I can't do anything with it!!! The database field is a string. I have tried:

Sender.Value := convertDate(Sender.AsString)

but since that changes the value the Validate function runs again and my database field (20020916) returns a not a valid date error!

Thanks! Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Leslie, what kind of database are you using? Use the the date format supported by your database. Remember the Y2K bug? it started this way.

Delphi has the datetime (press F1) field that supports date and time calculation. Basically the date is expressed as the number of days since 1899 and the time is divided in fractions.

Regards Steven van Els
SAvanEls@cq-link.sr
 
OK!!! I finally got it to work right!

It only validates if it is in the MM/DD/YYYY format:

procedure TJMSData.qryVenMaintMAILDATEValidate(Sender: TField);
var
CheckDate : TDateTime;
Year, Month, Day : Word;
begin
if Pos('/', Sender.AsString) > 0 Then
begin
CheckDate := StrToDate(Sender.AsString);
DecodeDate(CheckDate, Year, Month, Day);
IsValidDate(Year, Month, Day);
end;
end;

It converts the value to the proper database format
procedure TJMSData.qryVenMaintMAILDATESetText(Sender: TField;
const Text: String);
begin
Sender.Value := convertdate(Text);
end;

It formats the field to display proper MM/DD/YYYY if it's not blank. It was putting // in the field when it was blank!
procedure TJMSData.qryVenMaintMAILDATEGetText(Sender: TField;
var Text: String; DisplayText: Boolean);
begin
if Sender.AsString <> '' then Text := DateFormat(Sender.AsString);
end; Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Thanks Steven,

We are using an AS400 that doesn't have a specified DATE format! We either have to declare it as an integer or string. I have decided to use strings. But see previous post, I got it!!!

la
Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Not really!! I started trying to do this yesterday morning, spent all day on it and finally got it at the end of this morning! But since my Delphi.clue := .05, I feel like I might be getting this stuff! (But only due to the helpful tekkies here!) Thanks for all the info!

Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top