我有一个基本表单,我想一次将其用于屏幕上的多个表单。我以为我正确设置了继承,但是当我创建 2 个表单时,只有最后创建的一个显示在屏幕上。当使用构造函数传入时,我也无法让标题字符串实际更改。
这是我的祖先形式:
unit BasePanel;
interface
uses
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
OvcBase,
StdCtrls,
ExtCtrls,
MySBox,
AdvGroupBox,
AdvOfficeImage,
EnJpgGr,
BorderPanel,
AdvPanel,
Grids,
AdvObj,
BaseGrid,
AdvGrid,
AdvUtil;
type
TBasePanelForm = class(TForm)
MainPanel: TAdvPanel;
BaseTimer: TTimer;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure SavePosition;
procedure SetTimerInterval(Interval: Cardinal);
constructor CreatePanel(Name:String; Title:String; TimerEnabled: Boolean);
end;
var
BasePanelForm: TBasePanelForm;
PanelName : String;
BaseTimerEnabled: Boolean;
PanelTitle:String;
implementation
{$R *.dfm}
constructor TBasePanelForm.CreatePanel(Name: String; Title:String; TimerEnabled: Boolean);
begin
inherited Create(application);
PanelName := Name;
if Title = '' then
Title := PanelName;
PanelTitle := Title;
BaseTimerEnabled := TimerEnabled;
end;
procedure TBasePanelForm.SetTimerInterval(Interval: Cardinal);
begin
BaseTimer.Interval := Interval;
end;
procedure TBasePanelForm.FormCreate(Sender: TObject);
begin
self.MainPanel.Text := '<img src="idx:1"> ' + PanelTitle;
BaseTimer.Enabled := BaseTimerEnabled;
MainPanel.OptimizePaint := True;
MainPanel.DoubleBuffered := True;
end;
procedure TBasePanelForm.SavePosition;
begin
//Save the postions to ini
BaseTimer.Interval := 1;
end;
end.
这里是继承它的形式之一:
unit WeatherPanel;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, BasePanel, Vcl.ExtCtrls, AdvPanel,
AdvCustomControl, AdvWebBrowser;
type
TWeatherPanelForm = class(TBasePanelForm)
WebBrowser: TAdvWebBrowser;
constructor CreatePanel(url_string:String);
procedure BaseTimerTimer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
end;
var
WeatherPanelForm: TWeatherPanelForm;
URL:String;
implementation
{$R *.dfm}
constructor TWeatherPanelForm.CreatePanel(url_string:String);
begin
inherited CreatePanel('weather','Weather', True);
URL := url_string;
end;
procedure TWeatherPanelForm.FormCreate(Sender: TObject);
begin
inherited;
WebBrowser.Navigate(URL);
end;
end.
这是我创建它们的方法:
TextPanelForm := TTextPanelForm.CreatePanel;
TextPanelForm.Parent := MainForm;
TextPanelForm.Top := 0;
TextPanelForm.Left := 0;
TextPanelForm.Visible := true;
TextPanelForm.Show;
WeatherPanelForm := TWeatherPanelForm.CreatePanel('url-here');
WeatherPanelForm.Parent := MainForm;
WeatherPanelForm.Visible := true;
WeatherPanelForm.Show;
WeatherPanelForm.Top := 300;
WeatherPanelForm.Left := 500;
我尝试设置表单继承。文件->新建->其他->继承。 TextPanelForm 和 WeatherPanelForm 都继承了 basepanelform
我期望能够实例化基本表单的单独实例。就像我在创建每个表单时设置面板的标题一样。
仅显示天气面板,我设置的标题标签默认与BasePanel中的内容没有变化
它似乎只使用 1 个 BasePanel 实例,如果我在运行时更改 BasePanel 实例中的属性,它不会执行屏幕上显示的内容。
我做错了什么?