Z
zhenghui
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
electric=record
dsf_czm:shortint;
dsf_type:array[0..2]of char;
dsf_area:array[0..2]of char;
flag:byte;
data_len:integer;
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
e1,e2:electric;
sTEmp :^string;
begin
e1.dsf_czm :=100;
e1.dsf_type :='www';
e1.dsf_area :='hhh';
e1.flag :=50;
e1.data_len :=65535;
//setlength(stemp,sizeof(electric));
getmem(stemp,sizeof(electric));
copymemory(pointer(stemp),pointer(@e1),sizeof(electric));
copymemory(pointer(@e2),pointer(stemp),sizeof(electric));
showmessage(inttostr(e2.data_len));
showmessage(stemp^);//出错,访问冲突
freemem(stemp);
end;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
electric=record
dsf_czm:shortint;
dsf_type:array[0..2]of char;
dsf_area:array[0..2]of char;
flag:byte;
data_len:integer;
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
e1,e2:electric;
sTEmp :^string;
begin
e1.dsf_czm :=100;
e1.dsf_type :='www';
e1.dsf_area :='hhh';
e1.flag :=50;
e1.data_len :=65535;
//setlength(stemp,sizeof(electric));
getmem(stemp,sizeof(electric));
copymemory(pointer(stemp),pointer(@e1),sizeof(electric));
copymemory(pointer(@e2),pointer(stemp),sizeof(electric));
showmessage(inttostr(e2.data_len));
showmessage(stemp^);//出错,访问冲突
freemem(stemp);
end;