错误对话框具体内容为
"Project CrackMe.exe raised exception class EAccessViolation with message 'Accessviolation at address 00454648 in module 'CrackMe.exe'. Read of address 0000004C'. Process stopped. Ues Step or Run to continue."以下是代码,
unit UntCrackMe;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;type
TForm1 = class(TForm)
Panel1: TPanel;
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
Button3: TButton;
Label2: TLabel;
SpeedButton1: TSpeedButton;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
function InRegionNo(x,y:Integer):integer;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
Rec: array[1..128] of Integer;
i: integer;
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
j:integer;
begin
Edit1.Enabled := False;
Button1.Enabled := False;
Edit1.Text := '';
i:=0;
for j:=0 to 127 do Rec[j] := 0;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
Close;
end;procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if SpeedButton1.Down then
begin
Canvas.Pen.Mode := pmNot;
Canvas.moveto(0,round(Form1.Height/3));
Canvas.lineto(Form1.Width,round(Form1.Height/3));
Canvas.MoveTo(0,round(Form1.Height/3*2));
Canvas.LineTo(Form1.Width,round(Form1.Height/3*2));
Canvas.MoveTo(round((Form1.Width-Panel1.Width)/3),0);
Canvas.LineTo(round((Form1.Width-Panel1.Width)/3),Form1.Height);
Canvas.MoveTo(round((Form1.Width-Panel1.Width)/3*2),0);
Canvas.LineTo(round((Form1.Width-Panel1.Width)/3*2),Form1.Height);
end
else
begin
Canvas.Pen.Mode := pmNot;
Canvas.moveto(0,round(Form1.Height/3)); --->似乎是这里的问题
Canvas.lineto(Form1.Width,round(Form1.Height/3));
Canvas.MoveTo(0,round(Form1.Height/3*2));
Canvas.LineTo(Form1.Width,round(Form1.Height/3*2));
Canvas.MoveTo(round((Form1.Width-Panel1.Width)/3),0);
Canvas.LineTo(round((Form1.Width-Panel1.Width)/3),Form1.Height);
Canvas.MoveTo(round((Form1.Width-Panel1.Width)/3*2),0);
Canvas.LineTo(round((Form1.Width-Panel1.Width)/3*2),Form1.Height);
end;
end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
While SpeedButton1.Down do
begin
Edit1.Text := inttostr(InRegionNo(x,y));
end;
end;function TForm1.InRegionNo(X,Y:Integer):Integer;
begin
If x<round((Form1.Width-Panel1.Width)/3) then
if x>=0 then
if y<round(Form1.Height/3) then
if y>=0
then Result := 1;
If x<round((Form1.Width-Panel1.Width)/3*2) then
if x>=round((Form1.Width-Panel1.Width)/3) then
if y<round(Form1.Height/3) then
if y>=0
then Result := 2;
If x<round(Form1.Width-Panel1.Width) then
if x>=round((Form1.Width-Panel1.Width)/3*2) then
if y<round(Form1.Height/3) then
if y>=0
then Result := 3;
If x<round((Form1.Width-Panel1.Width)/3) then
if x>=0 then
if y<round(Form1.Height/3*2) then
if y>=round(Form1.Height/3)
then Result := 4;
If x<round((Form1.Width-Panel1.Width)/3*2) then
if x>=round((Form1.Width-Panel1.Width)/3) then
if y<round(Form1.Height/3*2) then
if y>=round(Form1.Height/3)
then Result := 5;
If x<round(Form1.Width-Panel1.Width) then
if x>=round((Form1.Width-Panel1.Width)/3*2) then
if y<round(Form1.Height/3*2) then
if y>=round(Form1.Height/3)
then Result := 6;
If x<round((Form1.Width-Panel1.Width)/3) then
if x>=0 then
if y<round(Form1.Height) then
if y>=round(Form1.Height/3*2)
then Result := 7;
If x<round((Form1.Width-Panel1.Width)/3*2) then
if x>=round((Form1.Width-Panel1.Width)/3) then
if y<round(Form1.Height) then
if y>=round(Form1.Height/3*2)
then Result := 8;
If x<round(Form1.Width-Panel1.Width) then
if x>=round((Form1.Width-Panel1.Width)/3*2) then
if y<round(Form1.Height) then
if y>=round(Form1.Height/3*2)
then Result := 9;end;end.
以上代码有些变量还没有用到,我的本意是首先用线条将整个窗口划分成9个格子,然后在不用区域点击鼠标后回显示不用的数字.但原先以上的代码执行时并没有问题,但后来不知道哪里不对劲,就出现了最上面的错误内容.程序无法运行.
"Project CrackMe.exe raised exception class EAccessViolation with message 'Accessviolation at address 00454648 in module 'CrackMe.exe'. Read of address 0000004C'. Process stopped. Ues Step or Run to continue."以下是代码,
unit UntCrackMe;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;type
TForm1 = class(TForm)
Panel1: TPanel;
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
Button3: TButton;
Label2: TLabel;
SpeedButton1: TSpeedButton;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
function InRegionNo(x,y:Integer):integer;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
Rec: array[1..128] of Integer;
i: integer;
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
j:integer;
begin
Edit1.Enabled := False;
Button1.Enabled := False;
Edit1.Text := '';
i:=0;
for j:=0 to 127 do Rec[j] := 0;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
Close;
end;procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if SpeedButton1.Down then
begin
Canvas.Pen.Mode := pmNot;
Canvas.moveto(0,round(Form1.Height/3));
Canvas.lineto(Form1.Width,round(Form1.Height/3));
Canvas.MoveTo(0,round(Form1.Height/3*2));
Canvas.LineTo(Form1.Width,round(Form1.Height/3*2));
Canvas.MoveTo(round((Form1.Width-Panel1.Width)/3),0);
Canvas.LineTo(round((Form1.Width-Panel1.Width)/3),Form1.Height);
Canvas.MoveTo(round((Form1.Width-Panel1.Width)/3*2),0);
Canvas.LineTo(round((Form1.Width-Panel1.Width)/3*2),Form1.Height);
end
else
begin
Canvas.Pen.Mode := pmNot;
Canvas.moveto(0,round(Form1.Height/3)); --->似乎是这里的问题
Canvas.lineto(Form1.Width,round(Form1.Height/3));
Canvas.MoveTo(0,round(Form1.Height/3*2));
Canvas.LineTo(Form1.Width,round(Form1.Height/3*2));
Canvas.MoveTo(round((Form1.Width-Panel1.Width)/3),0);
Canvas.LineTo(round((Form1.Width-Panel1.Width)/3),Form1.Height);
Canvas.MoveTo(round((Form1.Width-Panel1.Width)/3*2),0);
Canvas.LineTo(round((Form1.Width-Panel1.Width)/3*2),Form1.Height);
end;
end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
While SpeedButton1.Down do
begin
Edit1.Text := inttostr(InRegionNo(x,y));
end;
end;function TForm1.InRegionNo(X,Y:Integer):Integer;
begin
If x<round((Form1.Width-Panel1.Width)/3) then
if x>=0 then
if y<round(Form1.Height/3) then
if y>=0
then Result := 1;
If x<round((Form1.Width-Panel1.Width)/3*2) then
if x>=round((Form1.Width-Panel1.Width)/3) then
if y<round(Form1.Height/3) then
if y>=0
then Result := 2;
If x<round(Form1.Width-Panel1.Width) then
if x>=round((Form1.Width-Panel1.Width)/3*2) then
if y<round(Form1.Height/3) then
if y>=0
then Result := 3;
If x<round((Form1.Width-Panel1.Width)/3) then
if x>=0 then
if y<round(Form1.Height/3*2) then
if y>=round(Form1.Height/3)
then Result := 4;
If x<round((Form1.Width-Panel1.Width)/3*2) then
if x>=round((Form1.Width-Panel1.Width)/3) then
if y<round(Form1.Height/3*2) then
if y>=round(Form1.Height/3)
then Result := 5;
If x<round(Form1.Width-Panel1.Width) then
if x>=round((Form1.Width-Panel1.Width)/3*2) then
if y<round(Form1.Height/3*2) then
if y>=round(Form1.Height/3)
then Result := 6;
If x<round((Form1.Width-Panel1.Width)/3) then
if x>=0 then
if y<round(Form1.Height) then
if y>=round(Form1.Height/3*2)
then Result := 7;
If x<round((Form1.Width-Panel1.Width)/3*2) then
if x>=round((Form1.Width-Panel1.Width)/3) then
if y<round(Form1.Height) then
if y>=round(Form1.Height/3*2)
then Result := 8;
If x<round(Form1.Width-Panel1.Width) then
if x>=round((Form1.Width-Panel1.Width)/3*2) then
if y<round(Form1.Height) then
if y>=round(Form1.Height/3*2)
then Result := 9;end;end.
以上代码有些变量还没有用到,我的本意是首先用线条将整个窗口划分成9个格子,然后在不用区域点击鼠标后回显示不用的数字.但原先以上的代码执行时并没有问题,但后来不知道哪里不对劲,就出现了最上面的错误内容.程序无法运行.
Form1: TForm1;
Rec: array[1..128] of Integer;--->问题就出现在这两行代码,应该是内存冲突了
i: integer;不过还是请高手帮我解释解释!
......
Rec: array[1..128] of Integer;
......procedure TForm1.FormCreate(Sender: TObject);
var
j:integer;
begin
......
for j:=0 to 127 do Rec[j] := 0; <-此处访问数组Rec出现了下标越界
end;