Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

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
Avatar of rfwoolf
rfwoolf
Flag of South Africa image

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
Avatar of Peter Kiers

ASKER

What should I fill in this procedure:

procedure TMainForm.ClientDataSet1CalcFields(DataSet: TDataSet);
begin
//
end;

p.
Uses
  Dateutils;

Something like clientdataset1.fieldbyname('MyCalculatedField').asstring := DayOfTheWeek(clientdataset1.fieldbyname('Date').asdate);
Undeclared identifier: asdate

p.
Try asdatetime
i have this:
clientdataset1.fieldbyname('Day').asstring := DayOfTheWeek(clientdataset1.fieldbyname('Day').asdatetime);

but get Incompatible Types: string and word

p.
Your right is Day and ur left is Day, make the right one Date
clientdataset1.fieldbyname('Day').asstring := DayOfTheWeek(clientdataset1.fieldbyname('Date').asdatetime);

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
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;

Open in new window

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
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'?
I only see the column Day because I have created it, but it stays empy.
I think i maid work when the column Day is created dynamicly.
Peter
ASKER CERTIFIED SOLUTION
Avatar of rfwoolf
rfwoolf
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oke, thanks for te tips.
500 points are comming to you...

greetings,Peter Kiers