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:17] admin [Passing Parameters] |
tutorial:procedureandfunction [2019/01/04 16:02] admin |
||
---|---|---|---|
Line 135: | Line 135: | ||
writeln('X = ',X); | writeln('X = ',X); | ||
end; | end; | ||
- | </sxh> | + | </sxh> \\ |
- | + | ||
- | อย่างไรก็ตาม เราสามารถระบุ const หน้า Parameter ได้เช่นกัน | + | |
- | + | ||
- | <sxh delphi;> | + | |
- | procedure DoItA(const X:integer); | + | |
- | begin | + | |
- | X:=10; | + | |
- | writeln('X = ',X); | + | |
- | end; | + | |
- | </sxh> | + | |
- | \\ | + | |
====By Reference==== | ====By Reference==== | ||
Line 158: | Line 147: | ||
end; | end; | ||
</sxh> | </sxh> | ||
+ | |||
+ | \\ | ||
+ | <hidden Example-6: Passing Parameters (By Value, By Reference)> | ||
+ | <sxh delphi;> | ||
+ | program Project1; | ||
+ | |||
+ | 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> | ||
+ | </hidden> |