Difference between revisions of "Ide/Creating new Project Items"

From wiki.visual-prolog.com

Line 16: Line 16:


* The subdirectory into which the package files will be placed.
* The subdirectory into which the package files will be placed.
* The package header file (i.e. '''NewPackage.ph''' that describes the ''public'' view of the package. The package header file should be inserted by <vp>#include</vp> directives in all other packages that use the package. The package header file contains the list of ''public'' interfaces, the list of ''public'' classes, and some <vp>#requires</vp> directives.<br />Names declared in public interfaces and classes are seen outside the package in all places where the package header file is included. <vp>#requires</vp> directives are used to guaranty that all packages required to use the package are included into the project.
* The package header file (i.e. '''NewPackage.ph''') that describes the ''public'' view of the package. The package header file should be inserted by <vp>#include</vp> directives in all other packages that use the package. The package header file contains the list of ''public'' interfaces, the list of ''public'' classes, and some <vp>#requires</vp> directives.<br />Names declared in public interfaces and classes are seen outside the package in all places where the package header file is included. <vp>#requires</vp> directives are used to guaranty that all packages required to use the package are included into the project.
* The package implementation file (i.e. '''NewPackage.pack''') produces a Visual Prolog compilation unit which is added to a set of project modules.
* The package implementation file (i.e. '''NewPackage.pack''') produces a Visual Prolog compilation unit which is added to a set of project modules.


Line 54: Line 54:
The package header file provides external view of the package.
The package header file provides external view of the package.


* It provides <vp>#include</vp> directives for all files containing declarations of all interfaces ('''.i''') and all classes ('''.cl''' files) exported from the package (''public ''interfaces and classes).
* It provides <vp>#include</vp> directives for all files containing declarations of all interfaces ('''.i''' fles) and all classes ('''.cl''' files) exported from the package (''public ''interfaces and classes).
* It contains <vp>#include</vp> directives for package header ('''.ph''' files) files of all packages publicly used by the package. Since these package header files provide declarations of all public names declared in them; therefore, all public names declared in these packages are also publicly visible from the package.
* It contains <vp>#include</vp> directives for package header ('''.ph''' files) files of all packages publicly used by the package. Since these package header files provide declarations of all public names declared in them; therefore, all public names declared in these packages are also publicly visible from the package.
* It contains some <vp>#requires</vp> directives. <vp>#requires</vp> directives define packages whose implementations (compiled code) have to  be accessible in order to use the package.
* It contains some <vp>#requires</vp> directives. <vp>#requires</vp> directives define packages whose implementations (compiled code) have to  be accessible in order to use the package.
Line 96: Line 96:
[[Image:Ide_How_COMPackage.png|center|frame|Creating '''New COM Package''' Dialog]]
[[Image:Ide_How_COMPackage.png|center|frame|Creating '''New COM Package''' Dialog]]


After you fill in all required COM package settings, you can press the '''Create''' button. Then the IDE creates the package subdirectory, the package header file '''XML.ph''' for the above picture), and the package implementation file ('''XML.pack''' for the above picture). They appear in the project tree in the Project Window after the created package is compiled.
After you fill in all required COM package settings, you can press the '''Create''' button. Then the IDE creates the package subdirectory, the package header file ('''XML.ph''' for the above picture), and the package implementation file ('''XML.pack''' for the above picture). They appear in the project tree in the Project Window after the created package is compiled.


==== Options: ====
==== Options: ====
Line 165: Line 165:


