[问答] Firemonkey 控件继承后无法显示(空白)
提问:如下安装后的 TMyPanel 能在设计期时正常显示,但 TMyPanel2 在设计期时是白板,不能正常看到,为什么?
TMyPanel = class(TPanel) end; TMyCustomPanel = class(TPanel) TMyPanel2 = class(TMyCustomPanel) end; RegisterComponent('Test', [TMyPanel, TMyPanel2]);
可能:是隔代无法继承 Style 造成的,改成如下就可以了:
TMyPanel = class(TPanel) end; TMyCustomPanel = class(TPanel) end; TMyPanel2 = class(TMyCustomPanel) protected function GetDefaultStyleLookupName: string; override; end; function TMyPanel2.GetDefaultStyleLookupName: string; begin Result := 'panelstyle'; end;
ps. 这个是 QQ 群里的问题,记录一下。
Delphi 10.4 更新如下:
unit TestGrid; interface uses System.SysUtils, System.Classes, FMX.Types, FMX.Controls, FMX.Controls.Model, FMX.Presentation.Factory, FMX.Presentation.Style, FMX.Grid.Style, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Grid; type TTestGrid = class(TStringGrid) private { Private declarations } protected { Protected declarations } public { Public declarations } published { Published declarations } end; procedure Register; implementation procedure Register; begin RegisterComponents('Test', [TTestGrid]); end; initialization RegisterFmxClasses([TTestGrid]); TPresentationProxyFactory.Current.Register(TTestGrid, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>); finalization TPresentationProxyFactory.Current.Unregister(TTestGrid, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>); end.