Delphi:将框架嵌入到面板中并查询框架内标签的属性

时间:2015-05-05 02:30:49

标签: delphi

使用delphi XE7。我只想将框架加载到面板中,然后单击按钮在运行时查询框架内标签的标题属性。我似乎无法让它发挥作用。请告知。感谢。

Unit1中的Panel2

unit Unit1;
interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils,
System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;

type
TForm1 = class(TForm)
 Button4: TButton;
 Panel2: TPanel;
 procedure Button4Click(Sender: TObject);
 procedure FormCreate(Sender: TObject);

private
    { Private declarations }
public
    { Public declarations }
end;

var
  Form1: TForm1;
implementation
{$R *.dfm}

uses Unit3{TFrame3};

 procedure TForm1.Button4Click(Sender: TObject);
 begin
   ShowMessage(Frame3.Label4.caption);
 end;

 procedure TForm1.FormCreate(Sender: TObject);
 begin
    Frame3.parent:=Panel2;
 end;
end.

本单元中的第3帧

unit Unit3;
interface

uses
 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
 System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
 Vcl.StdCtrls;

type
 TFrame3 = class(TFrame)
 Label4: TLabel;
 private
 public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
 end;

var
  Frame3: TFrame3;

implementation

{$R *.dfm}

constructor TFrame3.Create(TheOwner: TComponent);
 begin
   inherited Create(TheOwner);
 end;

destructor TFrame3.Destroy;
 begin
   inherited Destroy;
 end;
end.

编译ok时,但遇到错误 - " $ 005E098C的第一次机会异常。异常类$ C0000005,在0x005e098c处有消息'访问冲突:读取地址0x00000000'。处理Project1.exe(8416)"

0 个答案:

没有答案