Ask Dr. DePhobia - Questions and Answers about Clarion

by Jim DeFabia

Published 1997-09-01    Printer-friendly version

Question:

I've got a small image database program using a BLOB field to store the image. Everything works great with displaying my images as long as the user includes it when the record is created. But, if a user adds a record without an image and goes back later to update the record to include an image, it is not saved. It seems you only get one chance to save the image to the BLOB. If you don't add it the first time around, you're out of luck. Can you help?

Answer:

You noticed that the picture has changed, but the program didn't? That was very observant of you, now let's improve your program's observational skills.

The problem you see is due to the fact that the BLOB is actually outside of a RECORD structure. This means that a change to the BLOB does not mean a change to the "RECORD." You have to let the SaveButton control template know about the change so it knows to write the record to disk.

When you open a Form, the template saves the current RECORD to SAV::PRE:RECORD (where PRE is your file's prefix). Later, it compares SAV::PRE:RECORD to PRE:RECORD. If they are different, it sets the RecordChanged variable to TRUE. The value of this variable determines how it proceeds when the OK button is pressed. If it is FALSE, no updates are made to the file (or files depending on referential integrity settings). If it is TRUE, the RIUpdate:FileName FUNCTION is called (where FileName is the name of the file in use).

The solution to your problem is actually very simple, when a picture changes, set a flag to indicate the picture has changed. Next based on that flag, update the RecordChanged flag after the generated code does its check.

This requires a local variable and two bits of embedded code:

  1. Create a local variable: PictureChanged BYTE
  2. For the control where the user assigns a picture to the image, in the Control Event Handling, After Generated Code, Accepted embed, add the code PictureChanged = TRUE. This should follow your assignment of the graphic file to the Image and the assignment of the IMAGE to the BLOB.
  3. In the Before call to RIUpdate if Record Changed embed point, add this code:
  4. IF PictureChanged = TRUE
      RecordChanged = TRUE
    END
    

Question:

How do I use the ORDER expression to change the display order of the VIEW? It seems that this can be done with any VIEW components at any level of the JOIN regardless of the KEY. Unfortunately when I modify the generated source to add the ORDER expression, the browse box ends up empty.

Normally, I simply use a key to sort the records. In this case there are three files in a many to many relationship and not all fields are available for sorting. This is a normalized database. What can I do?

Answer:

This is exactly why PROP:Order was born. It allows you to sort without hurting your database normalization. The PROP:Order property assignment handles the ordering of the VIEW, but afterwards, you must refill the LIST control.

  1. First make sure the fields are in the VIEW structure by adding them as "hot fields" in the Actions for BrowseBox control template.
  2. Then add the code to change the order, SET the VIEW, and refill the BrowseBox control:
BRW1::View:Browse{PROP:Order} = 'Mem:LastName,MEM:FirstName'
!where the right side of the statement is the list of
!fields to you want to use for sorting
SET(BRW1::View:Browse)
DO BRW1::RefreshPage

Question:

I have looked through some of the examples that are included with Clarion and see in several places Icon files beginning with a tilde (~). In other places, I see a tilde preceding a Window's HelpID. What does the tilde mean? I know that it is not part of the filename.

Answer:

These are two different uses of the tilde. When used at the beginning of a HelpId, it indicates that the reference is a ContextString instead of a Keyword. This causes the help engine to jump to a single topic identified by that unique context string. A Keyword is non-unique and is the list of words that appear in the list on the Index Tab.

The use of a tilde before a graphic filename indicates that it is an internal resource. The tilde means that the program should find the item as a "linked in" resource, not as an external file. Graphics files, such as icons, are linked into the project in one of two ways. Most commonly, they are linked in because they are part of a WINDOW structure. Any graphics files specified inside the WINDOW structure are automatically linked into the project. Once they are linked in, they can be referenced by their name with a tilde prepended in property assignments.

The other method to link a resource into the project is through the Project editor.

  1. Open the Project Editor by pressing the Project button from the Application Generator.
  2. Highlight Library and object files and click on the Add File button.
  3. Select the bitmap, icon, or metafile graphic from the standard Open File dialog.
  4. Press the OK button to return to the Project Editor dialog.

Printer-friendly version

Reader Comments

To add a comment to this article you must log in.

 
 

Search

 

Advanced Search
Topical Index

Related Articles

Subscribe to
ClarionMag

One year: $169

(includes all back issues since '99)

Renewals from $119

Two years: $269

Renewals from $219

More Info

Subscribe Now!

ClarionMag Blog

RSS Feeds

Updates via Email

Enter your Email


Powered by FeedBlitz

Quick Links