私はあなたが求めたもの、つまり、実用的な解決策を見つけたと思います。コンポーネントのインスタンスが作成されたとき (フォームにドロップされたとき、またはそのインスタンスを含むフォーム/モジュールが IDE で開かれたとき) に、プロジェクト オプションからランタイム テーマを無効にします。これは、ユーザーがランタイム テーマを後で手動で再度有効にすることを妨げるものではありませんが、それでも役立つ場合があります。
ところで、IOTAProjectOptions
この場合は役に立たないようです。が必要なようIOTAProjectResource
です。
TestComponentU.pas
(ランタイム パッケージの一部):
unit TestComponentU;
interface
uses
Windows, Classes;
type
ITestComponentDesign = interface
function DisableRuntimeThemes: Boolean;
end;
TTestComponent = class(TComponent)
public
constructor Create(AOwner: TComponent); override;
end;
var
TestComponentDesign: ITestComponentDesign = nil;
implementation
uses
Dialogs;
constructor TTestComponent.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if (csDesigning in ComponentState) and Assigned(TestComponentDesign) and
TestComponentDesign.DisableRuntimeThemes then
ShowMessage('Project runtime themes disabled');
end;
end.
TestComponentRegU.pas
(IDE にインストールされたデザイン パッケージの一部):
unit TestComponentRegU;
interface
procedure Register;
implementation
uses
Windows, Classes, SysUtils, TestComponentU, ToolsAPI;
type
TTestComponentDesign = class(TInterfacedObject, ITestComponentDesign)
public
function DisableRuntimeThemes: Boolean;
end;
procedure Register;
begin
RegisterComponents('Test', [TTestComponent]);
end;
function GetProjectResource(const Project: IOTAProject): IOTAProjectResource;
var
I: Integer;
begin
Result := nil;
if not Assigned(Project) then
Exit;
for I := 0 to Project.ModuleFileCount - 1 do
if Supports(Project.ModuleFileEditors[I], IOTAProjectResource, Result) then
Break;
end;
function GetProjectResourceHandle(const ProjectResource: IOTAProjectResource; ResType, ResName: PChar): TOTAHandle;
var
I: Integer;
ResEntry: IOTAResourceEntry;
begin
Result := nil;
if not Assigned(ProjectResource) then
Exit;
for I := 0 to ProjectResource.GetEntryCount - 1 do
begin
ResEntry := ProjectResource.GetEntry(I);
if Assigned(ResEntry) and (ResEntry.GetResourceType = ResType) and (ResEntry.GetResourceName = ResName) then
begin
Result := ResEntry.GetEntryHandle;
Break;
end;
end;
end;
function DisableProjectRuntimeThemes(const Project: IOTAProject): Boolean;
var
ProjectResource: IOTAProjectResource;
ResHandle: TOTAHandle;
begin
Result := False;
ProjectResource := GetProjectResource(Project);
if not Assigned(ProjectResource) then
Exit;
ResHandle := GetProjectResourceHandle(ProjectResource, RT_MANIFEST, CREATEPROCESS_MANIFEST_RESOURCE_ID);
if Assigned(ResHandle) then
begin
ProjectResource.DeleteEntry(ResHandle);
Result := True;
end;
end;
function TTestComponentDesign.DisableRuntimeThemes: Boolean;
var
Project: IOTAProject;
begin
Project := GetActiveProject;
Result := Assigned(Project) and DisableProjectRuntimeThemes(Project);
end;
initialization
TestComponentDesign := TTestComponentDesign.Create;
finalization
TestComponentDesign := nil;
end.