Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Borislav Borissov
  Where is Borislav Borissov?
 Sofia
 Bulgaria
 Borislav Borissov
 To: Andy Kramek
  Where is Andy Kramek?
 Hot Springs Village
 Arkansas - United States
 Andy Kramek
 Tags
Subject: RE: #define versus assigning value to a public variable
Thread ID: 104562 Message ID: 104612 # Views: 2 # Ratings: 0
Version: Visual FoxPro 6 Category: Other
Date: Friday, August 18, 2006 12:12:23 PM         
   


> > Dan, one note.
> > #define is not evaluated during the compilation. Compiler just replace all words that are equal to left part with rigth part of #define. So if you have something like:

>
> That is correct. A #DEFINE is simply a localization that, at compile time replaces one string with another. The benefit is that if you have something that is used multiple times in a program, and wish to change it globally (like a message string), a single change (and re-compile) is all that is needed to update the code. The drawback is that they are static - unless you recompile the code the text that is inserted will never change.
>
> Microsoft makes extensive use of #DEFINE to create 'named constant' that are (supposed) to make things easier to remember - take a look at the FoxPro.h file to see some of these 'easy-to-remember' named constants for VFP e.g. for Setting Buffering:
>
> *-- Cursor buffering modes
> #DEFINE DB_BUFOFF 1
> #DEFINE DB_BUFLOCKRECORD 2
> #DEFINE DB_BUFOPTRECORD 3
> #DEFINE DB_BUFLOCKTABLE 4
> #DEFINE DB_BUFOPTTABLE 5
>
> It seems to me that trying to remember the names is harder than simply remembering the values they actually represent :)
>
> Regards
> Andy Kramek
> Microsoft MVP (Visual FoxPro)
> Tightline Computers Inc, Akron Ohio, USA



Agree, but imagine if you read someoneelses code and you read:

IF thisform.MyProperty = 5

I think this is more readable:

IF thisform.MyProperty = MY_DEFINE_WANTED_ACTION



Borislav Borissov



ENTIRE THREAD

#define versus assigning value to a public variable Posted by Dan Roche @ 8/17/2006 4:21:18 PM
RE: #define versus assigning value to a public variable Posted by Jim Winter @ 8/17/2006 4:40:56 PM
RE: #define versus assigning value to a public variable Posted by Brad Schulz @ 8/17/2006 5:53:53 PM
RE: #define versus assigning value to a public variable Posted by Ken Murphy @ 8/17/2006 6:03:43 PM
RE: #define versus assigning value to a public variable Posted by Dan Roche @ 8/17/2006 7:05:45 PM
RE: #define versus assigning value to a public variable Posted by Borislav Borissov @ 8/17/2006 7:40:52 PM
RE: #define versus assigning value to a public variable Posted by Andy Kramek @ 8/18/2006 11:58:15 AM
RE: #define versus assigning value to a public variable Posted by Borislav Borissov @ 8/18/2006 12:12:23 PM
RE: #define versus assigning value to a public variable Posted by Andy Kramek @ 8/18/2006 12:20:07 PM
RE: #define versus assigning value to a public variable Posted by Borislav Borissov @ 8/18/2006 1:05:49 PM
RE: #define versus assigning value to a public variable Posted by Bernard Bout @ 8/19/2006 5:37:30 PM
RE: #define versus assigning value to a public variable Posted by Andy Kramek @ 8/19/2006 8:27:20 PM
RE: #define versus assigning value to a public variable Posted by Ken Murphy @ 8/20/2006 3:48:45 AM
RE: #define versus assigning value to a public variable Posted by Bernard Bout @ 8/20/2006 6:57:01 PM
RE: #define versus assigning value to a public variable Posted by Bernard Bout @ 8/20/2006 6:59:14 PM