P
panwen
Unregistered / Unconfirmed
GUEST, unregistred user!
我定义了一个记录类型的数据,然后用一个指针指向它,但是通过指针读取数据的时候会出错,提示“Project Project1.exe raised exception class EAccessViolation with message "Access Violation at address 0040368A in Module 'Project1.exe'.Read address 0013FFDA".Process stopped”,大家帮忙看看怎么回事啊
-------------------------------------------------------------------------------
unit Unit11;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TCoinsRec = record
quarters,
pennies :word;
end;
PCoinsRec = ^TCoinsRec;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
CoinsRec : PCoinsRec;
begin
With CoinsRec^ do
begin
quarters := 10;
pennies := 20;
end;
With CoinsRec^ do
Form1.Edit1.Text := InttoStr(quarters);
Dispose(CoinsRec);
end;
end.
------------------------------------------------------------------------------
-------------------------------------------------------------------------------
unit Unit11;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TCoinsRec = record
quarters,
pennies :word;
end;
PCoinsRec = ^TCoinsRec;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
CoinsRec : PCoinsRec;
begin
With CoinsRec^ do
begin
quarters := 10;
pennies := 20;
end;
With CoinsRec^ do
Form1.Edit1.Text := InttoStr(quarters);
Dispose(CoinsRec);
end;
end.
------------------------------------------------------------------------------