=== Creating a Interface ===
=== Creating a Interface ===
'''How to Create a New Interface?'''
An interface definition defines the named object type.
All predicates declared in an interface are object members in objects of the interface type.
To create a new interface and to add it into one of the packages registered in the project you should activate the '''File | New''' IDE command. In the left pane of the opened '''Create Project Item''' dialog you should select '''Interface'''. Then the dialog accepts the following shape:
[[Image:Ide_How_NewInterface.png|center|frame|The '''New Interface''' Dialog]]
'''Name:'''
In the '''Name''' edit control you should type in an interface name (the '''interfaceName''' on the picture).
'''Package:'''
In the '''Package''' list button you should select one of the packages registered in the project (the '''NewPackage.pack''' on the picture). The created interface will be included into this package. The created file with the default declaration of this interface will be placed into the selected package subdirectory. This subdirectory name is displayed after the package name; it is <span style="color:Purple">(NewPackage\)</span> in the picture.
After you fill in all required settings you can press the '''Create''' button. The IDE creates the interface definition file (it appears in the {{ide|Project Tree#The Project Tree|project tree}} in the '''Project Window''' after compilation of the package) and the <vp>#include @"NewPackage\interfaceName.i"</vp> directive is added into the package header file '''NewPackage.PH''' of the specified package:
<vip>% exported interfaces
#include @"NewPackage\interfaceName.i"</vip>
Since the package header file should be inserted by the <vp>#include @"NewPackage.ph"</vp> directive in all places, where the package is used, so in all these places the <vp>#include @"NewPackage\interfaceName.i"</vp> directive also be seen. This means that the interface <vp>interfaceName</vp> is ''public''.
If you wish to create an interface that should be private to the '''NewPackage''' package, then the include directive for this interface can be manually moved into the package implementation file  '''NewPackage.PACK''':
<vip>% private interfaces
#include @"NewPackage\interfaceName.i"</vip>
Therefore, the interface declaration will not be seen outside of the package implementation. So the interface will be ''private'' to the package implementation.
Notice that information about a new interface does not appear in the project browse information until the package including this interface is compiled.
=== Creating a Class ===
=== Creating a Class ===
=== Creating a Text File ===
=== Creating a Text File ===
=== Creating a Resources ===
=== Creating a Resources ===

Revision as of 09:26, 4 March 2013

IDE

Creating a Project

How to Create a New Project?

To create a new project you should activate the Project | New menu command. Then in the opened Project Settings dialog you should type in or select the desired project settings and press the Create button. The new project with the default parameters correspondent to your settings will be created.

Creating a New Package

Overview

The basic units of code organization accepted in Visual Prolog v.7 are packages. We use packages in Visual Prolog to organize and structuring things. The use of packages ensures homogeneity in structuring principles among different projects. Packages define the standard for tool structuring, they ease sharing source code among projects.

By default, the IDE organizes projects into packages. When you create a new package in a project, the IDE creates:

  • The subdirectory into which the package files will be placed.
  • The package header file (i.e. NewPackage.ph) that describes the public view of the package. The package header file should be inserted by #include directives in all other packages that use the package. The package header file contains the list of public interfaces, the list of public classes, and some #requires directives.
    Names declared in public interfaces and classes are seen outside the package in all places where the package header file is included. #requires directives are used to guaranty that all packages required to use the package are included into the project.
  • The package implementation file (i.e. NewPackage.pack) produces a Visual Prolog compilation unit which is added to a set of project modules.

How to Create a New Package?

To create a new package in a project you should select the IDE menu command File | New. In the left pane of the appeared Create Project Item dialog you should select Package. Then the dialog accepts the following shape:

The New Package Dialog

Name:

In the Name edit control you should type in the name of the package being created (NewPackage in the picture).

Parent Directory

In the Parent Directory field you should type in or select (using the Browse button) the parent directory for the package. The package will be placed into the subdirectory of this parent directory. By default, when you activate this dialog, Parent Directory displays the directory selected in the project tree. If this directory is one of project subdirectories, then its path is displayed relatively to the project root directory.

In this Parent Directory the IDE creates a new subdirectory with the name correspondent to the specified package name. The package will be placed into this subdirectory.

After you fill in all required settings for the package, you can press the Create button. Then the IDE creates the package subdirectory, the package header file NewPackage.ph, and the package implementation file NewPackage.pack. (They will appear in the project tree in the Project Window after the created package is compiled.)

Packages

The concept of packages is used for grouping together several linked interfaces and classes. Packages can play a role of some class library. Packages can be used in your program instead of direct placing all these interfaces and classes into your program.

The package is a collection of several grouped together interfaces and classes. The package provides some common name to all these interfaces and classes. Each declaration or implementation of each interface or class from a package is placed in a separate file. Each filename (of these files) coincides with the name of a class or an interface that is declared or implemented in this file. All package files are stored in the same separate package directory. (If a package contains sub-packages, then they are placed in subdirectories of the package directory.)

Except for files with declarations and implementations of interfaces and classes, each package contains two special files: the package header (.PH) and the package implementation (.PACK) files.

  • The package header file provides declarations of all names exported from the package. Therefore, the package header file should be inserted by the #include directive in each other package that uses some names exported from this package.
  • The package implementation file provides code implementing the package classes which can be compiled into an object file. The package implementation file should be included only once into a project that uses this package.

So using the concept of packages we can create sets of linked interfaces and classes grouped into packages. Once created package can be included (and used) in several programs without copying package sources into each project. The example of such set of packages is our [..\..\pfc\pfcOverview.htm Visual Prolog Foundation Classes] (PFC).

Package Header Files

The package header file provides external view of the package.

  • It provides #include directives for all files containing declarations of all interfaces (.i fles) and all classes (.cl files) exported from the package (public interfaces and classes).
  • It contains #include directives for package header (.ph files) files of all packages publicly used by the package. Since these package header files provide declarations of all public names declared in them; therefore, all public names declared in these packages are also publicly visible from the package.
  • It contains some #requires directives. #requires directives define packages whose implementations (compiled code) have to  be accessible in order to use the package.

So the package header file provides declarations of all names exported from the package. Not only of exported names declared in the package itself, but also of all names declared in other packages that are included in the package header file.

A package header file should be inserted by #include directives in all places where the public names exported from the package should be visible.

A package header file does not produce any compiled code, but it is used while compilation to declare names exported from the package.

Usually a package header file has the PackageName.ph name.

Package Implementation Files

The package implementation file provides code implementing classes declared in the package. Compilation of the package implementation file generates object file that provides real implementations of classes declared in the package.

  • It contains the #include directive for the package header file.
  • It provides #include directives for package header files of external packages privately used by the package implementation. These header files provide declarations of all external names used in the package implementation (.pro) files.
  • It provides #include directives for files containing interfaces (.i files) privately used by the package implementation. These interfaces are only used inside the package implementation and are not seen externally.
  • It provides #include directives for files containing declarations of classes (.cl files) privately used by the package implementation. These classes are only used inside the package implementation and are not seen externally.
  • It provides #include directives for all files with class implementations (.pro files) that provides Prolog code implementing all classes declared the package.

Usually a package implementation file has the PackageName.pack name.

Creating a COM Package

How to Import an Existing COM Component

Terminology Used in COM

The Component Object Model (COM) is a way for software components to communicate with each other. It is a binary standard that allows any two components to communicate regardless of what machine they are running on (as long as the machines are connected), what operating systems the machines are running (as long as they support COM), and what language the components are written in. COM provides location transparency: it does not matter whether components are in DLLs or in EXEs. COM components are binary units of code that include packaging and registration code and that create COM objects. Each COM component, in the COM programming model, is a programming structure encapsulating both data and functionality. It is defined and allocated as a single unit and the only public access to the COM data and functionality is through the programming interfaces.

Each COM is simply a program module: a DLL or an EXE file. It can contain one or more COM components. (In Microsoft MSDN terminology components are coclasses.) Each component knows about several interfaces. (In MSDN terminology - each component can support several interfaces.) Each component supports the default interface iUnknown. Using the iUnknown::queryInterface/2-> predicate from the iUnknown interface, one can retrieve references to all interfaces known to a component. Each interface can provide several predicates (methods).

The main aim of importing a COM component into your project is using predicates defined in this COM component. Therefore, the COM package generated for an imported COM component has to provide some wrapper (glue code) to methods implemented in the COM component. That is, the generated COM package must provide declarations of correspondent interfaces, predicates, and domains.

How to Create a New COM Package

To create a COM package providing the interface (wrapper) to some COM component, you should activate the File | New IDE command. Then in the left pane of the opened Create Project Item dialog you should select COM Package. Then the dialog accepts the following shape:

Creating New COM Package Dialog

After you fill in all required COM package settings, you can press the Create button. Then the IDE creates the package subdirectory, the package header file (XML.ph for the above picture), and the package implementation file (XML.pack for the above picture). They appear in the project tree in the Project Window after the created package is compiled.

Options:

Name:

In the Name edit control you should type in the name (xml on the picture) of the COM package (wrapping package) being created.

Parent Directory

In the Parent Directory you should type in or select (using the Browse button) the parent directory for the package. The package will be placed into the subdirectory of this parent directory. If you specify a non-existing name, then this directory will be created. By default, Parent Directory displays the directory selected in the project tree when you activate this dialog. If this directory is one of the project subdirectories, then its path is displayed relatively to the project root directory. If Parent Directory is empty, than it is equal to the project root directory.

In the Parent Directory the IDE creates the new subdirectory with the name correspondent to the specified package name. (It is XML for the above picture.). The package will be placed into this subdirectory.

Source Group Box

Controls in this group box are used to specify a COM module (DLL or EXE) from which a component should be imported. It contains the following controls:

Type Library
  • When this option is checked ON, then in the edit control you should specify a file that contains the type library describing the COM component.
    Press the Load button to activate the Load Type Library File dialog using which you can find and insert the name of the type library file into the edit control.
    Attention! Notice that you HAVE to press the Load button to enforce the IDE to load the COM information from the specified type library even if you directly type in the type library filename into the edit control.
    If a COM client (our program importing COM server components) needs using COM server predicates, then the client application must have information about predicates in COM server components. Predicates often return values and accept parameters. The COM client requires declarations of all these predicates (and domains) in order to use them. This information can be made known in several ways. The Microsoft recommended way is to create a type library. (Remember that type libraries do not provide Prolog declarations.) Type library information can be stored in files with the following filename extensions: .TLB (type library itself), .OLB (multiple type libraries or foreign object libraries), .DLL (COM DLLs can embed type library resources), .EXE (COM EXEs can embed type library resources), .OCX (ActiveX controls).
TypeLib ID
  • When this option is checked ON, then in the edit control you should specify the TypeLib ID of the type library for the COM component that you wish to import. The TypeLib ID is a universally unique identifier (UUID) under which the type library is registered in the Windows system registry. (See CLSID for more information.) The TypeLib ID should be specified as a string of hexadecimal numbers with the following format:
    {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
    Then you MUST press the Load button to enforce the IDE to load COM information from the type library registered with this TypeLib ID.
    In the system registry database you can find all registered TypeLib IDs under:
    HKEY_CLASSES_ROOT\TypeLib = {TypeLib ID}
CLSID
  • When this option is checked ON, then in the edit control you should specify the CLSID of the COM component that you wish to import. The CLSID should be specified as a string of hexadecimal numbers with the following format:
    {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
    Then you MUST press the Load button to enforce the IDE to load COM information from the COM module that embeds the COM component with the specified CLSID.
    Note. Really a COM module can embed several COM components. If you wish to import one of these COM components, then you can specify a CLSID registered to any COM component in this COM module. (Later you will be able to specify the required COM component (or interface) in the list box in the [#Import_Group_Box Import] group box.)
    In MSDN terminology, CLSID is a class identifier. In the Visual Prolog PFC terminology (see the COM package description in the PFC) CLSID is a COM component identifier.
    CLSID is a universally unique identifier (UUID) that identifies the type of a COM component. Each COM component has its CLSID in the Windows system registry database so that it can be loaded and used by other applications. For example, a spreadsheet can create worksheet components, chart components, and macrosheet components. Each of these components has its own CLSID that uniquely identifies this component to the system. That is, if your COM module (COM server or COM container) allows linking to its embedded components, then you need to register the special CLSID for each COM component embedded into the COM module.
    The CLSID is stored in the Windows registry database under the following registry key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID = {CLSID}
    The CLSID is a 128-bit number (in the hexadecimal format) within a pair of curly braces. Typically, CLSIDs (and other UUID values) are represented as strings of hexadecimal numbers with the following format:
    {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
    For example,
    {4208fb66-e22a-11d1-a7d7-00a0c982c00d}
    You can use the UUIDGEN.exe tool to create a new UUID.
    When you find a CLSID you can find the associated PROGID under the following registry sub-key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{CLSID}\ProgID = <programatic identifier>
    See the PROGID options description below.
    Universally unique identifier (UUID)
    The universally unique identifier (UUID) is also known as the globally unique identifier (GUID). The UUID, or GUID, is a unique, 128-bit value used to identify objects. Objects can be OLE servers, interfaces, client objects, etc. Beginning from this moment objects will be identified with UUIDs.
PROGID
  • When this option is checked ON. In the edit control you should specify the PROGID of the COM module from which you wish to import the COM component. The PROGID should be specified as a string of the following format:
    <Program>.<Component>.<Version>
    Words are separated by dots as in Word.Document.6. (Blank spaces cannot be used.)
    Then you MUST press the Load button to enforce the IDE to load COM information from the COM module registered with this PROGID.
    PROGIDs are versioned programmatic identifiers. PROGIDs present human-readable versions of class identifiers (CLSID) used to identify COM components. PROGID is a registry entry that can be associated with CLSID. Like CLSID, PROGID identifies a COM component but with less precision because it is not guaranteed to be globally unique. The Version portion is optional but strongly recommended. Using Version, even if there is only one version of the PROGID, helps to avoid conflicts. It enables different versions of a component coexist without overwriting PROGIDs. If you do not specify a version for a PROGID, the default Version = 1.
    How to find PROGID entries in the registry is described in the CLSID.
IID
  • When this option is checked ON, then in the edit control you should specify the IID of the COM component interface that you wish to import.
    IID is a universally unique identifier (UUID) that uniquely identifies a particular COM interface. IID should be specified as a string of hexadecimal numbers with the following format:
    {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
    Then you MUST press the Load button to enforce the IDE to load COM information from the COM module that embeds the interface with the specified IID.
    Really you can specify an IID registered to any interface embedded into the same COM module that embeds the interface you wish to import. (Later you will be able to specify the required COM component (or interface) in the list box in the [#Import_Group_Box Import] group box.)
    In the system registry database you can find all registered IIDs under:
    HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface

Creating a Interface

How to Create a New Interface?

An interface definition defines the named object type. All predicates declared in an interface are object members in objects of the interface type. To create a new interface and to add it into one of the packages registered in the project you should activate the File | New IDE command. In the left pane of the opened Create Project Item dialog you should select Interface. Then the dialog accepts the following shape:

The New Interface Dialog

Name:

In the Name edit control you should type in an interface name (the interfaceName on the picture).

Package:

In the Package list button you should select one of the packages registered in the project (the NewPackage.pack on the picture). The created interface will be included into this package. The created file with the default declaration of this interface will be placed into the selected package subdirectory. This subdirectory name is displayed after the package name; it is (NewPackage\) in the picture.

After you fill in all required settings you can press the Create button. The IDE creates the interface definition file (it appears in the project tree in the Project Window after compilation of the package) and the #include @"NewPackage\interfaceName.i" directive is added into the package header file NewPackage.PH of the specified package:

% exported interfaces
#include @"NewPackage\interfaceName.i"

Since the package header file should be inserted by the #include @"NewPackage.ph" directive in all places, where the package is used, so in all these places the #include @"NewPackage\interfaceName.i" directive also be seen. This means that the interface interfaceName is public.

If you wish to create an interface that should be private to the NewPackage package, then the include directive for this interface can be manually moved into the package implementation file NewPackage.PACK:

% private interfaces 
#include @"NewPackage\interfaceName.i"

Therefore, the interface declaration will not be seen outside of the package implementation. So the interface will be private to the package implementation.

Notice that information about a new interface does not appear in the project browse information until the package including this interface is compiled.

Creating a Class

Creating a Text File

Creating a Resources