This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
tutorial:class [2019/01/28 10:09] admin |
tutorial:class [2019/01/29 08:24] (current) admin |
||
|---|---|---|---|
| Line 38: | Line 38: | ||
| end; | end; | ||
| - | __**หมายเหตุ**__ - ในการสร้าง Class ทุกๆครั้งที่ไม่ได้ระบุว่าสืบทอดมาจาก Class ใด จะเป็นการสร้าง Class สืบทอดจาก TObject ซึ่งเป็น Class พื้นฐานของ FPC เสมอ \\ \\ | + | __**หมายเหตุ**__ - ในการสร้าง Class ทุกๆครั้งที่ไม่ได้ระบุว่าสืบทอดมาจาก Class ใด จะเป็นการสร้าง Class สืบทอดจาก TObject ซึ่งเป็น Class พื้นฐานของ FPC เสมอ \\ |
| + | |||
| + | ตัวอย่างการสร้าง Class แบบละเอียด | ||
| + | <sxh delphi;> | ||
| + | Type | ||
| + | TMyClass = class(TObject) | ||
| + | private | ||
| + | FName:string; | ||
| + | FValue:integer; | ||
| + | protected | ||
| + | function GetIsOK:boolean; | ||
| + | public | ||
| + | constructor create; | ||
| + | destructor destroy; override; | ||
| + | procedure DoSomeThing; | ||
| + | published | ||
| + | property Name:string read FName write FName; | ||
| + | property Value:integer read FValue write FValue default 0; | ||
| + | property IsOK:boolean read GetIsOK; | ||
| + | end; | ||
| + | </sxh> | ||
| + | \\ | ||
| ---- | ---- | ||
| =====Property===== | =====Property===== | ||
| - | คือ คุณสมบัติของ Object ประกอบไปด้วย Getter (คำสั่งหลัง read) และ Setter (คำสั่งหลัง write)\\ \\ | + | คือ คุณสมบัติของ Class (หรือ Object) เช่น ความยาว ความกว้าง ตำแหน่ง เป็นต้น โครงสร้างของ property นั้นประกอบไปด้วย Getter (คำสั่งหลัง read) และ Setter (คำสั่งหลัง write)\\ \\ |
| เพื่อเป็นการอธิบายให้เห็นภาพ จะขอยกตัวอย่าง | เพื่อเป็นการอธิบายให้เห็นภาพ จะขอยกตัวอย่าง | ||