Board index » delphi » what does var do in the parameter passing
Ramrao Salka
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
|
Ramrao Salka
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
what does var do in the parameter passing
I wanted to know what 'var' does in parameter passing for function or
procedure like eg. Function FunType(var ch: integer):integer; now whats the difference if i dont give 'var'???? |
Robert AH Prin
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:what does var do in the parameter passingIn article <7jrh3i$rn...@news.vsnl.net.in>, "Ramrao Salkar" <ramr...@vsnl.com> wrote: Quote> I wanted to know what 'var' does in parameter passing for function or Robert Sent via Deja.com http://www.deja.com/ |
toDSa
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:what does var do in the parameter passingQuoteRamrao Salkar wrote: value of that parameter withing the procedure or function. Normally you are also able to do this, but when the procedure or function exits the value will be set back to what it was before you called the prodedure. This will not be the case when you use var. greetz, ---------------------------------- |
Frederi
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:what does var do in the parameter passingQuoteRamrao Salkar wrote: in a variable to the sub program, it rather passes a pointer to that variable. That's also why you cannot pass an immediate value to such a sub program. In your example, the compiler does not pass the value in ch, it passes a pointer to ch ("call by reference" instead of "call by value"). As a result, when you write ch := 2; inside the sub program, this var procedure test(var ch: integer); begin If you omit "var", you can still assign a value to ch inside the It sounds more intricate than it actually is. Maybe someone else -- |
Rommert J. Casimi
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:what does var do in the parameter passingQuoteRamrao Salkar wrote: CH within the procedure is equivalent to an assignment to the corresponding actual parameter.For example if there is a call Funtype(x), ch:='a' within the procedure means the same as x:='a'; Many Pascal compilers, including Turbo Pascal, implement this behaviour -- |
Frederi
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:what does var do in the parameter passingQuoteRobert AH Prins wrote: -- |
Osmo Ronkan
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:what does var do in the parameter passingIn article <376103F9.67AFC...@todsah.nl.eu.org>, QuotetoDSaH <tod...@todsah.nl.eu.org> wrote: of passing a parameter: by value or by reference. When a parameters is passed by value the value of the parameter is pushed to the stack and the procedure then can use that value like a local variable. When a parameter is passed by reference (var) then the address of the actual parameter is passed instead of the value. When the parameter is used in the procedure the an implicit pointer reference is done and the variable that was passed is accessed. One can only pass variables (or typed constants) as variable parameters. TP 7.0 has also a third type: constant parameters (keyword const) as the Osmo |
toDSa
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:what does var do in the parameter passingQuoteOsmo Ronkanen wrote: of basic. If this guy (Ramrao) doesn't yet understand what var infront of a parameter does , he probably wouldn't know what a pointer is. So maybe it isn't a technically correct awnser but he should be able to get the point. greets, ---------------------------------- |
Bj?rn Teege
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:what does var do in the parameter passingHallo Rommert! Quote> Many Pascal compilers, including Turbo Pascal, implement this behaviour value and by reference. To indicate that a parameter has to be passed by reference, you must use the keyword 'var'. The character literal 'x' is a value in Pascal. And references to values do I do not know the official Pascal report, but I am sure that people have Bj?rn |
Bj?rn Teege
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:what does var do in the parameter passingQuote> > >If you put 'var' in front of a parameter, you will be able to change the you knew that, of course. Usually it is a good way to describe only the effects within going into details, especially if the asking person does not know about that details. But your answer was not only technically incorrect, but also the described Consider we could use your way of passing arguments indicated by the keyword procedure p; procedure print; procedure svar(var n: integer); procedure svar2(var2 n: integer); procedure sval(n: integer); begin Bj?rn |
1. Passing Strings as Var Parameters
2. Passing an multidimensional array as a var parameter?
3. Passing var parameter to a DLL
4. Passing Var parameters in Events
5. Passing ASP Objects in var Parameters
6. Passing property as var parameter?
7. Can I tell delphi not to redraw the window until I am done doing what I want
8. Can I tell delphi not to redraw the window until I am done doing what I want to do!