Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PUBLIC, PRIVATE & LOCAL

Status
Not open for further replies.

IRABYY

Programmer
Apr 18, 2002
221
0
0
US
I am starting this thread by suggestion from Mike Lewis.

My statement:

PRIVATE mem. vars. belong to a class definition. For everything else there are LOCAl and PUBLIC mem. vars. And the less PUBLIC mem. vars. - the better.

Consequently, implicit memory variable's declaration - which makes it PRIVATE - in procedural modules has to be avoided. (This includes implementation of SCATTER MEMVAR command in procedure and/or function as well.)

Everybody is welcome to join the discussion.


Regards,

Ilya
 
FrikFrak2

Send me the source and let me see if it does it on one of my machines.

Martin.Griffin@Finedata.com

Regards

Griff
Keep [Smile]ing
 
Hi FrikFrak2

I have a few machines here, I have a bit of patience and a little time.

If you can supply the raw ingredients I'll run the program.

Seriously, I don't think there is any other way!

zip it up and send it.

Nice to hear from you.



Regards

Griff
Keep [Smile]ing
 
I like to make all my variables LOCAL except for arrays which I declare as PRIVATE. This is for scoping reasons as I find arrays don't pass very well, as in my example below.
The 2nd time This.ArrayTest() is called it crashes as the local array is out of scope.


DEFINE CLASS TestClass AS CUSTOM

PROCEDURE MainProc

LOCAL MyArray
PRIVATE MyArray2

DIMENSION MyArray[1]
DIMENSION MyArray2[1]

MyArray[1] = "Shardlow"
MyArray2[1] = "Shardlow2"

THIS.ArrayTest("MyArray2")
THIS.ArrayTest("MyArray")

RETURN

ENDPROC


PROCEDURE ArrayTest

LPARAMETERS P_TheArray

IF AELEMENT(&P_TheArray, 1) == 1
MESSAGEBOX("It's an Array")
ELSE
MESSAGEBOX("I don't know what it is!")
ENDIF

RETURN

ENDPROC

ENDDEFINE
 
FrokFrak,

Well, I don't think it worked by putting it LOCAL becuase it still crashes.

Well, some of us pointed out that making the variable local wouldn't necessarily solve the problem. This whole discussion has been very interesting, but it is not relevant to your situation, and has only served as a distraction.

I still say that you should either rewrite the whole thing so that it runs in a reasonable time, or set a breakpoint on the variable -- or both.

Mike


Mike Lewis
Edinburgh, Scotland
 
Shardlow,

Two questions:
1. You first declare variables, and then declare arrays with the same names. Wouldn't it be better if you just
Code:
LOCAL ARRAY MyArray[1]
DIMENSION MyArray2[1]
would it?

2. You pass the array's name as string. Why don't you pass a pointer on that array instead? I.e.
Code:
THIS.ArrayTest(@MyArray)
Actually, you need to pass only one array, the LOCAL one. The PRIVATE one is in the scope already anyway. Or - am I missing something? Are there some restrictions for a class definition?


Regards,

Ilya
 
Irabyy,
You are of course right on both points, but that was just the way the company I worked for wanted their code to be structured. All variables and arrays had to be declared and passed to whatever method used them in the manner I have done above. This provided consistency throughout the code, which made teaching others straight out of school so much more easier. On the other hand it did make life a little more difficult for the rest of us.

Shardlow.
 
Shardlow (Programmer):

that was just the way the company I worked for wanted their code to be structured. All variables and arrays had to be declared and passed to whatever method used them in the manner I have done above.
...
On the other hand it did make life a little more difficult for the rest of us.

Yeah, we can't go against company's standards, can we? [sad] My sympathy/condolences to you, bro! Looks like whoever set these standards were used to linear programming style of old days... I guess these standards ban using visual design also, no?


Regards,

Ilya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top