Сделай Сам Свою Работу на 5

Creating modeless forms such as windows





Using the Object Repository: Overview

The Object Repository (Tools|Repository) makes it easy share forms, dialog boxes, frames, and data modules. It also provides templates for new projects and wiz­ards that guide the user through the creation of forms and projects. The Repository is maintained in DELPHI32.DRO (by default in the BIN directory), a text file that con­tains references to the items that appear in the Repository and New Items dialogs.

Sharing items within a project

You can share items within a project without adding them to the Object Re­pository. When you open the New Items dialog box (File|New|Other), you'll see a page tab with the name of the current project. This page lists all the forms, dialog boxes, and data modules in the project. You can derive a new item from an existing item and customize it as needed.

Adding items to the Object Repository

You can add your own projects, forms, frames, and data modules to those al­ready available in the Object Repository. To add an item to the Object Repository,

1 If the item is a project or is in a project, open the project.

2 For a project, choose Project|Add To Repository. For a form or data module, right-click the item and choose Add To Repository.

3 Type a description, title, and author.

4 Decide which page you want the item to appear on in the New Items dialog box, then type the name of the page or select it from the Page combo box. If you type the name of a page that doesn't exist, the Object Repository creates a new page.

5 Choose Browse to select an icon to represent the object in the Object Re­pository.

6 Choose OK.

Sharing objects in a team environment

You can share objects with your workgroup or development team by making a repository available over a network. To use a shared repository, all team members must select the same Shared Repository directory in the Environment Options dialog:

1 Choose Tools|Environment Options.

2 On the Preferences page, locate the Shared Repository panel. In the Direc­tory edit box, enter the directory where you want to locate the shared repository. Be sure to specify a directory that's accessible to all team members.



Using an Object Repository item in a project

To access items in the Object Repository, choose File|New|Other. The New Items dialog appears, showing all the items available. Depending on the type of item you want to use, you have up to three options for adding the item to your project: copy, inherit, use.

Copying an item

Choose Copy to make an exact copy of the selected item and add the copy to your project. Future changes made to the item in the Object Repository will not be reflected in your copy, and alterations made to your copy will not affect the original Object Repository item.

Inheriting an item

Choose Inherit to derive a new class from the selected item in the Object Re­pository and add the new class to your project. When you recompile your project, any changes that have been made to the item in the Object Repository will be reflected in your derived class, in addition to changes you make to the item in your project: Changes made to your derived class do not affect the shared item in the Object Re­pository.

Using project templates

Templates are predesigned projects that you can use as starting points for your own work. To create a new project from a template:

1 Choose File|New|Other to display the New Items dialog box.

2 Choose the Projects tab.

3 Select the project template you want and choose OK.

4 In the Select Directory dialog, specify a directory for the new project's files.

The template files are copied to the specified directory, where you can modify

them. The original project template is unaffected by your changes.

Modifying shared items



If you modify an item in the Object Repository, your changes will affect all fu­ture projects that use the item as well as existing projects that have added the item with the Use or Inherit option. To avoid propagating changes to other projects, you have several alternatives:

Copy the item and modify it in your current project only.

Copy the item to the current project, modify it, then add it to the Repository under a different name.

Create a component, DLL, component template, or frame from the item. If you create a component or DLL, you can share it with other developers.

Specifying a default project, new form, and main form

By default, when you choose File|New|Application or File|New|Form, a blank form appears. You can change this behavior by reconfiguring the Repository:

5 Choose Tools|Repository.

6 If you want to specify a default project, select the Projects page and choose an item under Objects. Then select the New Project check box.

7 If you want to specify a default form, select a Repository page (such as Forms), them choose a form under Objects. To specify the default new form

(File|New|Form), select the New Form check box.. To specify the default main form for new projects, select the Main Form check box.

4 Click OK.

Developing the application user interface: Overview

