M
Miros
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TA = packed record
Idx: Word;
temp: Word;
end;
TAArr = array of array of TA;
pTAArr = ^TAArr;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
FS: TFileStream;
pAArr: pTAArr;
I, J: Integer;
begin
pAArr := AllocMem(Sizeof(TA) * 5);
if pAArr = nil then ShowMessage('= nil');
FS := TFileStream.Create('D:/1.1', fmCreate);
try
for I := 0 to 4 do
for J := 0 to 4 do
begin
pAArr^[I, J].Idx := I; //这里有Access violation at address 00454341 in module 'Project1.exe'. Read of address 00000000
pAArr^[I, J].temp := J;
end;
except
On E: Exception do
Memo1.Lines.Add(E.Message)
end;
FS.WriteBuffer(pAArr^,Sizeof(TA) * 5 * 5);
FreeAndNil(FS);
FreeMem(pAArr);
end;
end.
请求高人解决。
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TA = packed record
Idx: Word;
temp: Word;
end;
TAArr = array of array of TA;
pTAArr = ^TAArr;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
FS: TFileStream;
pAArr: pTAArr;
I, J: Integer;
begin
pAArr := AllocMem(Sizeof(TA) * 5);
if pAArr = nil then ShowMessage('= nil');
FS := TFileStream.Create('D:/1.1', fmCreate);
try
for I := 0 to 4 do
for J := 0 to 4 do
begin
pAArr^[I, J].Idx := I; //这里有Access violation at address 00454341 in module 'Project1.exe'. Read of address 00000000
pAArr^[I, J].temp := J;
end;
except
On E: Exception do
Memo1.Lines.Add(E.Message)
end;
FS.WriteBuffer(pAArr^,Sizeof(TA) * 5 * 5);
FreeAndNil(FS);
FreeMem(pAArr);
end;
end.
请求高人解决。