现在的位置: 首页 > 综合 > 正文

两个结构体可以直接赋值吗? – 回复 “JohnsonAnother” 的问题

2011年07月22日 ⁄ 综合 ⁄ 共 581字 ⁄ 字号 评论关闭
问题来源: http://www.cnblogs.com/del/archive/2008/11/26/1031787.html#1382525

两个结构体可以直接赋值!, 测试如下:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  TRec = record
    name: string;
    age: Word;
  end;

procedure TForm1.Button1Click(Sender: TObject);
var
  r1,r2: TRec;
begin
  r1.name := '张三';
  r1.age := 66;

  r2 := r1;

  r1.name := '李四';
  r1.age := 77;

  ShowMessageFmt('%s, %d', [r1.name, r1.age]); {李四, 77}
  ShowMessageFmt('%s, %d', [r2.name, r2.age]); {张三, 66}
end;

end.

【上篇】
【下篇】

抱歉!评论已关闭.