大家帮我看看这个问题,编译老说array type required,谢谢!

Csharp 2004-03-28 08:22:26
大家帮我看看这个问题,
编译老说array type required,谢谢!

unit Umain;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Grids;

const Country_Num=20;


type
TColor=array[1..Country_Num] of 0..4;
TForm_Main = class(TForm)
btn_OK: TButton;
stg_Main: TStringGrid;
Label1: TLabel;
Edit_Num: TEdit;
RichEdit_Result: TRichEdit;
procedure Edit_NumChange(Sender: TObject);
procedure btn_OKClick(Sender: TObject);
private
procedure a_try(i:integer);
function proved(i,j:integer):boolean;
procedure print;
{ Private declarations }
public
{ Public declarations }
end;



var

Form_Main: TForm_Main;
Color:Tcolor;
Country_Num_Input:Integer;

implementation

{$R *.dfm}

var
Relation:array[1..Country_Num,1..Country_Num] of 0..1;



procedure TForm_Main.Edit_NumChange(Sender: TObject);
begin
try
stg_main.RowCount:=strtoint(Edit_Num.Text);
stg_main.ColCount:=strtoint(Edit_Num.Text);
except
on EConvertError do
messagebox(handle,'国家数要是整数','提示',MB_OK);
end;
end;

procedure TForm_Main.btn_OKClick(Sender: TObject);
var
Country1,Country2:integer;
begin
Country_Num_Input:=strtoint(Edit_Num.Text);
for Country1:=1 to Country_Num_Input do
begin
for Country2:=1 to Country_Num_Input
do Relation[Country1,Country2]:=strtoint(stg_Main.Cells[Country1,Country2]);
end;
for Country1:=1 to Country_Num_Input do
Color[Country1]:=0;//这里array type required
a_try(1);
end;

procedure TForm_Main.a_try(i: integer);
var
j:integer;
begin
for j:=1 to 4 do
begin
if proved(i,j) then
begin
Color[i]:=j;;//这里array type required
if i=Country_Num_Input then
print
else
a_try(i+1);
Color[i]:=0;;//这里array type required
end;
end;
end;

function TForm_Main.proved(i, j: integer): boolean;
var
k:integer;
begin
for k:=1 to i-1 do
if (Relation[i,k]=1) and (j=Color[k]) then;//这里array type required
begin
Result:=false;
exit;
end;
Result:=true;
end;

procedure TForm_Main.print;
var
k:integer;
s:string;
begin
s:='';
for k:=1 to Country_Num_Input do
begin
case Color[k] of;//这里array type required
1:s:=s+'R ';
2:s:=s+'B ';
3:s:=s+'W ';
4:s:=s+'Y ';
end;
end;
RichEdit_Result.Lines.Append(s);
end;

end.
...全文
171 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
cll007 2004-04-07
  • 打赏
  • 举报
回复
TColor=array[1..Country_Num] of 0..4; //与Graphics里面的TColor冲突
//TColor改成 TMyColor
-------
var

Form_Main: TForm_Main;
Color:Tcolor; //Color改成 MyColor ,与Self.Color冲突

Country_Num_Input:Integer;
xz1980 2004-04-07
  • 打赏
  • 举报
回复
Type
TSetColor = Set of 0..1;


.
.
.
var
Relation:array[1..Country_Num,1..Country_Num] of TSetColor;

定义数组世需要类型标识的。
把0..1定义了就可以
welllove88 2004-04-03
  • 打赏
  • 举报
回复
不能那么定义!你Relation:array[1..4] of 0..4这样不行

如果你想限制数组内的内容,你可以定义一个只有0..4的类型

不能这么直接用,再说你的这个TColor是不是有和系统的类重名的嫌疑?
lance 2004-04-03
  • 打赏
  • 举报
回复
由于color定义为TColor,而i定义为integer
所以 color[1]:=i 会出错。
w78z 2004-03-30
  • 打赏
  • 举报
回复
定义数组的格式是:
<数组名>:arrary[启始值..最终值] of 数组类型;

所以,上面的就应该是
Relation:array[1..4] of integer;
sxy_9761 2004-03-29
  • 打赏
  • 举报
回复
pazee(耙子)的意思是:
TColor=array[1..Country_Num] of Integer;
Relation:array[1..Country_Num,1..Country_Num] of Integer
耙子 2004-03-28
  • 打赏
  • 举报
回复
楼主没用过Delphi吧?

编译报错应该提示你行号,你该能看到。

前面的一个改了,你就不能把后面的也改了?


Relation:array[1..Country_Num,1..Country_Num] of 0..1;
SydPink 2004-03-28
  • 打赏
  • 举报
回复
var

Form_Main: TForm_Main;
Color:Tcolor;//这个TColor 和Graphics 单元的TColor 编译器知道是哪个TColor ??
Country_Num_Input:Integer;
Csharp 2004-03-28
  • 打赏
  • 举报
回复
改成integer还是那个错,
不是这个原因
耙子 2004-03-28
  • 打赏
  • 举报
回复
TColor=array[1..Country_Num] of Integer;
耙子 2004-03-28
  • 打赏
  • 举报
回复
TColor=array[1..Country_Num] of 0..4;
~~~~

哪有这么写的

通常后面要写数据类型

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