4

I'd like to add a dcu file to a project before compiling it. I'm trying to use the OTA to this. In IOTAProject I have the option to add a file (AddFile()), but when I try to add a dcu it doesn't allow me, and I must set the file as the first file in my project.

I'd like to simulate some thing like:

------------------ Original project
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};
etc...

------------------- Before compile I intercept it and set
program Project1;

uses
  MyDCU, //Add this
  Forms,
  Unit1 in 'Unit1.pas' {Form1};
etc...

------------------ After compile remove and it came back to 
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};
etc...

The after/before compiling interception is not the problem IOTAIDENotifier give me the necessary interface to work with. The problem is only with the dcu file as the first file of my project.

Someone can help me? Tks

Rodrigo Farias Rezino
  • 2,687
  • 3
  • 33
  • 60
  • you have before and after compile options in project options, what you could do is call a utility app that will do just that for you. –  May 10 '12 at 03:20
  • @Dorin Duminica, I edited my post. Tks to the answer. But I'm not in troubles with the compiling interception, the problem is the dcu. – Rodrigo Farias Rezino May 10 '12 at 03:26
  • I'm thinking about change the dpr as a text file, add the things that I need, save, and after remove and save again. But I'm looking for solutions to avoid it. – Rodrigo Farias Rezino May 10 '12 at 03:30
  • 1
    You can find a partial answer to you post [here](http://stackoverflow.com/a/10297048/744588) on SO: Reverting should be straight forward, TUsesManager can also do it! – menjaraz May 10 '12 at 04:10
  • @Dorin Duminica: Doing so is intrusive and annoying, the IDE notify the user every time a unit reference insertion/deletion has occured to resync its edit buffer (Reload from disk). – menjaraz May 10 '12 at 04:28
  • @menjaraz not suggesting that it's a good idea (: actually, I wouldn't interfere with delphi's build process at all, it's buggy enough as is. –  May 10 '12 at 04:39
  • 2
    @Dorin Duminica: You are right, the same to the `uses clause` of a DPR file which is more or less "owned" by the IDE as Rudy Velthuis stated [here](http://stackoverflow.com/questions/6762194/how-to-prevent-delphi-modifying-its-dpr-project-source-unexpectedly/6765289#6765289). – menjaraz May 10 '12 at 05:10
  • @menjaraz thank you, didn't knew about that, makes me sad ): –  May 10 '12 at 05:18
  • @Dorin Duminica: You are welcome. – menjaraz May 10 '12 at 05:20
  • Why not add the DCU file contents by adding it to another .pas file's uses list, one NOT OWNED BY THE IDE. – Warren P May 10 '12 at 10:58

1 Answers1

1

Since the OTA does not supply a CodeDom (as far as I know) the only chance how to do this is by intercepting the BeforeCompile Notification, parse the project file (The IDE version not the file system) and add it to the uses clause yourself. That done, stream back the modified contents to the IDE buffer.

Tobias R
  • 928
  • 8
  • 22
  • Indeed, that's the mechanism used by the defunct `DelFor` expert to reformat codes (PAS and DPR files included). – menjaraz May 10 '12 at 11:08