Want Tabs

Word Wrap

The WantTabs property is an interesting by-product of the Windows world. The Tab key is commonly used for navigation purposes in an application and especially for moving among the fields of a dataset. A user attempting to place a tab character into the text of a DBMemo would find that he had suddenly exited the field with the keystroke. The WantTabs property can be set to True to allow the application to accept the tab characters literally in the DBMemo text. In this state, the user will be able to tab into the control but not out of it. If this property is used, it will be necessary to explain this behavior and the workaround to your users so that they do not become confused and frustrated.

Word Wrap

DBMemo Events

The formatting property WordWrap allows the control to wrap text at its right margin when displayed. Setting this property to True places soft returns into the displayed text so that it does not run off the edge of the control. The returns are for display purposes only and do not affect the stored text. When this property is True, no horizontal scroll bar is needed.

DBMemo Events

An important event for the DBMemo control as well as the other edit controls is the OnChange event. This event fires whenever the Text value of an edit control changes. The event is triggered after the Text property of the control has been updated and gives the application its first opportunity to respond to changes in the text. Before responding through the event handler, it is suggested that you query the Modified property to determine if a change truly occurred.

Putting] DBMemd and DBImage\ td Work

The Venue Manager application is going to undergo some serious - novation! after having served us well for several pages. We are going td) modify the Venue Manager to put these two controls through their paces. Each of the tables that are used by the application has Memo and Image fields within them that lend a lot to the program. Figure 6.7 shows the modified Venue Manager as it will appear after the follovl^lngj modifications have been applied.

Adjust the width of DBG rid 1 to approximately the size of the three displayed columns and the scroll bar and move it to the left as shown in the picture. Add a DhImage component to the form, placing it to the right of DBGrici 1J

Adjust the size of the con troll so that its height measurement is the same as that of the Venue grid. Set the width so that it fills out the space comfortably Depending on the size of your form, the image should be roughly rectangular. Set the DataSourcd property to DataModulel.VENUESRC] and the Data Fie ld| property to Venue-Map. Use the Stretch property to have the different-sized images display in the DBImagej control by setting the property to True. We are not going to worry about the distortion of the image in this application, though it should not be discounted for others.

Chapter 6—Delphi's Data-Aware Components ■ I

3. Add a DBMemo control to Forml just below the DBImage component Set the DataSource property to DataModule 1 .VENUE SRC and the DataField property to Remarks. Set the width to the same size as the image control and the height to display about six lines of text. We are going to leave the WordWrap property set to True so the only scroll bar we will need is a vertical one. Set the ScrollBars property to ssVertical to add this attribute.

Execute the modified application and scroll through several rows of the database. The images are small so they display quickly in this application but you should always take into consideration that this is not always the case. If the images are large and of high quality, consider setting the AutoDisplay property to False to improve the user's browsing speed. Speaking of the image, we see that the map is not of much use to us due to its limited size. Giving the user the ability to display a. small graphic image at a larger size is an excellent addition to an a cation such as this. We'll add this capability in the next steps.

  1. Add a new form to the project. Name this form EnlargedF and add a DBImage control. Set the Align property to alClient so that it fills all of the available area inside of the form. Save the new unit as EnlargU.pas.
  2. The application is going to take advantage of the sharing ability of the data module so we need to add that unit to the new form. Select the EnlargedF form and then select File | Use Unit and the dModU unit to include the code into the form's unit.
  3. Select the DBImage control and set the DataSource property to DataModulel.VENUESRC. This value is now available since the data module's unit was added to the Uses clause. Set the DataField property to Venue-Map and the Stretch property to True. The graphics that we are using are not of the highest resolution but they give us a good opportunity to experiment.
  4. One last thing must be done on the new form. When the image form is . closed, the resources should be released to the system. Add the following code to the form's OnClose handler:

procedure TEnlargedF.FormClose(Sender: TObject; var Action: TCIoseActi on);


  1. Rel ease; end;
  2. This form should not be displayed as a part of the application until it is called. For this reason, it should not be auto-created when the

178 ■ Part l/-The Delphi Database Tools application starts. Select Project) Options from the menu and move the EnlargedF form from the Auto-create list to the Available list.

6. Select the VenMgrU unit and modify the Uses line under Implementation to read:

uses dmodu, enlargeu;

7. The application is going to allow the user to click on the small image and receive an enlarged view of the same picture that would let them view the seating sections seating better. Press F12 to switch from the unit editor to the form. Double-click on the DBImage control so that you can modify the OnClick event handler and enter the following code:

procedure TForml.DBImagelCIick(Sender: TObject); begin

EnlargedF := TEnl a rgedF..Create (Appl i cation);

EnlargedF .Show;

8. Compile and execute your application. Click on the image displayed < from the database and you will be treated to the sight of a much larger version, Though the image quality causes these to pixelate when displayed, you are able to see the idea in action.

The use of the data module is what enables us to create this multiple form application so easily. Both forms are accessing a single dataset object so the record pointer is always synchronized without us having to write the complex code needed to manage independent table accesses.

Was this article helpful?

0 0

Post a comment