Solved

Case DayOfWeek(Date) of

Posted on 1999-01-07
6
231 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Virtualstringtree carsh after invalidate for while 5 86
Printing problem 2 80
Convert MS Word document to a PDF file 9 63
Graphics32 under Delphi 10.1 Berlin 2 37
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now