This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
tutorial:procedureandfunction [2019/01/04 15:56] admin |
tutorial:procedureandfunction [2019/01/04 16:03] admin [By Reference] |
||
---|---|---|---|
Line 147: | Line 147: | ||
end; | end; | ||
</sxh> | </sxh> | ||
+ | |||
+ | |||
+ | <hidden Example-6: Passing Parameters (By Value, By Reference)> | ||
+ | <sxh delphi;> | ||
+ | program Passing_Param; | ||
+ | |||
+ | var A,B:integer; | ||
+ | |||
+ | procedure DoItA(X:integer); //By Value | ||
+ | begin | ||
+ | X:=100; | ||
+ | writeln('DoItA, X = ',X); | ||
+ | end; | ||
+ | |||
+ | procedure DoItB(var X:integer); //By Reference | ||
+ | begin | ||
+ | X:=200; | ||
+ | writeln('DoItB, X = ',X); | ||
+ | end; | ||
+ | |||
+ | begin | ||
+ | A:=1; | ||
+ | B:=2; | ||
+ | |||
+ | writeln('A = ',A); | ||
+ | writeln('B = ',B); | ||
+ | |||
+ | DoItA(A); | ||
+ | DoItB(B); | ||
+ | |||
+ | writeln('A = ',A); | ||
+ | writeln('B = ',B); | ||
+ | |||
+ | readln(); | ||
+ | end. | ||
+ | </sxh> | ||
+ | |||
+ | Compiled Results: | ||
+ | |||
+ | A = 1 | ||
+ | B = 2 | ||
+ | DoItA, X = 100 | ||
+ | DoItB, X = 200 | ||
+ | A = 1 | ||
+ | B = 200 | ||
+ | | ||
+ | </hidden> |