Is this var public or private or both ? 
Author Message
 Is this var public or private or both ?

Hello out there,

i have to translate a old application (1991) to CSharp. Because i do not
know much about Pascal i do not know if this var "myVar" is private or
public or even both. Here the code:

        someVar = myVar * foo / 100 + bar / 100;

and also

        procedure AnyProcedure

                myVar = elseInt * otherInt / 100;
                ... and so on

So my question is i do not know if myVar in AnyProcedure is only valid
within this procedure
        or
if this myVar is the same used in
        someVar = myVar * foo /100 + bar / 100;

Thanks a lot in advance

best regards tom



Sat, 28 May 2005 19:04:06 GMT  
 Is this var public or private or both ?

Quote:

>Hello out there,

>i have to translate a old application (1991) to csharp. Because i do not
>know much about pascal i do not know if this var "myVar" is private or
>public or even both. Here the code:

>    someVar = myVar * foo / 100 + bar / 100;

>and also

>    procedure AnyProcedure

>            myVar = elseInt * otherInt / 100;
>            ... and so on

>So my question is i do not know if myVar in AnyProcedure is only valid
>within this procedure
>    or
>if this myVar is the same used in
>    someVar = myVar * foo /100 + bar / 100;

>Thanks a lot in advance

>best regards tom

If you know any C#, then you know about variable declarations, and
there isn't MUCH difference between Pascal and C* (meaning ALL the C
family) declarations.
Look in the VAR sections of your program header and procedures.
It would be BAD programming practice to:
o use myVar as a variable name in the first place
o reuse the variable name in the procedures called by parent
procedures or the main Program
o use global variables unless really necessary.
Anyway, if myVar appears only in the VAR section of the Program, it is
Global, if it appears in a procedure, it is local to the procedure.


Sun, 29 May 2005 21:41:27 GMT  
 Is this var public or private or both ?

Quote:

>Hello out there,

>i have to translate a old application (1991) to csharp. Because i do not
>know much about pascal i do not know if this var "myVar" is private or
>public or even both. Here the code:

>    someVar = myVar * foo / 100 + bar / 100;

>and also

>    procedure AnyProcedure

>            myVar = elseInt * otherInt / 100;
>            ... and so on

>So my question is i do not know if myVar in AnyProcedure is only valid
>within this procedure
>    or
>if this myVar is the same used in
>    someVar = myVar * foo /100 + bar / 100;

>Thanks a lot in advance

>best regards tom

BTW: I think you are confusing private/public with global/local.
Private variables are explicitly declared so and are NOT available
outside the instance of a class, etc.


Sun, 29 May 2005 21:43:17 GMT  
 Is this var public or private or both ?


Quote:
> Hello out there,

> i have to translate a old application (1991) to csharp. Because i do not
> know much about pascal i do not know if this var "myVar" is private or
> public or even both. Here the code:

> someVar = myVar * foo / 100 + bar / 100;

> and also

> procedure AnyProcedure

> myVar = elseInt * otherInt / 100;
> ... and so on

> So my question is i do not know if myVar in AnyProcedure is only valid
> within this procedure
> or
> if this myVar is the same used in
> someVar = myVar * foo /100 + bar / 100;

> Thanks a lot in advance

> best regards tom

In Pascal EVERY var, const, type, record, object,  procedure function etc HAS to be declared.
The place where you declare it determines where it is known
If it is declared in the main text of your program, it is known to anything below that declaration. If you declare it inside a
procedure or function it is only known to that function or procedure.
If you declare it in the interface section of a unit, it is known publicly to all programs or units that have the unit in their
interface section. If it is declared in the implementation section of a unit, it is only known inside the unit for the code below
the declaration.

e.g.

unit myunit;
interface
const somevalue=10;                   {const  declaration fixed value}
var A:integer;                               {integer declaration value unknown}
function ValueOf_B_is:integer;     {function declaration }
implementation
const B:integer=somevalue;          {integer declaration startingvalue =10}
                                                   {B is known inside Myunit only}

function ValueOf_B_is;                {Since this function is mentioned in }
begin                                            {the interface section it is known outside}
  inc(B);
  ValueOf_B_is:=B;                       {myunit}
end;

end.

program myprog
uses myunit;                           {all declarations in myunit's interface
                                               become known in the program}
procedure proc1(var C:integer)     {C is a call by name declaration.}
var d:integer;                     {d =only known inside proc1}
begin
   for d:= 1 to 10 do
           C:=valueOf_B_is;
end;

var e:real;                 {d is know to all code below}

procedure proc2(c:real);  {call by value declaration}
                           { inside proc2 is C a real, not known outside}
begin
   e:=c;
end;

begin
    proc1(A);    {A gets the value of B inside proc1 where it is called C  }
    proc2 (1.5);  { filling in a value here is allowed since the argument is call by value}
end.



Sun, 29 May 2005 23:00:52 GMT  
 Is this var public or private or both ?
First i would like to thank you both for your replies.

My Problem is actual a little more complex.

In codeFile_v.pas the following is written:

        procedure Startinitial
          begin
            myVar:=0;
            ...
          end;

in codeFile_e.pas you can find:

        Interface
        uses codeFile_a.pas;

        procedure FileRead; {a lot of procedure announcements)

        Implementation
        procedure CalculateSpeed
          begin
             ....
               Startinitial; {so myVar is set 0 }

and finally in codeFile_r.pas you can find:

        Interface
        uses Moni_v, Moni_a;

        Implementation

        procedure CalculateWeight
          begin
            ....
            weight_a = myVar * SomeVars/100;
            ....

        foo := myVar + intElse + aLotOfOtherStuff;
        bar := myVar + intB + evenMore;

and a many lines later in the same file (codeFile_r.pas)

        procedure AnyProcedure

           myVar = elseInt * otherInt / 100;
           ... and so on

the procedure startinitial is never used (instantiated, called) in
codeFile_r.pas.

I really appreciate your help.
Thanks in advance

best regards
tom



Mon, 30 May 2005 21:56:57 GMT  
 Is this var public or private or both ?

Quote:

>First i would like to thank you both for your replies.

>My Problem is actual a little more complex.

<snip>

>I really appreciate your help.

Well, as mentioned in my other reply, you should first get aquainted
with the basics of Pascal, otherwise you are running over and over in
such problems where the language concepts (and compiler dependent
implementations) between (Turbo/Borland) Pascal and C# are
different....

As for the problem at hand, your myVar is a public (global) variable,
which is defined somehwere in the INterface section of one of the used
units.

Ralf



Wed, 01 Jun 2005 04:44:42 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Var Word to Var String

2. newbee question,string var to char var

3. Problem with setting private dir...

4. protected or private

5. Private directories

6. Delete Private Directory

7. Private Dir Alias Woes

8. Private Directory Question

9. problem with the scope of private members

10. This is a posting of some private mail I responded to

11. MemDB - Memory Database Expert enters public beta

12. DOS Multithreading library released to public domain.

 

 
Powered by phpBB® Forum Software