Solved

Case DayOfWeek(Date) of

Posted on 1999-01-07
6
229 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

19 Experts available now in Live!

Get 1:1 Help Now