在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一.主要代码 a)主窗体 type TFrameClass = class of TFrame; TFrmMain = class(TForm) Button1: TButton; Panel1: TPanel; Button2: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } FCurrentfrmClassName: string; FCurrentfrm: TFrame; procedure LoadFrameByClassName(theFrameClass: TFrameClass); public { Public declarations } end; var FrmMain: TFrmMain; implementation {$R *.dfm} procedure TFrmMain.FormCreate(Sender: TObject); begin FCurrentfrmClassName:=''; FCurrentfrm:=nil; end; procedure TFrmMain.LoadFrameByClassName(theFrameClass: TFrameClass); begin if Assigned(FCurrentfrm)and( not SameText(theFrameClass.ClassName,FCurrentfrmClassName)) then FreeAndNil(FCurrentfrm); FCurrentfrm:=theFrameClass.Create(nil); FCurrentfrm.Parent:=Panel1; FCurrentfrm.Left:=(Panel1.Width-FCurrentfrm.Width)div 2; FCurrentfrm.Top:=(Panel1.Height-FCurrentfrm.Height)div 2; FCurrentfrmClassName:=theFrameClass.ClassName; end; procedure TFrmMain.Button1Click(Sender: TObject); begin Self.LoadFrameByClassName(TFrmFirstFrame); ShowMessage('显示第一个Frame!'); end; procedure TFrmMain.Button2Click(Sender: TObject); begin Self.LoadFrameByClassName(TFrmSecondFrame); ShowMessage('显示第二个Frame!'); end; end.
b)第一个Frame type TFrmFirstFrame = class(TFrame) private { Private declarations } public { Public declarations } end; implementation {$R *.dfm} end. c)第二个Frame type TFrmSecondFrame = class(TFrame) private { Private declarations } public { Public declarations } end; implementation {$R *.dfm} end.
二.测试 显示第一个Frame
显示第二个Frame |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论