第一次在Delphi里面写过程,不知道带数组参数的过程如何写,详细如下:
================================================================
unit Unit9;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm9 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
Memo1: TMemo;
Label2: TLabel;
Label3: TLabel;
BtnClear: TButton;
Button1: TButton;
Button2: TButton;
procedure InitItems(var arr1: array);//运行的时候这里出错!
procedure FormCreate(Sender: TObject);
procedure BtnClearClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form9: TForm9;
MyArray: array[0..25] of Char;implementation{$R *.DFM}procedure InitItmes(var arr1:array);
var
i,j: Integer;
begin
for i := 0 to High(arr1) do
begin
j := i + 97;
arr1[i] := Chr(j);
end;
end;
================================================================运行的时候程序一直弹出Error对话框,提示在出错行有这样的错误: Expected OF but ')' found到底是怎么回事呢?
================================================================
unit Unit9;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm9 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
Memo1: TMemo;
Label2: TLabel;
Label3: TLabel;
BtnClear: TButton;
Button1: TButton;
Button2: TButton;
procedure InitItems(var arr1: array);//运行的时候这里出错!
procedure FormCreate(Sender: TObject);
procedure BtnClearClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form9: TForm9;
MyArray: array[0..25] of Char;implementation{$R *.DFM}procedure InitItmes(var arr1:array);
var
i,j: Integer;
begin
for i := 0 to High(arr1) do
begin
j := i + 97;
arr1[i] := Chr(j);
end;
end;
================================================================运行的时候程序一直弹出Error对话框,提示在出错行有这样的错误: Expected OF but ')' found到底是怎么回事呢?
解决方案 »
- BDE Administrator 5.2.0.2
- 关于dbcombobox与sql2000数据表中的某个字段连接的问题
- 如何安装DevExpress
- 自己做了一个控件,后来又加了一个只读属性,却在面板上没有显示,怎么回事啊?请大家帮忙,多谢!!!
- 怎么判断一个字符串是否在一个stringlist里面????
- 虽然没有分,大家还是看看,急啊!!!
- 谁有这样的例子,我给500分
- 怎么样用进程ID直接杀死进程?
- 关于引号的用法!
- 困扰已久的数据库问题
- 请问大家用什么制作 帮助文件啊 要支持中文的 能告诉我哪里有下载吗???
- 请问,如何在一个bmp图形中查找是否有$FFFFFF颜色呢,请问用什么算法来查找呢?请帮助.
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm9 = class(TForm)
ListBox1: TListBox;
Memo1: TMemo;
Label2: TLabel;
Label3: TLabel;
BtnClear: TButton;
Button2: TButton;
Button1: TButton;
Button3: TButton;
TMyArray = array [0..255] of Char;//该行出错
procedure InitItems(var arr1: TMyArray);
procedure FormCreate(Sender: TObject);
procedure BtnClearClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form9: TForm9;
MyArray: array[0..25] of Char;implementation{$R *.DFM}procedure InitItmes(var arr1:TMyArray);
var
i,j: Integer;
begin
for i := 0 to High(arr1) do
begin
j := i + 97;
arr1[i] := Chr(j);
end;
end;
procedure TForm9.FormCreate(Sender: TObject);
var
i,j: Integer;
begin
for i := 0 to High(MyArray) do
begin
j := i + 97; //ASCII 'a' = #97
MyArray[i] := Chr(j);
//ListBox1.Items[i] := MyArray[i];
end;
ListBox1.MultiSelect := True;
end;procedure TForm9.BtnClearClick(Sender: TObject);
begin
ListBox1.Clear;
end;procedure TForm9.Button2Click(Sender: TObject);
var
i :Integer;
begin
self.InitItems(MyArray);
for i := 0 to High(MyArray) do
ListBox1.Items.Strings[i] := MyArray[i];
end;=======================================================
我修改了程序之后,可是又出现错误了:Expected ':' but '=' found,为什么呢?
改为:procedure InitItems(var arr:array of char) 即可。如果你要用restboy(枫) ( )的方法,你需要将TMyArray = array [0..255] of Char;写在Type之后(你代码中第9行那个Type)。
================================================================
unit Unit9;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm9 = class(TForm)
ListBox1: TListBox;
Memo1: TMemo;
Label2: TLabel;
Label3: TLabel;
BtnClear: TButton;
Button2: TButton;
Button1: TButton;
Button3: TButton;
procedure InitItems(var arr1:array of Char);//Error!
procedure FormCreate(Sender: TObject);
procedure BtnClearClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form9: TForm9;
MyArray: array[0..25] of Char;implementation{$R *.DFM}procedure InitItmes(var arr1:array of Char);
var
i,j: Integer;
begin
for i := 0 to High(arr1) do
begin
j := i + 97;
arr1[i] := Chr(j);
end;
end;
procedure TForm9.FormCreate(Sender: TObject);
var
i,j: Integer;
begin
for i := 0 to High(MyArray) do
begin
j := i + 97; //ASCII 'a' = #97
MyArray[i] := Chr(j);//如果使用类型TMyArray,则在此会出现类型转换不了
ListBox1.Items[i] := MyArray[i];
end;
ListBox1.MultiSelect := True;
end;procedure TForm9.BtnClearClick(Sender: TObject);
begin
ListBox1.Clear;
end;procedure TForm9.Button2Click(Sender: TObject);
var
i :Integer;
begin
self.InitItems(MyArray);
for i := 0 to High(MyArray) do
ListBox1.Items.Strings[i] := MyArray[i];
end;procedure TForm9.Button3Click(Sender: TObject);
begin
ListBox1.MultiSelect := True;
end;procedure TForm9.Button1Click(Sender: TObject);
begin
//
end;end.
==============================================================
为何还会出现这样的错误呢?到底出了什么问题,请高手继续解答