variant的困惑 (50分)

  • 主题发起人 主题发起人 coolrain
  • 开始时间 开始时间
C

coolrain

Unregistered / Unconfirmed
GUEST, unregistred user!
一段程序,不知是何故,编译能通过,运行时总是出现 cpu的调试窗口。
求大家帮我看看。
是一个计算优化变体数组时间的程序。
unit Unit1;

interface

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


type
TintArray=Array[1..1000000] of integer;
PIntArray=^TIntArray;

type
TForm1 = class(TForm)
UnLkTm: TEdit;
LkTm: TEdit;
AryBound: TEdit;
Button1: TButton;
StsBar: TStatusBar;
ArrayNum: TLabel;
UnlockTime: TLabel;
LockTime: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
FVarintCount:integer;
FvarAry:variant;
{ Private declarations }
public
function CountWriteTime(Avalue:PIntArray):dword;
end;


var
Form1: TForm1;
PVarAry:PIntArray;
implementation

{$R *.DFM}

{ TForm1 }



function TForm1.CountWriteTime(Avalue: PIntArray): dword;
var Index:integer;
T1,T2:Dword;
begin
T1:=GetTickCount;
for Index:=0 to FvarintCount do
begin
Avalue^[Index]:=Index;
end;
T2:=GetTickCount;
Result:=T2-T1;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
try
FvarintCount:=StrToInt(AryBound.Text);
except
StsBar.SimpleText:='conver error!';
exit;
end;
FvarAry:=VarArrayCreate([0,FvarintCount],varinteger);
try
PVarAry:=varArrayLock(FvarAry);
LkTm.Text:=FloatToStr(CountWriteTime(PvarAry));
finally
varArrayUnlock(FvarAry);
VarClear(FvarAry);
end;

end;
end.
 
无解,这种情况经常碰到。
Tools->Debugger options->Integrated debugging钩去掉。
 
procedure TForm1.Button1Click(Sender: TObject);
begin
....
---> FvarAry:=VarArrayCreate([0,FvarintCount],varinteger);
....
end;

function TForm1.CountWriteTime(Avalue: PIntArray): dword;
var Index:integer;
T1,T2:Dword;
begin
T1:=GetTickCount;
---> for Index:=0 to FvarintCount do
应该为for index := 0 to fvarintcount-1 do
begin
Avalue^[Index]:=Index;
end;
 
后退
顶部