Solved

Case DayOfWeek(Date) of

Posted on 1999-01-07
6
237 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

737 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