请问为什么I循环?如何改才对?在线等谢了
Cnt:=100with Q1 do
begin
sql.Clear;
SQL.Add('Select * from AA ');
Open;
while not eof do
begin
for I:=0 to Cnt-1 do
begin
point[I].X:=FieldValues['字段1'];
point[I].Y:=FieldValues['字段2'];
end;
next;
end;
polybezier(h,point,Cnt); end;
with Q1 do
begin
sql.Clear;
SQL.Add('Select * from AA ');
Open;
while not eof do
begin
for I:=0 to Cnt-1 do
begin
point[I].X:=FieldValues['字段1'];
point[I].Y:=FieldValues['字段2'];
end;
polybezier(h,point,Cnt); //----- next;
end;
// polybezier(h,point,Cnt); end;
type
TLinesForm = class(TForm)
Button1: TButton;
StatusBar1: TStatusBar;
Button2: TButton;
Conn: TADOConnection;
Q1: TADOQuery;
Ds_Q1: TDataSource;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
LinesForm: TLinesForm;implementation{$R *.dfm}//取得SQL返回语句
function GetSQL(ColStr:String;SqlStr:String):String ;
begin
Result:='';
with LinesForm.Q1 do
begin
SQL.Clear;
SQL.Add(SqlStr);
Open;
If RecordCount>0 then
Result:=VarToStr(FieldValues[ColStr])
else
Result:='';
end;
end;procedure TLinesForm.Button1Click(Sender: TObject);
var
point:array[0..6] of Tpoint;
h:HDC;
I:Integer;
Cnt:Integer;
begin
h:=getdc(LinesForm.handle);
{point[0].x:=25; point[0].y:=25;
point[1].x:=35; point[1].y:=170;
point[2].x:=130;point[2].y:=120;
point[3].x:=150;point[3].y:=150;
point[4].x:=170;point[4].y:=280;
point[5].x:=250;point[5].y:=115;
point[6].x:=250;point[6].y:=225;}
Cnt:=StrToInt(GetSQL('Cnt','Select Count(*)as Cnt from AA')); with Q1 do
begin
sql.Clear;
SQL.Add('Select * from AA ');
Open;
while not eof do
begin
for I:=0 to Cnt-1 do
begin
point[I].X:=FieldValues['字段1'];
point[I].Y:=FieldValues['字段2'];
end;
polybezier(h,point,Cnt); //----- next;
end;
end;
end;
那就不需要用FOR循环了,还有就是你的POINT的声明有问题了应该是一个动态的var
point:array of Tpoint; //<-----------------------------
h:HDC;
I:Integer;
Cnt:Integer;
begin
h:=getdc(LinesForm.handle);
{point[0].x:=25; point[0].y:=25;
point[1].x:=35; point[1].y:=170;
point[2].x:=130;point[2].y:=120;
point[3].x:=150;point[3].y:=150;
point[4].x:=170;point[4].y:=280;
point[5].x:=250;point[5].y:=115;
point[6].x:=250;point[6].y:=225;}
Cnt:=StrToInt(GetSQL('Cnt','Select Count(*)as Cnt from AA'));
setlength(point,Cnt);
i := 0;
with Q1 do
begin
sql.Clear;
SQL.Add('Select * from AA ');
Open;
while not eof do
begin
point[I].X:=FieldValues['字段1'];
point[I].Y:=FieldValues['字段2'];
inc(i) //<-----------------------------------
next;
end;
polybezier(h,point,Cnt);
end;
end;
同时为了可以正常释放应该使用
setlength(point,cnt)
try
....finally
setlength(point,0);
end;
出现了access violation at 0x000000b7:read of address 0x000000b7.Stopped.Use Step or Run to Continue.的错误。
--------------------------------------------------------------------------
procedure TLinesForm.Button1Click(Sender: TObject);
var
point:array[0..6] of Tpoint;
h:HDC;
I,J:Integer;
Cnt:Integer;
begin
h:=getdc(LinesForm.handle);
i := 0;
with Q1 do
begin
sql.Clear;
SQL.Add('Select * from AA ');
Open;
while not eof do
begin
point[I].X:=FieldValues['字段1'];
point[I].Y:=FieldValues['字段2'];
inc(i); //
polybezier(h,point,RecordCount);
next;
end;
end;procedure TLinesForm.FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
var
P:TPoint;
h:HDC;
begin
h:=getdc(LinesForm.handle);
GetCursorPos(p); //获取屏幕的坐标
Windows.ScreenToClient(h,p); //转成窗口的坐标,h是窗口句柄
StatusBar1.Panels[0].Text:='X:='+IntToStr(P.X)+' '+'Y:='+IntToStr(P.Y);
end;end.
begin
h:=getdc(LinesForm.handle);
i := 0;
with Q1 do
begin
sql.Clear;
SQL.Add('Select * from AA ');
Open;
while not eof do
begin
point[I].X:=FieldValues['字段1']; //<-----------你要判断i是不是大于6啊
point[I].Y:=FieldValues['字段2'];
inc(i); //
polybezier(h,point,RecordCount);
next;
end;
end;你不判断,如果i >6 那point[7]是肯定要出错了啊.