<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - Property Declaration
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help+en"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../lang+en">Up</a>&nbsp;
<a href="procedure+en">Previous</a>&nbsp;
<a href="property+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Property Declaration
</h1>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><b>PROPERTY</b> [ <b>READ</b> ] <u>Identifier</u> <b>AS</b> <u>Datatype</u></pre><p>

This declares a class property.
<p>
If the keyword <tt><b>READ</b></tt> is specified, then the property will be read-only.
<p>
Once declared, a property must be implemented : you must write a function to read the property, and, if not read-only, a function to write the property.
<p>
The name of the read function is the name of the property followed by an underscore and the word <tt>Read</tt>. This function takes no argument and must return a data whose type is the same as the property datatype.
<p>
The name of the write function is the name of the property followed by an underscore and the word <tt>Write</tt>. This function is a procedure that returns nothing, and that takes only one argument whose type is the same as the property datatype.
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">PROPERTY Enabled AS Boolean
PROPERTY READ Handle AS Integer
...

PRIVATE $bEnabled AS Boolean
PRIVATE $iHandle AS Integer

' Implements the Enabled property

FUNCTION Enabled_Read() AS Boolean

  RETURN $bEnabled

END

SUB Enabled_Write(bEnabled AS Boolean)

  $bEnabled = bEnabled
  UpdateEverything

END

' Implements the Handle property

FUNCTION Handle_Read() AS Integer

  RETURN $iHandle

END</pre>
<p>
<hr><b>See also</b><br>
<a href="methoddecl+en">Method Declaration</a>&nbsp;

</div>
</body>
</html>

