From 5b057a70f8142bd7fcd948ccd61dd8ece78aba21 Mon Sep 17 00:00:00 2001 From: lmbelo Date: Fri, 17 Jun 2022 07:41:36 -0700 Subject: [PATCH] Code optimization --- Source/PythonTools.IOTAUtils.pas | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Source/PythonTools.IOTAUtils.pas b/Source/PythonTools.IOTAUtils.pas index c77bc77..9615c94 100644 --- a/Source/PythonTools.IOTAUtils.pas +++ b/Source/PythonTools.IOTAUtils.pas @@ -23,6 +23,7 @@ TIOTAUtils = class class function ModuleIsPas(const AModule: IOTAModule): boolean; class function ModuleIsCpp(const AModule: IOTAModule): boolean; class function ModuleIsForm(const AModule: IOTAModule): boolean; + class function ModuleIsExportable(const AModule: IOTAModule): boolean; class procedure EnumComps(const AFormEditor: IOTAFormEditor; const ACallback: TProc); class function GetFormCaption(const AComponent: TComponent): string; @@ -103,7 +104,7 @@ class procedure TIOTAUtils.EnumForms(const AProc: TProc); LModule := LModuleServices.Modules[I]; LEditor := GetFormEditorFromModule(LModule); - if not ((ModuleIsPas(LModule) or ModuleIsCpp(LModule)) and ModuleIsForm(LModule)) then + if not ModuleIsExportable(LModule) then Continue; LDesigner := (LEditor as INTAFormEditor).FormDesigner; @@ -306,20 +307,12 @@ class function TIOTAUtils.HasForms: boolean; LModuleServices := (BorlandIDEServices as IOTAModuleServices); for I := 0 to LModuleServices.ModuleCount - 1 do begin LModule := LModuleServices.Modules[I]; - if (ModuleIsPas(LModule) or ModuleIsCpp(LModule)) and ModuleIsForm(LModule) then + if ModuleIsExportable(LModule) then Exit(true); end; Result := false; end; -class function TIOTAUtils.ModuleIsCpp(const AModule: IOTAModule): boolean; -begin - if SameText(ExtractFileExt(AModule.FileName), '.cpp') then - Result := true - else - Result := false; -end; - class function TIOTAUtils.ModuleIsForm(const AModule: IOTAModule): boolean; var LEditor: IOTAFormEditor; @@ -347,10 +340,19 @@ class function TIOTAUtils.ModuleIsForm(const AModule: IOTAModule): boolean; class function TIOTAUtils.ModuleIsPas(const AModule: IOTAModule): boolean; begin - if SameText(ExtractFileExt(AModule.FileName), '.pas') then - Result := true - else - Result := false; + Result := SameText(ExtractFileExt(AModule.FileName), '.pas'); +end; + +class function TIOTAUtils.ModuleIsCpp(const AModule: IOTAModule): boolean; +begin + Result := SameText(ExtractFileExt(AModule.FileName), '.cpp'); +end; + +class function TIOTAUtils.ModuleIsExportable( + const AModule: IOTAModule): boolean; +begin + Result := (ModuleIsPas(AModule) or ModuleIsCpp(AModule)) + and ModuleIsForm(AModule); end; class procedure TIOTAUtils.EnumComps(const AFormEditor: IOTAFormEditor;