Object repository)

Source: Internet
Author: User

Object repository is a method by which users can select pre-defined objects and apply them to their own applications. The object library can do the following:

  • Select a predefined application, form, or dialog box for your application.
  • Add your own forms, dialog boxes, and applications to the object library.
  • Add other objects to your applications, such as adding ASCII text files and additional source code units.
  • Data Modules)
  • Create component)
  • Create a new packages)
  • Create a new ActiveX control or activeforms.
  • Call the Wizard to create a dialog box or application.

The above is only a selective introduction. Apart from the objects listed above, you can also create other objects.

1. Object repository pages and options)

Select 【File | newThe object library is automatically displayed, for example, the object library window that appears when the project is not opened:

Note

It may seem a little strange at first. The object library title is "new items", and the Object Library configuration dialog box is "Object repository", but this "new items" is the object library window.

The Object Library has several option pages. Each page contains different objects. As you can see, the new page is selected at first, and the simple descriptions of each page of the Object Library are listed below.

Object Library page
  • New -- allows you to create a new application, form, or unit for your application. You can also create advanced objects, such as packages, DLLs, components, NT server applications, web server applications, and data modules.
  • ActiveX: allows you to create new ActiveX controls, type libraries, COM objects, activeforms, and other ActiveX objects.
  • Multitier: enables you to create a CORBA and MTS object and a data module (applicable only to the customer/Server version ).
  • Forms: allows you to create standard forms using pre-created forms (such as the about window, dual-List window, and tabs.
  • Dialogs -- provides several basic dialog box types for users to choose from, and also includes dialog wizard.
  • Projects -- lists all projects available for selection. You can select one of them to create an application, which also contains the Application Wizard.
  • Data Modules-enables users to select data modules in applications.
  • WebServices: allows you to create SOAP server applications and data modules.
  • Web documents: allows users to create standard HTML, XSL, WML, XHTML, and other webpage texts.
Note

If you call "Object repository" when a project has been opened, an additional tab is displayed. The tab name is the name of the current project. Click this tab to display a page that includes all objects of the current project. You only need to simply select from object repository to quickly reuse a form or other objects. For example:

Note

Object repository is also known as Gallery ).

There are three single-choice buttons at the bottom of each page, marked with copy, inherit, and use, respectively. They determine the implementation method of the selected object. Depending on the selected object, some radio buttons may become grayed out (invalid ). For example, when the new page is displayed, all three buttons are dimmed. This is because copy is the only available option on the new page. Therefore, Delphi dimmed all buttons and automatically used the copy option.

(1) Copy button

When you select the copy button, Delphi creates a copy of the selected object and places it in your application. At this time, you can freely modify the copy object, when you modify this object in the application, the original object in the repository will not change.

For a more intuitive understanding, you can make an example: there is a table (for example, a work schedule), you want to fill in the Schedule content, but you cannot fill in the original table directly (if you fill in the original table, this table cannot be used repeatedly. Instead, you should copy the original table and save the original table for future use.

You can fill in the copied form. This is the reason for copying objects in the object library. You can modify and copy the original without changing it. Copying is the safest way to use objects.

(2) inherit button

Inherit is similar to copy, but the biggest difference between the two is that the new inherit object is connected to the original object. If you modify the original object in the library, the new object will change the same as the new object. In turn, this is not true. Users can modify new objects without changing the original objects.

To understand the usage of this type of object, for example, information management personnel often use a spreadsheet program to create a workbook data table and use it in a word processing program to create a report. When pasting or importing a workbook from the clipboard to a word processing program, they typically selectively link the data to the workbook. In this way, the word processing document will change when the electronic data table is modified.

Similarly, when the original form is changed, all the inherited forms are changed. When multiple forms are derived from one public form and must be modified in some places, the inherit option is available. Any modification to the original form is reflected on the inherited form.

(3) Use button

The use option is not generic. When a user uses an object, that is, the object is directly opened for editing. Select this option when you store an object in the object library and make permanent changes to the object. As mentioned in the "inherit button", modifications to the original form will be reflected on all inherited forms. To change an original form, use the use option to open it.

(4) use the Object Library (using the object repository)

What happens when a user selects an object from object repository? This depends on multiple factors. This includes the type of the selected object, whether the project is enabled, and the type of use (copy, inherit, or use) selected by the user ).

If you open an application and select to create a new application from object repository, the system will prompt you to save the current project before displaying the new project.

Tip

