我是这样定义的函数:
function abc(aa:array of double; i:integer): boolean;
...
result:= true;
...
//aa在函数体内是否还要定义?在调用它的时候我用了
if abc(a[],4) then ......;
其中a[]表示数组a的数,4表示取数组a中的前4个数。可是结果我跟踪一下aa的值根本没有从a中接受,这个函数的形参如果才能正确接受实参的数据。还有一个问题,定义全局变量以下两个位置有什么区别:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
// 位置一
end;var
Form1: TForm1;
// 位置二
function abc(aa:array of double; i:integer): boolean;
...
result:= true;
...
//aa在函数体内是否还要定义?在调用它的时候我用了
if abc(a[],4) then ......;
其中a[]表示数组a的数,4表示取数组a中的前4个数。可是结果我跟踪一下aa的值根本没有从a中接受,这个函数的形参如果才能正确接受实参的数据。还有一个问题,定义全局变量以下两个位置有什么区别:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
// 位置一
end;var
Form1: TForm1;
// 位置二
解决方案 »
- 求帮助,在线急等!!!!!!
- delphi 数据敏感控件的疑问 太敏感了 还是我不会控制
- 使用internet下的webbrowser控件时,提示出错
- Adoquery有象query的cachedupdates的功能吗?
- 如何对日期进行?比如2003-11-1加上3日期就变成2004-2-1了??救命啊
- 网站上有一数据库,我怎么把数据传到本地机器?
- 在delphi中,如何发送键盘指令
- 求助:cxGrid中如何使用行,列索引使指定单元格取得编辑焦点?
- SetWindowLong怎么用?
- Append和Insert的不同(在线等待)
- 小問題~合並記錄怎麼解決~
- 关于DELPHI数据库中,ACCESS数据库的问题?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function abc(aa:array of double; i:integer): boolean;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.abc(aa: array of double; i: integer): boolean;
var j:integer;
begin
for j:=0 to i-1 do
showmessage(floattostr(aa[j]));
end;procedure TForm1.Button1Click(Sender: TObject);
begin
self.abc([0.22,32.211,0.32,0.23,2.100],3);
end;end.
2.aa在函数体内无需定义;
3.可能是因为你在函数体又定义了aa和i这样就取函数体内的而不是你传的参数了;
4.定义全局变量位置一是属于form1的成员;位置二是属于unit1的成员;
而form1也是unit1的
我觉得应该改为:function abc(aa[10]:array of double; i:integer): boolean;
第二个问题:位置一:对于整个程序是公用
位置二:对于单个form是公用
public中的变量是form1的一个公共变量,在外部可以用 form1.变量:=?。
而var则是全局的变量,在外部可以直接用 变量:=?。
FORM1.变量位置二是一个全局变量,在任何引入该单元的单元中都可以用,用的时候直接写 变量名 :=
public中的变量是form1的一个公共变量,在外部可以用 form1.变量:=?。
而var则是全局的变量,在外部可以直接用 变量:=?。
2、abc(a[],4) 改为 abc(a,4)
3、位置一:是TForm1的域,可以通过TForm1的实例引用,如Form1.FieldName
位置二:单元的共有变量,对于本单元内部及引用该单元的单元可用,直接引用或加单元名引用(在重名时)。