Solved

Case DayOfWeek(Date) of

Posted on 1999-01-07
6
238 Views
Last Modified: 2010-04-06
Why will this not compile under Delhpi 3?  The error is on the first line, Incompatible types, Integer and TDateTime.

Case DayOfWeek(Date) of
2 {Monday} : System.Assign(FileHandle,'Monday.txt');
5 {Thursday} : System.Assign(FileHandle,'Thursday.txt');
else : System.Assign(FileHandle,'others.txt');
end;
0
Comment
Question by:Kapusta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 30 total points
ID: 1355205
On my D4.02 the case line compiles just fine.

However, there is a syntax error, also change date to SYSutils.date to remove any name collision:

Change it to this:

Case DayOfWeek(SysUtils.Date) of
    2 {Monday} : System.Assign(FileHandle,'Monday.txt');
    5 {Thursday} : System.Assign(FileHandle,'Thursday.txt');
    else
   System.Assign(FileHandle,'others.txt');
    end;

This procedure I made from your code sample compiles OK:

procedure test;

var
  FileHandle : TExt;

begin
Case DayOfWeek(SYSUtils.Date) of
    2 {Monday} : System.Assign(FileHandle,'Monday.txt');
    5 {Thursday} : System.Assign(FileHandle,'Thursday.txt');
    else : System.Assign(FileHandle,'others.txt');
    end;
end;

Cheers,

Raymond.
0
 
LVL 3

Expert Comment

by:williams2
ID: 1355206
I'm not sure, though this example compiles fine:

procedure TForm1.FormCreate(Sender: TObject);
var
  S: String;
  F: File;
begin
  Case DayOfWeek(Date) of
    1 {Sunday}   : S:='Sunday.txt';
    2 {Monday}   : S:='Monday.txt';
    3 {Tuesday}  : S:='Tueday.txt';
    4 {Wednsday} : S:='Wednsday.txt';
    5 {Thursday} : S:='Thursday.txt';
    6 {Friday}   : S:='Friday.txt';
    7 {Saturday} : S:='Saturday.txt';
    else
                   S:='Else';
  end;
  System.Assign(F,S);
end;

If this doesn't help, try to say where your problem occurs.

But you could event though try to replace the case sentence with:
  Case DayOfWeek(TDateTime(Date)) of

(It might also be an error, where you previously declared a 'Date' variable as an Integer overriding the system Date function.)

Regards,
Williams
0
 

Author Comment

by:Kapusta
ID: 1355207
>>However, there is a syntax error, also change date to SYSutils.date
>> to remove any name collision:
>>    Change it to this:
>>    Case DayOfWeek(SysUtils.Date) of

Your solution did not work.  Same problem...  However, you did get my brain juices flowing, and I did discover that the following DOES work...

    Case SysUtils.DayOfWeek(SysUtils.Date) of

thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:williams2
ID: 1355208
Hmm... Raymond, sometimes it surprices me how fast you are hehehe

:-)
0
 

Author Comment

by:Kapusta
ID: 1355209
Thanks to Williams too!  You guys (gals?) are great.


0
 
LVL 3

Expert Comment

by:williams2
ID: 1355210
That's alright, another time ?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 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