Solved

Case DayOfWeek(Date) of

Posted on 1999-01-07
6
233 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Open a URL with Internet Explorer in a new tab (not a new window) 1 92
Reconfigure Delphi Install? 2 51
Performance of SQL statement 37 111
Delphi Yen format 3 34
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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