小弟有一段代码无法通过编译,不知问题出在哪里,请各位大虾指教。(10分)

  • 主题发起人 ~风之彼端~
  • 开始时间

~风之彼端~

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟有一段代码无法通过编译,不知问题出在哪里,请各位大虾指教。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons;
type
TDaysOfWeekArray=(wMonday,wTuesday,wWednesday,wThursday,wFriday,wSaturday,wSunday);

TDaysOfWeek=set of TDaysOfWeekArray;

......................


function WordToWeek(const W:Integer):TDaysOfWeekArray;//这个函数无法通过编译

function WeekToWord(const W:TDaysOfWeekArray):Word;//这个函数却没有问题

implementation

function WordToWeek(const W:Integer):TDaysOfWeekArray;
const
TResultWeek:array [1..7] of TDaysOfWeekArray = (wMonday,wTuesday,
wWednesday,wThursday,wFriday,wSaturday,wSunday);
begin
if W<1 then
Result:=1
else if W>7 then
Result:=7
else
Result:=TResultWeek[W];
{之所以像这些写这段代码,是因为想提高代码的效率,同时使得代码尽可能
地简洁,所以没有在这里用case之类的语句}
end;

function WeekToWord(const W:TDaysOfWeekArray):Word;
const
TResultWeek:array [wMonday..wSunday] of Word = (1,2,3,4,5,6,7);
begin
Result:=TResultWeek[W];
{和上面代码的写法一致,因为希望简洁有效率}
end;

Delphi无法编译通过函数WordToWeek,点击F9键运行时会弹出一个错误对话框,
对话框内容如下:

Access violation at address 00B04D3C in module 'DCC60.DLL'. Read
of address FFFFFFFF.

如果不是点击F9运行,而是点击Build命令的话,Delphi无法通过编译,返回下面
一个编译错误:

[Fatal Error] Unit1.pas(68): Internal error: U2951

查看帮助后得到下面这些英文信息:

Internal error: <element><name>

List of compiler error messages
_______________________________________________________________________

Occasionally when compiling an application in Delphi, the compile will halt
and display an error message that reads, for example:

Internal Error: X1234

This error message indicates that the compiler has encountered a condition,
other than a syntax error, that it cannot successfully process.

The information after "Internal Error" contains from one to three characters
and is immediately followed by a number that indicates the file and line number
in the compiler itself where the error occurred. Although this information may
not help you, it can help us (Borland) track down the problem if and when you
report the error. Be sure to jot down this information and include it with your
internal error description.

What to do if you encounter an internal error

Follow these steps to attempt to resolve an internal error:

1. If the error occurs immediately after you have modified code in the editor,
go back to the place where you made your changes and make a note of what was
changed.
2. If you can undo or comment out the change and then recompile your application
successfully, it is possible that the programming construct that you introduced
exposed a problem with the compiler. If so, skip to step 7.

Otherwise, follow the next few steps to resolve your problem.

1. Delete all of the .dcu or .dpu files associated with your project.

2. Close your project completely using File | Close All, then reopen your project,
this will clear the unit cache maintained in the IDE. Alternatively you can
simply close the IDE and restart.
3. Another options is to try and recompile your application using the Project|Build
option so that the compiler will regenerate all of your dcus or dpus.
4. If the error is still present exit the IDE and try to compile your application
using the command line version of the compiler (dcc32.exe) from a command
prompt. This will remove the unit caching of the IDE from the picture and could
help to resolve the problem.

If the problem still exists, go back to the place where you last made modifications to
your file and review the code.

Typically, most internal errors can be reproduced with only a few lines of code and
frequently the code involves syntax or constructs that are rather unusual or unexpected.
If this is the case, try modifying the code to do the same thing in a different way.
For example, if you are typecasting a value, try declaring a variable of the cast type
and do an assignment first.

Examples

begin

if Integer(b) = 100 then...
end;
var
a: Integer;
begin
a := b;
if a = 100 then...
end;

Here is an example of unexpected code that you can correct to resolve the error:

var

A : Integer;
begin
if Int64(Int64(A))=0 then
end;

In this case, the second cast of A to an Int64 is unnecessary and removing it corrects the
error.

If the problem seems to be a "while...do" loop, try using a "for...do" loop instead.
Although this does not actually solve the problem, it may help you to continue work
on your application. If this resolves the problem, it does not mean that either "while"
loops or "for" loops are broken but more likely it means that the manner in which you
wrote your code was unexpected.

Once you have identified the problem, we ask that you create the smallest possible
test case that still reproduces the error and submit it to Borland.

请问各位尊敬的大虾:有解决问题的方法吗?为什么这段代码不能通过编译?小弟分数不多,
但是等我有分了一定补上,决不食言!
 
你用的D6吗,升级一下补丁.
 
Delphi7能解决问题吗?
 
Delphi 7 也有bug,不过delphi 6刚发行那个版本问题比较严重。
最好升级到 Update Pack 2
 
哪里有下载的?
 
http://xuhao23.myetang.com/bd/
 
您给的页面打不开!
 
可能你真是应该象上面说的打个补丁吧
我的是可以通过的
 
谢谢xeen大哥:我想确实是Delphi的问题,因为Delphi7可以通过编译。先给您加分,以后我
有分了再给您加。谢谢!
 
顶部