Ask Dr. DePhobia - Questions and Answers about Clarion

by Jim DeFabia

Published 1998-02-01    Printer-friendly version

Q:

I am lost. In Clarion 2.003; we had embed points for a BrowseBox for "No Records Found" and "Records found." Clarion 4 does not have these embed points and I don't know where to place my code. Can you help me find my way?

A:

Fear not. I will help you find your way in two ways. First, I'll give you directions on where to place your code (and the code to write).

Second, and more important, I will show you how to find a "new" embed point when you know the "old" one.

In Clarion 2.00x, some embed points would automagically write "wrapper" code around the embed points when the embed was filled.

For example in Clarion 2.00x, embedded code in theBrowser--No Records Found orBrowser--Records Found embed points, would cause the templates to write anIF..ELSE structure.

Now, there is a single embed point:

Browser Method Executable Code Section-
 -Browse on <file> using BrowseClass-
 -ResetQueue-
 -(BYTE ResetMode)

You are responsible to write the "wrapper"IF..ELSE structure code:

IF RECORDS(SELF.ListQueue)
!do something
ELSE
!do something else
END

This may be a little more work on your part (three extra lines of code to write), but the resulting code will be easier to read and maintain.

Another case of this is the embed to trap a double-click on a browse. In the legacy embed forBrowse Double-Click Handler, the templates wrote a structure when you added code in the embed point.

Now, we have an embed in theBrowser Method Executable Code Section--Browse on <file> using BrowseClass--TakeKey--(),BYTE where you are responsible to write the "wrapper"IF..ELSE..END andCASE..OF..END structure code:

IF RECORDS(SELF.ListQueue)
  CASE KEYCODE()
  OF MouseLeft2
    !do something
  END
END

Again, a bit more work at the front-end, but better in the long run.

Now for the important question:

Q:

How do you find a "new" embed point when you know the legacy embed point?

A:

From the Application Tree:

  1. Select Setup -> Application Options.
  2. Choose Show all and Generate all from the Action for Legacy Embeds drop-down list.
  3. Embed your code (or a ! comment) in the point you are familiar with in the Embedded Source dialog.
  4. Select Setup -> Application Options.
  5. Choose Show filled and Generate from the Action for Legacy Embeds drop-down list. This setting will generate the Embed Point and label it as "Legacy."
  6. Open the Embeditor (from the Application Tree, rt-click and select Source.)
  7. Find your code (or ! comment). Notice the embed point is noted as Legacy.
  8. Use cut-and-paste to move the code to the appropriate new embed point. You'll find it just above or just below to spot where your code is embedded.

Q:

I want a file dialog to select a directory. How can I do this in Clarion?

A:

First, the good news-it's simple in Clarion 4. The bad news-it isn't as easy in Clarion 2.003, but it's not too difficult either.

In Clarion 4, the FILEDIALOG has a fourth parameter that allows you to set a flag determining its behavior. This flag is an integer constant or variable containing a bitmap to indicate the type of file action to perform.

The bit numbers are:

Bit What it Does
0 If zero (0000b), the Open... dialog displays. If one (0001b), the Save... dialog displays.
1 If one (0010b), saves and restores the current directory path.
2 If one (0100b), doesn't report errors if the file does exist on Save... or does not exist on Open....
3 If one (1000b), returns multiple selections as a space-delimited string of filenames (with the full path on the first). Long filenames with embedded spaces are enclosed in double quotes.
4 If one (10000b), uses long filename dialog in 32-bit programs.
5 If one (100000b), displays a directory select dialog for selecting a directory path.

There are also EQUATES to make these bit values easier to use (and easier to remember).

FILE:Save       EQUATE(1)
FILE:KeepDir    EQUATE(2)
FILE:NoError    EQUATE(4)
FILE:Multi      EQUATE(8)
FILE:LongName   EQUATE(10H)
FILE:Directory  EQUATE(20H)

To use a FILEDIALOG to select a directory, you would write a line of code like:

FILEDIALOG('Select a Directory',VarToHoldDirName,, 100000b)

Another way of writing this uses the EQUATE declared in EQUATES.CLW:

FILEDIALOG('Select a Directory',VarToHoldDirName,,FILE:Directory)

An interesting note is the way bitmaps work. Since each bit is in effect a toggle (zero or one), EQUATES for bitmaps can merely be added together to combine them.

For example,

FILEDIALOG('Select a Directory',VarToHoldDirName,,FILE:Directory+ FILE:LongName)

Here's how to select a directory using the Windows API in Clarion 2.003 (32-bit only).

! In Global Embed, After Global Includes:

BROWSEINFO     GROUP,TYPE
hWndOwner        LONG
pIDLRoot         LONG
lpszDisplayName  LONG
lpszTitle        LONG
ulFlags          LONG
lpfnCallBack     LONG
iImage           LONG
               END

!Global Embed, Inside Global Map:

               MODULE('Shell32')
                 SHBrowseForFolder(*BrowseInfo),LONG,RAW,PASCAL
                 SHGetPathFromIDList(Long,*CSTRING),LONG,RAW,PASCAL
                 CoTaskMemFree(*LONG),RAW,PASCAL
               END

!in your Procedure, Embed, Data

BI             LIKE(BrowseInfo)
cTitle         CSTRING(30)
cPath          CSTRING(251)

! In your procedure, somewhere after window is open
!(e.g., in the Event accepted for a button)

  cTitle = 'Select a Directory'
  cPath = '<0>{250}'
  BI.hWndOwner = 0{prop:Handle}
  BI.lpszTitle = ADDRESS(cTitle)
  BI.ulFlags = 1 !only show directories!
  lpIDList# = SHBrowseForFolder(BI)
  IF lpIDList#
    Result# = SHGetPathFromIDList(lpIDList#, cPath)
    COTaskMemFree(lpIDList#)
    MESSAGE('You Chose ' & cPath, 'Result')
  END

Q:

I want all my new apps to be 32bit. Is there a way I can set up my Clarion environment to create 32-bit applications by default?

A:

At last, an easy question <g>. Seriously, this is easy to set up.

With the Clarion environment closed, open CLARION4.INI in any text editor.

Search for:

default32bit=off

Change it to:

default32bit=on

Save and exit. The next time you create an application, it will be set to 32-bit.

Author's note
Thanks to Jeff Berlinghoff for the FILEDIALOG code for Clarion 2.003. Special Thanks to Richard Taylor, Director of Technical Communication at TopSpeed (and my boss!) for his contribution to much of the other code in this article. His help not only improved the content of this article, but also increased my knowledge of the Object-Oriented paradigm in Clarion 4.

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: $189

(includes all back issues since '99)

Renewals from $139

Two years: $289

Renewals from $239

More Info

Subscribe Now!

ClarionMag Blog

RSS Feeds

Updates via Email

Enter your Email


Powered by FeedBlitz

Quick Links