Peter Kiers
asked on
Question about dbgrid
Hi,
I have a dataset with data on my form created the following way:
->a DBGrid1 on myform with property DataSource set to DataSource1.
->a DataSource1 with property DataSet set to ClientDataset1
->a ClientDataSet with property ProviderName set to XMLTransformProvider1.
and property Active to True.
->a XMLTransformProvider1 with the property FileName set to a xml-filename.
->and a DBNavigator with the propery DataSource set to DataSource1.
The Dataset has 3 columns:Date,Time,Value
I would like to create a fourth column (called Day) to display the name of the day
that is associated with the column Date. So f.e if a cell in column Date
is 21 june 2010 the cell of the column Day has to give Monday.
Is that possible? Or am I asking the impossible now?
Who knows the answer and is willing to help me?
Greetings,
Peter Kiers
I have a dataset with data on my form created the following way:
->a DBGrid1 on myform with property DataSource set to DataSource1.
->a DataSource1 with property DataSet set to ClientDataset1
->a ClientDataSet with property ProviderName set to XMLTransformProvider1.
and property Active to True.
->a XMLTransformProvider1 with the property FileName set to a xml-filename.
->and a DBNavigator with the propery DataSource set to DataSource1.
The Dataset has 3 columns:Date,Time,Value
I would like to create a fourth column (called Day) to display the name of the day
that is associated with the column Date. So f.e if a cell in column Date
is 21 june 2010 the cell of the column Day has to give Monday.
Is that possible? Or am I asking the impossible now?
Who knows the answer and is willing to help me?
Greetings,
Peter Kiers
Double click ur clientdataset, right cllick and add all fields, right click and add a new calculated field. Then on the clientdatasets oncalculate event, set the value of ur calculated field to the day of the week. Hope this helps
ASKER
What should I fill in this procedure:
procedure TMainForm.ClientDataSet1Ca lcFields(D ataSet: TDataSet);
begin
//
end;
p.
procedure TMainForm.ClientDataSet1Ca
begin
//
end;
p.
Uses
Dateutils;
Something like clientdataset1.fieldbyname ('MyCalcul atedField' ).asstring := DayOfTheWeek(clientdataset 1.fieldbyn ame('Date' ).asdate);
Dateutils;
Something like clientdataset1.fieldbyname
ASKER
Undeclared identifier: asdate
p.
p.
Try asdatetime
ASKER
i have this:
clientdataset1.fieldbyname ('Day').as string := DayOfTheWeek(clientdataset 1.fieldbyn ame('Day') .asdatetim e);
but get Incompatible Types: string and word
p.
clientdataset1.fieldbyname
but get Incompatible Types: string and word
p.
Your right is Day and ur left is Day, make the right one Date
ASKER
clientdataset1.fieldbyname ('Day').as string := DayOfTheWeek(clientdataset 1.fieldbyn ame('Date' ).asdateti me);
Still the error...
p.
Still the error...
p.
It looks like dayoftheweek returns an integer, where 1 is Sunday and 7 is Saturday. You'll need to change the procedure so that if u get 1 put 'Sunday' etc. I can help u further when I get to my pc
ASKER
ok
Okay here we go...
uses
dateutils;
procedure TMainForm.ClientDataSet1CalcFields(DataSet: TDataSet);
const
Days : array[0..6] of string
= ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
begin
clientdataset1.fieldbyname('Day').asstring := Days[DayOfTheWeek(clientdataset1.fieldbyname('Date').asdatetime)];
end;
ASKER
Oke no more error:
But it doesn't work, and I don't know wherer the problem is!!!
It could be the code but it could be somewhere else.
Peter
But it doesn't work, and I don't know wherer the problem is!!!
It could be the code but it could be somewhere else.
Peter
Check that your dbgrid doesn't have persistent fields - by double-clicking on your dbgrid. If it does have persistent fields, make sure you add all fields again so that it includes the Day field
So what do you mean "it doesn't work"? Does it compile? Does it run? Do you see a column called 'Day'?
ASKER
I only see the column Day because I have created it, but it stays empy.
ASKER
I think i maid work when the column Day is created dynamicly.
Peter
Peter
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oke, thanks for te tips.
500 points are comming to you...
greetings,Peter Kiers
500 points are comming to you...
greetings,Peter Kiers