Visible 属性在设计时被忽略。所有关于可见的信息都只存储在 Frame 的 dfm 中。在使用框架的表单中将实例的可见性设置为 true 不会存储在表单的 dfm 中。手动添加它没有帮助,它会在下次保存时被忽略并删除。
澄清后,它可以显示为例如属性颜色。在设计时创建了一个框架颜色 clBlack,在 Form used 2 Frames 中,颜色设置为 clRed 和 clBlue。
unit Unit7;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TCallOnCreate=Procedure(Sender:TObject) of object;
TFrame7 = class(TFrame)
Button1: TButton;
Procedure Loaded;override;
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
Public Constructor Create(AOwner:TComponent);Override;
end;
implementation
uses RTTI;
{$R *.dfm}
{ TFrame7 }
constructor TFrame7.Create(AOwner: TComponent);
var
ToCall : TCallOnCreate;
Routine : TMethod;
begin
inherited;
Showmessage('Created ' + IntToStr(Color));
Routine.Data := Pointer(AOwner);
Routine.Code := AOwner.MethodAddress('InfoOnFrameCreate');
if Assigned(Routine.Code) then
begin
ToCall:= TCallOnCreate(Routine);
ToCall(Self);
end;
end;
procedure TFrame7.Loaded;
begin
inherited;
Showmessage('Loaded ' + IntToStr(Color));
end;
end.
通过以下示例,如何在将使用 Frame 的窗体中实现代码。
unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unit7;
type
TForm6 = class(TForm)
Frame71: TFrame7;
Procedure InfoOnFrameCreate(Sender:TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form6: TForm6;
implementation
{$R *.dfm}
{ TForm6 }
procedure TForm6.InfoOnFrameCreate(Sender: TObject);
begin
Showmessage('Frame Created');
end;
end.