Ask Dr. DePhobia - Questions and Answers about Clarion

by Jim DeFabia

Published 1999-02-01    Printer-friendly version

Q:

I want to allow users to copy an existing record in a list. Is there an easy way to copy a record?

A:

Yes, and you can even copy this code to do it!

I am assuming that you are using the ABC templates (if you aren’t, you should be). The ABC library is the mechanism that makes this easy.

I am also assuming you are using a BrowseBox control template with the BrowseUpdateButtons control template.

1. First, you’ll need a local variable in the Browse procedure. This variable is used as a flag to indicate whether or not a record that is being inserted is a copy or a new (blank) record. This should be a BYTE. Let’s call it LOC:CopyFlag.

x.gif

2. Next, the Browse Procedure needs a button that the user will press to copy a record. Populate a button on the WINDOW. Lets call it ?Copy.

3. Double-click on the button to see its embed points.

4. In the EVENT:Accepted for the ?Copy button embed point, add this code:

LOC:CopyFlag = TRUE           !Flag as a copy
POST(EVENT:Accepted,?Insert)    !Press the Insert button

copycode.gif

5. In the BRW1.PrimeRecord method (the Embeditor is best for this) add the following code -before- the PARENT.PrimeRecord call:

IF LOC:CopyFlag
       SuppressClear = TRUE !Suppress record CLEARing
END

suppress.gif

This suppresses clearing of the record buffer so new records appear with the values from the current record.

6. Finally, you’ll reset the flag. In the BRW1.PrimeRecord method (once again, the Embeditor is best for this) add the following code -after- the PARENT.PrimeRecord call:

LOC:CopyFlag = FALSE !Turn off the copy flag

That’s all there is to it!

Now when a user presses the Copy button, the new record will take on the values from the last current values in all fields, except any auto-number fields. This is exactly what you want, because it respects the integrity of your database design. Good news, huh? Well here is some even better news. This technique works when you are using a form for updates or when you are using edit-in-place. You don’t need to change a thing!

Q:

I want to display a list in reverse order of the key. I know I could make a descending key, but the data file cannot be converted because it must continue to work with a legacy system. Is there any way to display a list in descending order without a descending key?

A:

Well, you could turn everyone’s monitor upside down when they are not looking, but then they couldn’t read their e-mail. A better way would be to display the list in a custom sort order using a "key-less" browse.

  1. On the Actions tab of the BrowseBox control template, specify the file, but no KEY.
  2. In the Additional sort fields, specify the key components fields you want to use for the sort order and prepend a minus sign to indicate reverse order.

The Additional Sort Fields sets the ORDER for the VIEW. Remember that this is a comma separated list.

Browse.gif

Q:

I unregistered some of my file drivers in the Database Driver Registry. Now I am trying to add them again. I press the Add button and a file dialog appears, but no files display? Where are my file drivers?

A:

Where, oh, where have my file drivers gone? Oh where, oh where can they be?

The solution is really quite simple. In Windows 95/98/NT, Explorer has a setting allowing you to set the manner in which files display. One of these settings is to Hide System Files. When this is enabled, DLL files do not display. Since database drivers are DLLs, they won’t appear.

1. From Windows Explorer, choose View => Folder Options.

2. On the View Tab, check the View All Files box.

3. Your database driver will now appear in the filedialog.

showall.gif

Submit your questions to jim-d@topspeed.com (please mention this column when submitting your questions).

Printer-friendly version

 
 

Search

 

Advanced Search
Topical Index

Related Articles

Subscribe to
ClarionMag

One year: $184

(includes all back issues since '99)

Renewals from $134

Two years: $274

Renewals from $224

More Info

Subscribe Now!

ClarionMag Blog

RSS Feeds

Updates via Email

Enter your Email


Powered by FeedBlitz

Quick Links