Select File | new | application from the main menu to start a new application. It is equivalent to selecting the new menu item from the main menu, and then selecting the application object from the object repository. Similarly, the new form item on the main menu is a simple method to start a new form.

When you use Object repository to create a new form, you can open or not open the project in different ways. If you open the project, the new form is added to the application as a form and corresponding form unit. If you do not open the project, the new form and form unit are created as independent forms. A form other than a project must be added to the project before it can be used in the running stage. This option is used when you want to create a new basic form that is added to the object library.

If you choose to create a new unit or text file, it is easy to use code editor to create a new file (if it is a new unit, add it to the current project ). There are multiple reasons for creating a new text file. For example, you need to add a configuration file (INI file) to your application ), you can create a new text file in Object repository to create the configuration file. Whenever a new unit is created, the user starts a new source file for the user's application, and the source file is irrelevant to the form (such as including the file ).

Selecting a new dll will create a new project, which is used as the DLL. When creating a new build or thread object, a dialog box is displayed asking for details about the object to be created.

(5) The object repository views)

In fact, the object library window is a Win32 List View Control (listview control), which is similar to the right half of Windows Resource Manager. Multiple viewing views are available for users to choose from: Large icons, small icons, list, and details. The missing time view is large icons. To change the view of the object library, right-click the object repository and select the view style, as shown in:

The object repository shortcut menu also provides different arrangement methods, which can be arranged by name, description, date, or author.

2. Use the object library to create a new object (creating new objects from the object repository)

Undoubtedly, the most basic purpose of the Object Library is to create a new object with the object in the library. For better understanding, follow the steps below to create a simple application, which has a main form, an about dialog box, and a next form.

(1) Close all projects, select file | new from the main menu, and select Application in Object repository. a blank form is displayed after the new application is created.

(2) place the two buttons in the form, set the caption attribute of one button to "about", and set the caption attribute of the other button to "display form2". If necessary, you can also change the name attribute of each button. For example:

(3) Select File | new from the main menu to display the object repository again. Click the forms tag and select the "about box" object to ensure that the copy button is selected, as shown in. Click "OK" to create a new about form. The about form is displayed quickly and can be modified as needed (such as entering your own information, changing the icon, size, and position of the form ).

The about window is as follows:

(4) Select File | new from the main menu. The object repository is displayed for the third time. Click the forms tag, select the "dual list box" object, and click OK. The dual list box window is as follows:

(5) Compile the event handler for the two buttons as required (one button shows the about form, and the other shows the dual list box form ). Do not forget to add the units of the about form and dual list box form to the uses of the main form. The Code is as follows:

uses UAboutBox, UDualListDlg;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin  AboutBox.ShowModal;end;procedure TForm1.Button2Click(Sender: TObject);begin  DualListDlg.ShowModal;end;

(6) Compile and run the program and test the program.

This program does not do anything. It shows you how to use Object repository to quickly develop application prototypes.

The above code passes the test in Delphi7. Download the sample code:Create a new object. rar

3. Add an object to the object library (adding objects to the object repository)

If the user's exclusive permission cannot be added to the object repository, the object repository effect cannot be displayed. You can add your own object to the object repository, and you should also do this. Adding common objects to object repository can improve work efficiency and become a more valuable programmer.

After creating an application, form, or other object, you can store it in the object library and use it as needed. Of course, there is no need to store every form created in the object library, and store frequently used in the object library.

You can add objects to the object library during normal application development, or create objects for adding objects to the object library. For example, when creating an about dialog box during application development, the user suddenly feels that the about dialog box should be saved for use in all programs, after all, it contains all company names, identifiers, and all copyright information. There is no need to recreate the same about dialog box for each application. To do this, you can simply add it to the object library.

To add a form to the object library, first save it. Right-click any part of the form and select the add to repository menu item from the Form Designer shortcut menu. The following dialog box is displayed:

The add to repository dialog box lists the current form and other objects (such as data modules) in the application in the forms list box on the left ). First, select the form to be added to the object repository.

Note

The current form in Form Designer has been selected in the forms list box in the add to repository dialog box.

Now enter the Object Name (title), which is displayed below the object icon in Object repository. In the description edit box, enter the description of the object. This information is displayed when the view in the object repository is details. The author of the input object in author.

Note

In the Delphi Object Library, the authors of most pre-created objects are named "Borland ".

In the page editing box, select the object repository page for storing objects. You can select an existing page or enter a new page in the page editing box. If the entered Page name does not exist, Delphi will create a new page. Click the browser button under the dialog box to select an icon for the new object.

