|
|
|
function CreateModule(const Creator: IOTACreator): IOTAModule; Notice this takes a parameter of IOTACreator. What is a Creator? A Creator is basically the definition of the Module to be created. The IDE calls the methods of the Creator and uses that information to choose what Module to create and how to create it. Once the Module is created it is returned to the caller. IOTACreator is one of the most frustrating interfaces in the OTA. It seems clear enough how to use it but the subtleties quickly show through. When methods return information that is not compatible the usual response of the IDE is to either fail in the creation of the Module, or more often throw error strange and useless error messages. I will try to take the frustration and mystery out of this important interface.
Implementing IOTACreator The type of Module to be created will dictate the IOTACreator that is necessary. The following Creators are available:
Since we are coding a ProjectCreator the IOTAProjectCreator is the interface to use:
Lets take the methods one at a time.
IOTACreator function IOTACreator.GetCreatorType: string; This method informs the IDE as to what type of project you would like to create. The valid choices are:
At first this seem clear enough but there is a hidden catch. If you use one of these constants you must not return an IOTAFile in the function NewProjectSource(const ProjectName: string): IOTAFile; method. Returning an IOTAFile is how you define your own contents of the file. If you do strange things can happen with the most common being this useless error message during the execution of the CreateModule call:
function IOTACreator.GetExisting: Boolean; This method informs the IDE if the module is existing. Typically when creating a new object the object does not exist so the normal return value is False. The catch here is a object may have multiple Owner Modules so I am assuming that a "creation" in this case means the object exists and it is now a shared resource between more than one Module. I have not seen an example of this in my testing.
function IOTACreator.GetFileSystem: string; Returns the IDString of the FileSystem to use for this module source. File Systems are an advanced topic that are more suited for IDE Editor enhancements. Typically an empty string is returned.
function IOTACreator.GetOwner: IOTAModule; Returns the Module that will be the owner of the new object being created. For example if the object being created is a Form then the owner would be the Project. If the object being created is a Project Module then the owner would be the Project Group.
function IOTACreator.GetUnnamed: Boolean; By returning true the IDE will show the Save As.. dialog box when the user tries to save the object for the first time.
IOTAProjectCreator function IOTAProjectCreator.GetFileName: string; Return a fully qualified file name of the source that already exists.
function IOTAProjectCreator.GetOptionFileName: string; Returns the name on an existing C++ Option file. The same caution applies as explained in the IOTAProjectCreator.GetFileName method.
function IOTAProjectCreator.GetShowSource: Boolean; If you want the IDE to show the source in the Editor when the Module is created return true.
procedure IOTAProjectCreator.NewDefaultModule; Called to create a new Default Module for the Project.
function IOTAProjectCreator.NewOptionSource(const ProjectName: string): IOTAFile; Called to create the C++ Option file by returning an IOTAFile that implements the file source. The parameter is the Project Name. If the IDE created the Module then it has assigned a default identifier to the project, typically something like "Project1" if it is the first Project created. It allows you to use the name of the Project in any source code that may be generated in this method.
procedure IOTAProjectCreator.NewProjectResource(const Project: IOTAProject); If there is some special non standard resource file that is necessary for your Project it may be created here. Notice that the Project Module is created and a pointer to it is passed in this method.
function IOTAProjectCreator.NewProjectSource(const ProjectName: string): IOTAFile; This is where the source for the project is added. Again if you are using a standard Creator Type return a nil, see IOTACreator.GetCreatorType, if GetCreatorType is returning an empty string you must return a valid IOTAFile interface or you will get an AV. The actual source code is not written in the method. It is done indirectly in the IOTAFile.GetSource implementation.
IOTAProjectCreator80
function GetProjectPersonality: string; This method tells the IDE what language the new project will be created in. The supported Personalities are:
IDE ProjectCreator Call Stack The following is a debug output of how the IDE calls the Project Module Creator when a default sApplication string is returned for GetCreatorType.
Notice the NewProjectResource and NewOptionSource methods are not called but the NewProjectSource is, even though if you return a IOTAFile it messes everything up. This was with Delphi 7.
Now when an empty string is returned for GetCreatorType.
Next we need to implement a File to create our own code in the
unit.
|
Last Modified on: |