When you open the IDE or create a new project, a blank form is displayed on the screen. You design your application's user interface (UI) by placing and arranging visual components, such as windows, menus, and dialog boxes, from the Component palette onto the form.

Controlling application behavior

TApplication, TScreen, and TForm are the classes that form the backbone of all applications by controlling the behavior of your project. The TApplication class forms the foundation of an application by providing properties and methods that en­capsulate the behavior of a standard program. TScreen is used at runtime to keep track of forms and data modules that have been loaded as well as maintaining system- specific information such as screen resolution and available display fonts. Instances of the TForm class are the building blocks of your application's user interface. The windows and dialog boxes in your application are based on TForm.

Working at the application level

The global variable Application, of type TApplication, is in every VCL- or CLX-based application. Application encapsulates your application as well as provid­ing many functions that occur in the background of the program. For instance, Appli­cation handles how you call a Help file from the menu of your program. Understand­ing how TApplication works is more important to a component writer than to devel­opers of stand-alone applications, but you should set the options that Application handles in the Project|Options Application page when you create a project.



Using the main form

The first form you create and save in a project becomes, by default, the pro­ject's main form, which is the first form created at runtime. As you add forms to your projects, you might decide to designate a different form as your application's main form. Also, specifying a form as the main form is an easy way to test it at runtime, because unless you change the form creation order, the main form is the first form displayed in the running application.

Hiding the main form

You can prevent the main form from appearing when your application starts by using the global Application variable.

To hide the main form at startup:

1 Choose Project|View Source to display the main project file.

2 Add the following code after the call to Application.CreateForm and before the call to Application.Run.

Application.ShowMainForm := False;

Forml .Visible := False; {the name of your main form may differ }

Adding forms

To add a form to your project, select File|New|Form. You can see all your pro­ject's forms and their associated units listed in the Project Manager (View|Project Manager) and you can display a list of the forms alone by choosing View|Forms.

Linking forms

Adding a form to a project adds a reference to it in the project file, but not to any other units in the project. Before you can write code that references the new form, you need to add a reference to it in the referencing forms' unit files. This is called form linking.

Avoiding circular unit references

When two forms must reference each other, it's possible to cause a "Circular reference" error when you compile your program. To avoid such an error, do one of the following:

Place both uses clauses, with the unit identifiers, in the implementation parts of the respective unit files. (Thisjs what the File|Use Unit command does.)

Place one uses clause in an interface part and the other in an implementation part. (You rarely need to place another form's unit identifier in this unit's interface part.)

Managing layout

At its simplest, you control the layout of your user interface by where you place controls in your forms. The placement choices you make are reflected in the control's Top, Left, Width, and Height properties. You can change these values at runtime to change the position and size of the controls in your forms.

Controls have a number of other properties, however, that allow them to auto­matically adjust to their contents or containers. This allows you to lay out your forms so that the pieces fit together into a unified whole.

Using forms

When you create a form from the IDE, Delphi automatically creates the form in memory by including* code in the main entry point of your application function. Usually, this is the desired behavior and you don't have to do anything, to change it. That is, the main window persists through the duration of your program, so you would likely not change the default behavior when creating the form for your main window.

However, you may not want all your application's forms in memory for the du­ration of the program execution. That is, if you do not want all your application's dia­logs in memory at once, you can create the dialogs dynamically when you want them to appear.

Forms can be modal or modeless. Modal forms are forms with which the user must interact before switching to another form (for example, a dialog box requiring user input). Modeless forms are windows that are displayed until they are either obscured by another window or until they are closed or minimized by the user.

Creating modeless forms such as windows

You must guarantee that reference variables for modeless forms exist for as long as the form is in use. This means that these variables should have global scope. In most cases, you use the global reference variable that was created when you made the form (the variable name that matches the name property of the form). If your ap­plication requires additional instances of the form, declare separate global variables for each instance.

 








Не нашли, что искали? Воспользуйтесь поиском по сайту:



©2015 - 2024 stydopedia.ru Все материалы защищены законодательством РФ.