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!

System's time, date for Delphi

Status
Not open for further replies.

beginner81

Programmer
Oct 27, 2003
44
MY
I'm currently doing a project.. and the project consists of 5 form, which is fmUS, fmJapan, fmKorea, fmEngland, fmAustralia ... so now i need to post a value to the Database.. the value is depends on which form is currently shown.. for example, if the form that i'm currently using is fmUS, i'll post the value "US" to the table.. so how am i going to do this ?? I'd try

If Tform.Name:= fmUs then
xxx // Post value "US" to the table
else if ....
else if.....

the code is not working and cos error anyway.. what wrong wif it ??


Another question here.. once the users click at "OK" button.. i need to save the current time and current date to the database server.. how am i going to do this then ?? P/S : I'd assign types String for both date and time in database server... since it only need to show to the users the value..

Ur help is appreciated.. thx in advance..
 
1) I assume you are performing this operation from inside one of the 5 forms, in which case you can do

if self.name = fmUS then

or

if self is TFmUS then

or

Table1.FieldByName('FormNameFieldName').AsString := Copy(self.name,3,length(self.name) - 2);



2) Check help on FormatDateTime if any of the below formats are incorrect, I don't have delphi open right now.)

Table1.edit;
Table1.FieldByName('DateFieldName').AsString := FormatDateTime('mm/dd/yyyy',now);
Table1.FieldByName('TimeFieldName').AsString :=
FormatDateTime('hh:nn:ss.zzz',now);
Table1.post;


Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
No.. Instead of performing this operation from inside one of the 5 forms, i'm performing this operation on a DataModule, so every form can use this method/procedure.. so how am i goin to do then??
 
why not add a new parameter to the procedure that does the database insertion, that specifies the value you need?

procedure addToDB(country : string);

then use country as the value for the field that depends on the form the user clicks the button.
 
Does the initial call come from the form? If so, you can make TForm a parameter for the function and handle it that way:

function PostFormData(AForm:TForm);
begin
Table1.FieldByName('FormNameFieldName').AsString := Copy(AForm.name,3,length(AForm.name) - 2);
end;

If the call does not emanate from the form, how/when do you instantiate your forms? Do you need a function to find the active form? If so, you can loop through application.components to find the form. You could also use a variable in your datamodule to indicate which form is active, and set the variable in the onactivate event for the form.



Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top