User Tools

Site Tools


tutorial:record

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
tutorial:record [2019/01/20 08:23]
admin
tutorial:record [2019/01/28 09:19]
admin
Line 169: Line 169:
 \\  \\ 
 จากตัวอย่างโค๊ดข้างบน จะอธิบายส่วนประกอบต่างๆทีละส่วนดังนี้ จากตัวอย่างโค๊ดข้างบน จะอธิบายส่วนประกอบต่างๆทีละส่วนดังนี้
-====Access ​Specifiers==== +====Access ​Modifier==== 
  
   type   type
Line 224: Line 224:
   property IsOK:​boolean read GetIsOK;   property IsOK:​boolean read GetIsOK;
  
-\\+
  
 <hidden Example-3: Object without Properties>​ <hidden Example-3: Object without Properties>​
Line 284: Line 284:
 </​sxh> ​ </​sxh> ​
 </​hidden>​ </​hidden>​
-\\    +   
-<hidden Example-4: Object ​with Properties>​+<hidden Example-4: Object Properties>​
 **ตัวอย่าง** การสร้าง Object ทรงกระบอก Cylinder เพื่อรับค่า รัศมีวงกลม (Radius) กับ ความสูง (Height) เข้ามาเป็น Input \\ จากนั้น **ตัวอย่าง** การสร้าง Object ทรงกระบอก Cylinder เพื่อรับค่า รัศมีวงกลม (Radius) กับ ความสูง (Height) เข้ามาเป็น Input \\ จากนั้น
 จึงนำมาคำนวณพื้นที่ฐาน (Area) และปริมาตร (Volume) \\ \\ จึงนำมาคำนวณพื้นที่ฐาน (Area) และปริมาตร (Volume) \\ \\
Line 292: Line 292:
    
 <sxh delphi;​highlight:​ []> <sxh delphi;​highlight:​ []>
-program ​Cylinder_Without_Properties;+program ​Cylinder_With_Properties;
  
 type type
Line 299: Line 299:
  
   TMyCylinder = Object   TMyCylinder = Object
 +  private
 +    function GetRadius: real;
 +    function GetVolume: real;
 +  public
     Radius:​real; ​  //​Input     Radius:​real; ​  //​Input
     Height:​real; ​  //​Input     Height:​real; ​  //​Input
-    Area:​real; ​    ​//Output +    ​property ​Area:​real ​read GetRadius   //Output 
-    Volume:​real; ​  ​//Output +    ​property ​Volume:​real ​read GetVolume //Output
-    procedure CalculateArea;​ +
-    procedure CalculateVolume;​+
     procedure ShowData;     procedure ShowData;
   end;   end;
Line 310: Line 312:
 { TMyCylinder } { TMyCylinder }
  
-procedure ​TMyCylinder.CalculateArea;+function ​TMyCylinder.GetRadius: real;
 begin begin
-  ​Area:​=system.pi*(Radius*Radius);​+  ​result:​=system.pi*(Radius*Radius);​
 end; end;
  
-procedure ​TMyCylinder.CalculateVolume;+function ​TMyCylinder.GetVolume: real;
 begin begin
-  ​Volume:​=Area*Height;​+  ​result:​=Area*Height;​
 end; end;
  
Line 332: Line 334:
 begin begin
   Cylinder.Radius:​=2;​ //Set Radius = 2   Cylinder.Radius:​=2;​ //Set Radius = 2
-  Cylinder.Height:​=10;​ //Set Radius ​+  Cylinder.Height:​=10;​ //Set Height ​10
-  Cylinder.CalculateArea;​ //Calculate Area of Cylinder +
-  Cylinder.CalculateVolume;​ //Calculate Volume of Cylinder+
   Cylinder.ShowData; ​ //Show the results   Cylinder.ShowData; ​ //Show the results
  
   Cylinder.Radius:​=10;​ //Change Radius to 10   Cylinder.Radius:​=10;​ //Change Radius to 10
-  Cylinder.ShowData; ​ //Show the result without calling CalculateArea+  Cylinder.ShowData; ​ //Show the results 
 + 
 +  Cylinder.Radius:​=5;​ //Change Radius to 5 
 +  Cylinder.Height:​=2;​ //Change Height = 2 
 +  Cylinder.ShowData; ​ //Show the results
  
   readln;   readln;
-end.   ​+end.  
 </​sxh> ​ </​sxh> ​
 +Compiled Results:
 </​hidden>​ </​hidden>​
 \\  \\ 
tutorial/record.txt · Last modified: 2019/01/28 10:14 by admin