Ask Dr. DePhobia - Questions and Answers about Clarion

By Jim DeFabia

Posted December 1 1998

Printer-friendly version

Q:

Do you have an example of how to enable or disable a main menu option on the application frame from another procedure? I am having trouble getting this to work.

A:

What we have here is a failure to communicate. Ahem... I mean, what you have to do is set up a means of communicating with the frame procedure from the child procedure. This involves three parts:

1. Store the frame's thread number so you know in which thread you will get the message.

2. Create user-defined events for the frame. You'll enable/disable the menu item based on these events.

3. Send the events to the frame using POST to tell the frame to enable/disable the menu item.

First, define a global variable (Press the Global Properties button, then press the Data button). Call this GLO:MainThreadNo and make it a BYTE.

data.gif

Next, declare two new event EQUATEs in the Global Properties, Global Data embed point:

EVENT:DisableCustomerItem EQUATE(401h)

EVENT:EnableCustomerItem EQUATE(402h)

(Note: user-defined events must start after 400h.)

Next, in the Frame procedures find the Local Objects, ThisWindow (WindowManager), Init procedure, CODE, Initialize the procedure embed point [Priority 6,001]. Insert the following code:

GLO:MainThreadNo = THREAD()

This stores the frame's thread number in the global variable. Whenever an MDI procedure is STARTed, a thread number is allocated to it. We need the thread number in order to post a message to the frame procedure.

init.gif

Now, still in the frame procedure, find the Local Objects, ThisWindow (WindowManager), TakeWindowEvent procedure, CODE, CASE EVENT() embed point [Priority 7,550]. Insert the code to handle the two user-defined events that the frame procedure will receive. This embed point places the code inside the CASE structure which handles events.

OF EVENT:DisableCustomerItem
  DISABLE(?ShowCust)
OF EVENT:EnableCustomerItem
  ENABLE(?ShowCust)

Embed.gif

Now to disable/enable it from another procedure, embed the following code at the point where you want to control the menu (e.g., the Window events--OpenWindow and CloseWindow):

POST(EVENT:DisableCustomerItem,,GLO:MainThreadNo)

or

POST(EVENT:EnableCustomerItem,,GLO:MainThreadNo)

Note that the second parameter is omitted ("comma comma").

Why store the Frame's thread number - surely it would always be number 1?

Well it might NOT be the first thread in the application.

Q:

I wrote an application to interface with an ODBC data source. I imported the files and made the application. It appears to work fine until I try to change a record. When I press the OK button, it reports an Error 33--Record not Available. I know it is available, I just saw it! What am I missing?

A:

You are missing a unique identifier. The ODBC driver must have a means to identify the record. This is a KEY with the correct components to ensure a unique value.

If you imported the file and such a KEY does not exist, merely add it or add a second component to make the key unique. Remember that the KEY in your Clarion dictionary does not need to exactly match the indexed fields in the ODBC data source.

Many ODBC data sources contain KEYs with only the linking fields; therefore the child files do not have a unique KEY. For example, I imported the data source from the Deluxe CD player included with Windows 98 Plus. This data source contains audio CD data from my CD collection (and automatically adds records from the master data file on the Internet when I play a new CD). The two main files are Titles and Tracks. The Titles file has a unique KEY on TitleID (a number which identifies the CD). The Tracks file only has a KEY on TitleID. Since this file has many records for each title (there are usually many songs on an album), this is NOT a unique KEY. To make it unique, I only had to add TrackID to the KEY and flag it as unique. This allowed my application to update the data.

Changing the KEY of an SQL accelerator file definition does not require any data conversion, so this does not affect the manner in which the original application interfaces with the data. In fact, you can add KEYs to sort the data in different orders than the original database designer had in mind. In the Deluxe CD Player database, I added a KEY to sort my Music CDs by Artist and Title.

Q:

How do I add a comment to my Redirection file?

A:

The comment delimiter in the Redirection file is a double-hyphen (--). For example:

[Common]
*.dll = .;%ROOT%\bin
*.tp? = %ROOT%\template
*.trf = %ROOT%\template
*.txs = %ROOT%\template
*.stt = %ROOT%\template
*.* = .; %ROOT%\libsrc; %ROOT%\template; %ROOT%\convsrc
*.lib = %ROOT%\lib
*.obj = %ROOT%\lib
*.res = %ROOT%\lib
-- The next line includes my graphics directory
*.jpg = d:\graphics

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

Article comments

Post a comment

You must be logged on to post comments.

Clarion Roadmap

Try the roadmap (beta)

Search ClarionMag

 

Advanced search

From the archives

Superfiles and NAME

9/14/2009 12:00:00 AM

Having covered Superfiles in the previous episode, Steve Parker tackles the intricacies of how to set arbitrary names for the tables inside Superfiles.