Search code examples
delphiopentools

How to get errors of the file using OTA?


I'd like to access the errors on the active file (.pas). Now a days I can find it on the left side of the IDE, as you can see on image.

I found on OTA the interface IOTAModuleErrors, that seems to be what I want. But I didn't found it on BorlandIDEServices.QueryInterface or BorlandIDEServices.GetService. Someone knows how to access it ?

enter image description here


Solution

  • I found it! It was much simpler than I thought, it's just a matter of casting the IOTAModule on the module to IOTAModuleErrors.

    If you want a practical example you can check this project I use on the unit Source/FindUnit.OTAUtils.pas, on function GetErrorListFromActiveModule.

    Sample:

    function GetErrorsListFromActiveModule: TOTAErrors;
    var
      ModuleServices: IOTAModuleServices;
      ModuleErrors: IOTAModuleErrors;
    begin
      ModuleServices := BorlandIDEServices as IOTAModuleServices;
      Assert(Assigned(ModuleServices));
      ModuleErrors := ModuleServices.CurrentModule as IOTAModuleErrors;
      Result := ModuleErrors.GetErrors(ModuleServices.CurrentModule.FileName);
    end;
    

    Thank you