...
type
tagPointMes=record
x,y,r:shortint;
typ_e :integer;
end;
tagRadialLineMes=record
n120,n240,n480:integer;
pPMes:^tagPointMes;
end;
const numcount = 360;
const pi = 3.1415927;
var
SA0010 : TSA0010;
LineMes: array[0..numcount] of tagRadialLineMes;
pAllPointMes,pCur :^tagPointMes;procedure TSA0010.CacuSinCos;
var
seta,i,xx,yy,idx,j,LinePointNum,jj:integer;
x,y,r,TotalPointNum:Integer;
p120 : Array [0..300] of ^tagPointMes;//如果写成【0..300*numcount】就会出现Stack overflow
p240 : Array [0..800] of ^tagPointMes;
p480 : Array [0..4000] of ^tagPointMes;
begin
TotalPointNum:=0;
for x:=0 to numcount do begin
LineMes[i].n120:=0;
LineMes[i].n240:=0;
LineMes[i].n480:=0;
end;
.............. 这样会提示出错信息,提示说非法地址访问。。盼早回音!!
type
tagPointMes=record
x,y,r:shortint;
typ_e :integer;
end;
tagRadialLineMes=record
n120,n240,n480:integer;
pPMes:^tagPointMes;
end;
const numcount = 360;
const pi = 3.1415927;
var
SA0010 : TSA0010;
LineMes: array[0..numcount] of tagRadialLineMes;
pAllPointMes,pCur :^tagPointMes;procedure TSA0010.CacuSinCos;
var
seta,i,xx,yy,idx,j,LinePointNum,jj:integer;
x,y,r,TotalPointNum:Integer;
p120 : Array [0..300] of ^tagPointMes;//如果写成【0..300*numcount】就会出现Stack overflow
p240 : Array [0..800] of ^tagPointMes;
p480 : Array [0..4000] of ^tagPointMes;
begin
TotalPointNum:=0;
for x:=0 to numcount do begin
LineMes[i].n120:=0;
LineMes[i].n240:=0;
LineMes[i].n480:=0;
end;
.............. 这样会提示出错信息,提示说非法地址访问。。盼早回音!!
但是从理论上考虑应该不是这么回事,因为delphi的数组规定,array[indexTye1,...indexTypen] of baseType中每个IndexType都可以是一个不超过2GB的序数类型,所以你的300*numcount才只有108000,显然离着还远呢。
由于无法运行你的代码,不知道这个错误到底是怎么样的。我只能建议你把数组开的小一些,至少剩内存啊,而且一般大数组都是不建议使用的。
LineMes[i].n120:=0;
LineMes[i].n240:=0;
LineMes[i].n480:=0;
end;=〉 for i:=0 to numcount do begin
LineMes[i].n120:=0;
LineMes[i].n240:=0;
LineMes[i].n480:=0;
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus;type
TSA0010 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Exit1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
New1: TMenuItem;
procedure Exit1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure CacuSinCos;
{ Public declarations }
end;type
tagPointMes=record
x,y,r:shortint;
typ_e :integer;
end;
tagRadialLineMes=record
n120,n240,n480:integer;
pPMes:^tagPointMes;
end;
const numcount = 360;
const pi = 3.1415927;
var
SA0010 : TSA0010;
LineMes: array[0..numcount] of tagRadialLineMes;
pAllPointMes,pCur :^tagPointMes;implementation
uses math;{$R *.DFM}procedure TSA0010.CacuSinCos;
var
seta,i,xx,yy,idx,j,LinePointNum,jj:integer;
x,y,r,TotalPointNum:Integer;
// p120,p240,p480 : ^tagPointMes;
p120 : Array [0..300] of ^tagPointMes;
p240 : Array [0..800] of ^tagPointMes;
p480 : Array [0..4000] of ^tagPointMes;
begin
TotalPointNum:=0;
// GetMem(p120,sizeof(tagPointMes)*300*numcount);
// GetMem(p240,sizeof(tagPointMes)*800*numcount);
// GetMem(p480,sizeof(tagPointMes)*4000*numcount); for x:=0 to numcount do begin
LineMes[i].n120:=0;
LineMes[i].n240:=0;
LineMes[i].n480:=0;
end;
for x:=0 to 480*2-1 do begin
xx:=(x-480)*(x-480);
for y:=0 to 480*2-1 do begin
yy:=(480-y)*(480-y);
seta:=round(ArcTan2(round((x-480.0)),round((480.0-y)))*180/pi);
if(seta<0) then seta:=360+seta;
if(seta>=360) then seta:=0;
r:=round(sqrt(xx+yy));
if(r<480) then begin
inc(TotalPointNum);
if(r>240) then begin
idx:=seta*4000+LineMes[seta].n480;
p480[idx].x := x - 480 ;
p480[idx].y := y - 480 ;
p480[idx].r := r ;
inc(LineMes[seta].n480);
end
else if(r>120) then begin
idx:=seta*800+LineMes[seta].n240;
p240[idx].x := x - 480 ;
p240[idx].y := y - 480 ;
p240[idx].r := r ;
inc(LineMes[seta].n240);
end
else begin
idx:=seta*300+LineMes[seta].n120;
p120[idx].x := x - 480 ;
p120[idx].y := y - 480 ;
p120[idx].r := r ;
inc(LineMes[seta].n120);
end;
end;
end;
end; GetMem(pAllPointMes,sizeof(tagPointMes)*totalpointNum);
pCur := pAllPointMes;
for i:=0 to numcount do begin
j:=0;
LinePointNum:=0;
LineMes[i].pPMes:=@pCur;
for j:=0 to LineMes[i].n120 do begin
jj:=i*300 + j;
pCur.x := p120[jj].x;
pCur.y := p120[jj].y;
pCur.r := p120[jj].r;
inc(pCur);
end; for j:=0 to LineMes[i].n240 do begin
jj:=i*800 + j;
pCur.x := p240[jj].x;
pCur.y := p240[jj].y;
pCur.r := p240[jj].r;
inc(pCur);
end; for j:=0 to LineMes[i].n480 do begin
jj:=i*480 + j;
pCur.x := p480[jj].x;
pCur.y := p480[jj].y;
pCur.r := p480[jj].r;
inc(pCur);
end; LineMes[i].n480 :=LineMes[i].n480 +LineMes[i].n240;
end;
FreeMem(pAllPointMes)
end;procedure TSA0010.Exit1Click(Sender: TObject);
begin
application.terminate;
end;procedure TSA0010.FormCreate(Sender: TObject);
begin
CacuSinCos;
end;end.这是全部源程序///
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus;type
TSA0010 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Exit1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
New1: TMenuItem;
procedure Exit1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure CacuSinCos;
{ Public declarations }
end;type
tagPointMes=record
x,y,r:shortint;
typ_e :integer;
end;
tagRadialLineMes=record
n120,n240,n480:integer;
pPMes:^tagPointMes;
end;
const numcount = 360;
const pi = 3.1415927;
var
SA0010 : TSA0010;
LineMes: array[0..numcount] of tagRadialLineMes;
pAllPointMes,pCur :^tagPointMes;implementation
uses math;{$R *.DFM}procedure TSA0010.CacuSinCos;
var
seta,i,xx,yy,idx,j,LinePointNum,jj:integer;
x,y,r,TotalPointNum:Integer;
p120 : Array [0..300*numcount] of ^tagPointMes;
p240 : Array [0..800*numcount] of ^tagPointMes;
p480 : Array [0..4000*numcount] of ^tagPointMes;
begin
TotalPointNum:=0;
for i:=0 to numcount do begin
LineMes[i].n120:=0;
LineMes[i].n240:=0;
LineMes[i].n480:=0;
end;
for x:=0 to 480*2-1 do begin
xx:=(x-480)*(x-480);
for y:=0 to 480*2-1 do begin
yy:=(480-y)*(480-y);
seta:=round(ArcTan2(round((x-480.0)),round((480.0-y)))*180/pi);
if(seta<0) then seta:=360+seta;
if(seta>=360) then seta:=0;
r:=round(sqrt(xx+yy));
if(r<480) then begin
inc(TotalPointNum);
if(r>240) then begin
idx:=seta*4000+LineMes[seta].n480;
p480[idx].x := x - 480 ;
p480[idx].y := y - 480 ;
p480[idx].r := r ;
inc(LineMes[seta].n480);
end
else if(r>120) then begin
idx:=seta*800+LineMes[seta].n240;
p240[idx].x := x - 480 ;
p240[idx].y := y - 480 ;
p240[idx].r := r ;
inc(LineMes[seta].n240);
end
else begin
idx:=seta*300+LineMes[seta].n120;
p120[idx].x := x - 480 ;
p120[idx].y := y - 480 ;
p120[idx].r := r ;
inc(LineMes[seta].n120);
end;
end;
end;
end; GetMem(pAllPointMes,sizeof(tagPointMes)*totalpointNum);
pCur := pAllPointMes;
for i:=0 to numcount do begin
j:=0;
LinePointNum:=0;
LineMes[i].pPMes:=@pCur;
for j:=0 to LineMes[i].n120 do begin
jj:=i*300 + j;
pCur.x := p120[jj].x;
pCur.y := p120[jj].y;
pCur.r := p120[jj].r;
inc(pCur);
end; for j:=0 to LineMes[i].n240 do begin
jj:=i*800 + j;
pCur.x := p240[jj].x;
pCur.y := p240[jj].y;
pCur.r := p240[jj].r;
inc(pCur);
end; for j:=0 to LineMes[i].n480 do begin
jj:=i*480 + j;
pCur.x := p480[jj].x;
pCur.y := p480[jj].y;
pCur.r := p480[jj].r;
inc(pCur);
end; LineMes[i].n480 :=LineMes[i].n480 +LineMes[i].n240;
end;
FreeMem(pAllPointMes)
end;procedure TSA0010.Exit1Click(Sender: TObject);
begin
application.terminate;
end;procedure TSA0010.FormCreate(Sender: TObject);
begin
CacuSinCos;
end;end.会出现堆栈overflow