动态数组的数组名的判断,怎么做?
有很多个动态数组,存了不同的值,每个数组要单独处理平均值。我特别做了一个函数,函数传递 动态数组,及当前值。
函数进入后,首先判断是哪个动态数组 传进来了
function smoothdata(myarray:array of Integer;mydat:Integer):Integer;
var
i,sum:Integer;
begin
if myarray=DataMForm.wd_l then begin //这里出错。datamform.wd_l是定义在数据模块的 动态数组
if DataMForm.wd_l_i>=DataMForm.AVGMAXLEN then
请高手看看
[解决办法]
数组不能这么判吧,你在函数里再加个参数,用于区分各个数组吧。
[解决办法]
请另加一个参数来判断数组
[解决办法]
你参数给指针不就行了
判断指针所指地址是那个数组的首地址
[解决办法]
- Delphi(Pascal) code
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button3Click(Sender: TObject); private F1: array[0..11] of Integer; F2: array[0..22] of Integer; public procedure test(const myarray: array of Integer); end;var Form1: TForm1;implementationconst S1: array[0..1] of Integer = (0, 1); S2: array[0..2] of Integer = (0, 1, 2);{$R *.dfm}procedure TForm1.test(const myarray: array of Integer);begin if @myarray = @F1 then ShowMessage('F1') else if @myarray = @F2 then ShowMessage('F2') else if @myarray = @S1 then ShowMessage('s1') else if @myarray = @S2 then ShowMessage('S2');end;procedure TForm1.Button1Click(Sender: TObject);begin test(F1);end;procedure TForm1.Button2Click(Sender: TObject);begin test(F2);end;procedure TForm1.Button4Click(Sender: TObject);begin test(S2)end;procedure TForm1.Button3Click(Sender: TObject);begin test(S1)end;end.
[解决办法]
按着上面的方法你再试试!
[解决办法]
通过设置动态数组的名称,来区别数组不好行吗?