为什么函数防回0(Function中动态数组的使用问题)?(100分)

  • 主题发起人 主题发起人 redweek
  • 开始时间 开始时间
R

redweek

Unregistered / Unconfirmed
GUEST, unregistred user!
下面的Function总是防回0,为什么?<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; Function IntToBCD(TT:integer;hh:array of byte):integer;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>FUnction TForm1.IntToBCD(TT:integer;hh:array of byte):integer;<br>&nbsp; var<br>&nbsp; &nbsp; &nbsp;STemp:array[0..3]of byte;<br>&nbsp; &nbsp; // hh:array[0..1]of byte;<br>&nbsp; &nbsp; &nbsp;i:integer;<br>begin<br>&nbsp; &nbsp; for I:=0 to 3 do<br>&nbsp; &nbsp; &nbsp; &nbsp;STemp:=0;<br>&nbsp; &nbsp; STemp[0]:=trunc(tt/1000);<br>&nbsp; &nbsp; STemp[1]:=trunc((TT-STemp[0]*10000)/100);<br>&nbsp; &nbsp; STemp[2]:=Trunc((TT-STemp[0]*1000-STemp[1]*100)/10);<br>&nbsp; &nbsp; STemp[3]:=TT mod 10 ;<br>&nbsp; &nbsp; hh[0]:=STemp[0]*16+STemp[1];<br>&nbsp; &nbsp; hh[1]:=STemp[2]*16+STemp[3];<br><br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>&nbsp; var<br>&nbsp; &nbsp; dd:array[0..1] of byte;<br>begin<br>&nbsp; IntToBCD(1234,dd);<br>&nbsp; edit1.text:=inttostr(dd[0])+inttostr(dd[1]);<br>end;<br><br>end.<br>
 
函数IntToBCD的参数hh要用动态参数:<br><br>FUnction TForm1.IntToBCD(TT:integer; var hh:array of byte):integer;
 
飞龙在天先来。<br><br>另,我还有点疑惑,既然IntToBCD你没有给返回值(result)赋值,为什么不用procedure?
 
IntToBCD(TT:integer;hh:array of byte):integer;<br><br>&nbsp; IntToBCD(1234,dd);//这句有输出吗?<br>ainteger:= &nbsp;IntToBCD(1234,dd);<br>function有问题吧?<br>&nbsp; <br>
 
同意兩位飞龙在天,sonie !<br>參數隻有為變參時才會返回其值!也就是要定義 var的<br>否則和一般參數一樣!<br>
 
你的function 根本就没有 返回值<br>你的 result &nbsp;=???
 
最后加上 Result:=.. &nbsp;;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
718
import
I
I
回复
0
查看
687
import
I
后退
顶部