After entering all the fields, select the icon and click OK to add the object to the object library. From the above process, it can be seen that adding objects to the object library is as easy as using objects.

Caution

When an object is added to the object library, Delphi adds an entry to the object library file to describe the object. This includes the path name of the object's form and directory where the source file is located. If you move or delete an object's form or source file, you cannot use the object from the object library.

4. Add a project to the object library (adding projects to the object repository)

There is no big difference between adding a project to the object library and adding a single form to the object library. To add a project to the object library, select project | add to Repository from the main menu to bring up the Add torepository dialog box (this dialog box is similar to the dialog box for adding objects to the object library, but there is no form list box); enter the required information (name, description, author, etc.), click OK to add the project to the object library. For example:

After you are familiar with Delphi, you should create an application shell that contains the most common features of the application. Each time you create a standard application, copy the application shell from the object library. You can create menus, toolbar, about dialog boxes, and other standard dialogs in the application shell in advance, which will be convenient for later use. After the application is created, you can modify it, such as adding a form or deleting a form that you do not want.

5. Object repository housekeeping)

The page and Object Management in the object library are done by using the object library configuration dialog box.

You can select the [tools | repository] menu item from the main menu or select the "properties" menu item from the shortcut menu of the Object Library to open the configuration dialog box for production, for example:

In this dialog box, you can delete objects and pages in the object library, move objects from one page to another, and change the order of pages in the object library. The pages in the object library are listed in the pages list on the left of the dialog box. The objects list box on the right of the dialog box lists the objects contained on the current page.

Note

The pages list box has two special notes. First, the new page (when calling the object library, it is always displayed in the first position) not in the list box (ActiveX and multitier pages are not in the pages list box ). The new page is fixed and cannot be changed. Note that the pages list contains an [Object repository] item. This item is actually a list of all projects on all pages of the Object Library.

(1) Object Management (managing objects)

You must select an object before you can mark, delete, or move an object. When selecting an object, click the object in the objects list box. After selecting the object, click "Edit object ..." Button to edit the object. When editing an object, you can change the object name, description, author information, and object page. For example, the "Edit object Info" dialog box is displayed.

Tip

To edit an object quickly, double-click the object in the objects list box.

You can delete an object by selecting an object and clicking the delete object button. Before deleting an object, the system prompts "whether to delete the object". After confirmation, the object is deleted. For example:

Note

Deleting an object from the object library removes the object from the object repository file and does not appear on any page of the Object Library. However, the form file and source file of the object are not deleted from the disk.

To move an object from one page to another, move the object from the object list box to a page position in the page list box with the mouse.

(2) Management pages)

In the object library configuration dialog box, you can also add, delete, or move the object library page. To delete a page, you must first delete all objects on the page, then click the Page name in the page list box, and click "delete page". Delphi first checks whether the page is empty, if the page is blank, Delphi will delete it from the object library.

Click "add page" to add a new page to the object library. A dialog box is displayed, asking you to enter the new page name. after entering the Page name, click OK. The new page will appear in the page list box. For example:

The page name is similar to this. Select a page and click "RENAME page". A dialog box is displayed, prompting you to enter a new page name. For example:

The order of the page in the object library can be changed. to change the order of a page, click the Page name to make it brighter, and then click the up or down arrow at the bottom of the page list box, move the page up or down. You can also drag the page to a new location.

(3) setting default forms and projects)

In the object library configuration dialog box, you can set the following three default objects:

  • Default form used when you select the file | new | form menu item from the main menu
  • Select File | new | application from the main menu as the default form of the main form.
  • The default project used when you select the file | new | Application menu item from the main menu.

Different check boxes are displayed under the object list box based on the selected object. If you select a form, the new form and main form check boxes are displayed. If you select a project, the new project check boxes are displayed, such:

 

Setting a form or project as the default is easy. For example, to set a main form as the default main form of the new application, you can select the form from the object list box, select the "main form" check box, and click OK. Since then, this main form has become the default main form. Similarly, to set a project as the default project, find the project in the object library configuration dialog box, click it, select the "new project" check box, and click OK. From then on, you only need to select [file | new | application] from the main menu, and the default project will be displayed.

Note

If you accidentally set a form to the default form for creating an application, you can check every form in the object library configuration dialog box. There must be a form to make the "main form" check box selected, at this time, it is changed to the deselected state, and everything will return to normal. These also apply to the default project. Check the projects page and find the project selected by the "new project" check box.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.