{"id":615,"date":"2025-07-08T13:50:21","date_gmt":"2025-07-08T13:50:21","guid":{"rendered":"https:\/\/xojo.itbib4you.be\/?page_id=615"},"modified":"2025-07-11T09:19:34","modified_gmt":"2025-07-11T09:19:34","slug":"subclasses","status":"publish","type":"page","link":"https:\/\/xojo.itbib4you.be\/index.php\/subclasses\/","title":{"rendered":"Subclasses"},"content":{"rendered":"\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-width wp-block-button__width-25\"><a class=\"wp-block-button__link has-light-green-cyan-to-vivid-green-cyan-gradient-background has-background has-small-font-size has-custom-font-size wp-element-button\" href=\"https:\/\/xojo.itbib4you.be\/\">Overview<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>In the previous lessons, we discussed in detail how to define classes and how to use objects created from these classes. In this lesson, we will learn how to create and use <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">subclasses<\/mark>. A <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">subclass<\/mark> inherits properties and methods from a parent class, called the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">superclass<\/mark>. Using some small examples, we will illustrate the usefulness of subclasses in object-oriented programming (OOP). <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to create a subclass?<\/h2>\n\n\n\n<p>For the class <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">DesktopTextField<\/mark> , many properties, methods and events are already available by default. However, it can sometimes be very useful to add new methods to this class. Since it is not possible to add new methods to existing Xojo classes, we have to create a new subclass. <\/p>\n\n\n\n<p>A subclass can be created in a simple way:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"596\" height=\"236\" src=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/06\/Schermafbeelding-2025-06-25-om-14.17.26.png\" alt=\"Define subclass\" class=\"wp-image-620\" style=\"width:220px;height:auto\" srcset=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/06\/Schermafbeelding-2025-06-25-om-14.17.26.png 596w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/06\/Schermafbeelding-2025-06-25-om-14.17.26-300x119.png 300w\" sizes=\"auto, (max-width: 596px) 85vw, 596px\" \/><\/figure>\n<\/div>\n\n\n<ol class=\"wp-block-list\">\n<li>Insert a new Class to your project (<em>MainMenuBar<\/em> &#8211; <em>Insert<\/em> &#8211; <em>Class<\/em> or via <img loading=\"lazy\" decoding=\"async\" width=\"25\" height=\"20\" class=\"wp-image-555\" style=\"width: 25px;\" src=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/06\/Schermafbeelding-2025-06-17-om-11.28.04.png\" alt=\"insert\"> button in toolbar);<\/li>\n\n\n\n<li>Name the new class (e.g. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">MyTextField<\/mark>) in the Inspector;<\/li>\n\n\n\n<li>Select the superclass (e.g. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">DesktopTextField<\/mark>)in the Inspector.<\/li>\n<\/ol>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MyTextField<\/mark> is now a subclass from the superclass <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">DesktopTextField<\/mark>. This means that an instance of <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MyTextField<\/mark> can be added to a window. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MyTextField<\/mark> inherits all properties (e.g. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Text<\/mark>) , methods (e.g. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AddText<\/mark>) and events (e.g. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">TextChanged<\/mark>) from the superclass <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">DesktopTextField<\/mark>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"496\" height=\"594\" src=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/06\/Schermafbeelding-2025-06-25-om-15.03.39.png\" alt=\"MyTextField1\" class=\"wp-image-628\" style=\"width:168px;height:auto\" srcset=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/06\/Schermafbeelding-2025-06-25-om-15.03.39.png 496w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/06\/Schermafbeelding-2025-06-25-om-15.03.39-251x300.png 251w\" sizes=\"auto, (max-width: 496px) 85vw, 496px\" \/><\/figure>\n<\/div>\n\n\n<p>Now you can drag and drop <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MyTextField<\/mark> from the navigator onto a Window. The default name of the object (new instance of MyTextField) will be <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">MyTextField1<\/mark>, but can be changed. To keep the example simple, I kept the default name.<\/p>\n\n\n\n<div style=\"height:4px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">How to add methods to a subclass?<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"494\" height=\"752\" src=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/06\/Schermafbeelding-2025-06-25-om-15.26.57.png\" alt=\"New methods MyTextField\" class=\"wp-image-631\" style=\"width:185px;height:auto\" srcset=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/06\/Schermafbeelding-2025-06-25-om-15.26.57.png 494w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/06\/Schermafbeelding-2025-06-25-om-15.26.57-197x300.png 197w\" sizes=\"auto, (max-width: 494px) 85vw, 494px\" \/><\/figure>\n<\/div>\n\n\n<p>Now you can add new methods to the subclass named <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MyTextField<\/mark>. Four new methods were added in the example (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">ToCurrency<\/mark>, <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">ToLowerCase<\/mark>, <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">ToTitleCase<\/mark>, <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">ToUpperCase<\/mark>). <\/p>\n\n\n\n<p>Our discussion will be limited to the methods <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">ToTitleCase<\/mark> and <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">ToCurrency<\/mark>. <\/p>\n\n\n\n<div style=\"height:1px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">ToTitleCase<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/ToTitleCase As String<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Var<\/mark> t <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">As String<\/mark> = <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Self<\/mark>.Text.Titlecase<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Return<\/mark> t<\/pre>\n\n\n\n<p>This method is very simple. The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Text<\/mark> property of <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MyTextField<\/mark> (denoted by the keyword <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Self<\/mark>) is converted by the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">String<\/mark> method <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">TitleCase<\/mark> and assigned to the local<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">String<\/mark> variable <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">t<\/mark>. The converted string is then returned to the calling method.<\/p>\n\n\n\n<p>In the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">MyTextField1<\/mark> object, the new method can now be called via the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">TextChanged<\/mark> event:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/TextChanged event<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Me<\/mark>.Text = <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Me<\/mark>.ToTitleCase<\/pre>\n\n\n\n<p>Now if you type the name &#8220;john de long&#8221; into <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">MyTextField1<\/mark> the name is automatically converted to &#8220;John De Long&#8221;. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">ToCurrency<\/h4>\n\n\n\n<p>A monetary amount entered as text in <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">MyTextField1<\/mark> can easily be converted to a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Currency<\/mark> data type via the method <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">ToCurrency<\/mark> . <\/p>\n\n\n\n<p>The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">ToCurrency<\/mark> method looks as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/ToCurrency As Currency<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Var<\/mark> v As <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Currency<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Try<\/mark><br>  v = <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Currency<\/mark>.FromString(<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Self<\/mark>.Text, Locale.Current)<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Catch<\/mark> error <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">As<\/mark> RuntimeException<br>  MessageBox(\"Error \"+error.Message)<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">End Try<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Return<\/mark> v<\/pre>\n\n\n\n<p>The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">FromString<\/mark> method is used to convert the value of the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Text<\/mark> property of <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MyTextField<\/mark> into a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Currency<\/mark> value. The parameter <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Locale.Current<\/mark> takes into account the local representation of money amounts (meaning of comma and period).<\/p>\n\n\n\n<p>If the conversion fails a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">RunTimeException<\/mark> is raised. This error condition  is caught by the Try..Catch..End Try construction. The converted value <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">v<\/mark> is returned to the calling method.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-yellow-background-color has-background\">An empty <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Currency<\/mark> value doesn't exist. The above code will return <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">0<\/mark> if the conversion fails! <\/pre>\n\n\n\n<p>In the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">MyTextField1<\/mark> object, the new method can be called via the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">KeyDown<\/mark> event:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/KeyDown(key As String) As Boolean<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">If<\/mark> key = Chr(3) <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Or<\/mark> key = Chr(13) Then<br>  <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Var<\/mark> amount <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">As Currency<\/mark> = <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Me<\/mark>.ToCurrency<br>  MessageBox(Str(amount))<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">End If<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Return False<\/mark><\/pre>\n\n\n\n<p>The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">KeyDown<\/mark> event waits until End-Of-Text (ETX) (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Chr(3)<\/mark>) is reached or Carriage Return (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Chr(13)<\/mark>) is pressed. The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">ToCurrency<\/mark> method converts the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Text<\/mark> of <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">TextField1<\/mark> into the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Currency<\/mark> value named <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">amount<\/mark>. In Europe the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Text<\/mark> value \u20ac1.234,55 entered in <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">MyTextField1<\/mark> is converted to 1234.56. This value can now be used to perform calculations.<\/p>\n\n\n\n<p>The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Return<\/mark> statement returns <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">False<\/mark> . Returning <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">False<\/mark> means the key reaches the control. Returning <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">True<\/mark> means the key is intercepted.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to add properties to a subclass?<\/h3>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Properties<\/mark> can be added to a subclass in the usual way. For example, you can add the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">CurrencyValue<\/mark> property (type <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Currency<\/mark> &#8211; scope <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Private<\/mark>) to store the currency amount calculated from the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Text<\/mark> property.<\/p>\n\n\n\n<p>In this case, modify the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">ToCurrency<\/mark> method as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/ToCurrency As Currency<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Try<\/mark><br>  CurrencyValue = <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Currency<\/mark>.FromString(<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Self<\/mark>.Text, Locale.Current)<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Catch<\/mark> error <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">As<\/mark> RuntimeException<br>  MessageBox(\"Error \"+error.Message)<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">End Try<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Return<\/mark> CurrencyValue<\/pre>\n\n\n\n<p>In the following paragraphs, I use a more practical example to illustrate adding <font color=\"#ff675f\"><span style=\"caret-color: rgb(255, 103, 95);\">events<\/span><\/font> to a subclass.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to add events to a (sub)class?<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"284\" src=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.40.08-1024x284.png\" alt=\"Accounts Window\" class=\"wp-image-661\" srcset=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.40.08-1024x284.png 1024w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.40.08-300x83.png 300w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.40.08-768x213.png 768w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.40.08.png 1188w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<p>For the following example, I have two &#8216;special&#8217; bank accounts: a retirement account (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RetirementAccount<\/mark>) and a savings account (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">SavingsAccount<\/mark>). Both accounts are slightly different: for a retirement account, each deposit is limited to 1000.0 (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">MaximumAmount<\/mark>); for a savings account, on the other hand, the total account balance is limited to 5000.0 (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">MaximumBalance<\/mark>).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"816\" src=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-07-om-16.02.29-1024x816.png\" alt=\"klassen\" class=\"wp-image-641\" style=\"width:260px;height:auto\" srcset=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-07-om-16.02.29-1024x816.png 1024w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-07-om-16.02.29-300x239.png 300w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-07-om-16.02.29-768x612.png 768w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-07-om-16.02.29-1536x1223.png 1536w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-07-om-16.02.29-1200x956.png 1200w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-07-om-16.02.29.png 2000w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n<\/div>\n\n\n<p>To solve this problem and illustrate the use of events, I created the class <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Account<\/mark> and two subclasses <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">LimitAmountAccount<\/mark> and <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">LimitBalanceAccount<\/mark>. <\/p>\n\n\n\n<div style=\"height:3px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-preformatted has-yellow-background-color has-background\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">REMARK<\/mark><br>There are several possible solutions to this problem. This solution was chosen to best illustrate the use of events.<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Account<\/h3>\n\n\n\n<p>The class <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Account<\/mark> has a method named <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Deposit<\/mark>(scope <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Protected<\/mark>):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/Deposit(amount As Double)<\/mark><br>AccountBalance = AccountBalance + amount<\/pre>\n\n\n\n<p>The class <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Account<\/mark> also has a property <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">AccountBalance<\/mark> (Type <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Double<\/mark> &#8211; Scope <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Protected<\/mark>).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-yellow-background-color has-background\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Protected<\/mark> means that the property or method can be used in the class itself and by its subclasses.<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">LimitAmountAccount<\/h3>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">LimitAmountAccount<\/mark> is a subclass of <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Account<\/mark>: <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Account<\/mark> is the superclass (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Super<\/mark> <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Account<\/mark>). <\/p>\n\n\n\n<p>Because a special rule applies to this subclass (the deposited amount cannot exceed 1000.00), a special method <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Deposit<\/mark> was created for this subclass. The following method has been added:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/Deposit(amount As Double)<br>\/\/ Calling the overridden superclass method.<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Super<\/mark>.Deposit(amount)<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">If<\/mark> amount &gt; 1000.0 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Then<\/mark><br>  <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RaiseEvent<\/mark> MaximumAmount<br>  AccountBalance = AccountBalance - amount<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">End If<\/mark><br>MessageBox(Str(AccountBalance))<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Super.Deposit(amount)<\/h4>\n\n\n\n<p>The first statement (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Super.Deposit(amount)<\/mark> ) is not difficult to understand: execute the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Deposit<\/mark> method from the superclass (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Account<\/mark>). In this case, the property <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AccountBalance<\/mark> is first incremented by the inserted value (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">amount<\/mark>). This statement is automatically added by Xojo if you refer to an existing method of the superclass (you want to override the existing method).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">RaiseEvent MaximumAmount<\/h4>\n\n\n\n<p>The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RaiseEvent MaximumAmount<\/mark> statement refers to an <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">event<\/mark> named <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MaximumAmount<\/mark>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"782\" src=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-11.14.45-1024x782.png\" alt=\"Event definition\" class=\"wp-image-648\" style=\"width:273px;height:auto\" srcset=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-11.14.45-1024x782.png 1024w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-11.14.45-300x229.png 300w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-11.14.45-768x586.png 768w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-11.14.45.png 1166w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n<\/div>\n\n\n<p>The use of events is easy to understand if you think of an event as a special <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">method<\/mark> called when a particular action is performed. An event (the &#8216;special&#8217; method) must be defined in an <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Event Definition<\/mark>.<\/p>\n\n\n\n<p>An <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Event Definition<\/mark> can be added by selecting the class and selecting the menu option <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Event Definition<\/mark> from the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Insert<\/mark> menu.<\/p>\n\n\n\n<div style=\"height:4px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"592\" height=\"396\" src=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-11.46.51.png\" alt=\"events\" class=\"wp-image-652\" style=\"width:279px;height:auto\" srcset=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-11.46.51.png 592w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-11.46.51-300x201.png 300w\" sizes=\"auto, (max-width: 592px) 85vw, 592px\" \/><\/figure>\n<\/div>\n\n\n<p>Just as you define an ordinary method, for events you must also specify the name of the event, optional parameters and an optional return type. No further information is required. <\/p>\n\n\n\n<div style=\"height:4px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div style=\"height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-preformatted has-yellow-background-color has-background\">An Event Definition needs only an Event Name, optional Parameters and an optional Return Type. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">No code is added in the coding pane.<\/mark><\/pre>\n\n\n\n<p>The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MaximumAmount <\/mark>event is called by the statement <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RaiseEvent MaximumAmount<\/mark> if the deposit in an account of the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">LimitAmountAccount<\/mark> subclass exceeds 1000.00. In this case, the account balance is also corrected back (the superclass already added the deposited amount) with the instruction <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AccountBalance = AccountBalance &#8211; amount<\/mark>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How to use the new event?<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Drag a class to the window<\/h5>\n\n\n\n<p>A (sub)class is just a template to define real objects. To use our new construction we have to create an object. A quick way to do this is to drag the class <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">LimitAmountAccount<\/mark> into the window and define the Name (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RetirementAccount<\/mark>), the Superclass (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">LimitAmountAccount<\/mark>) and the Scope (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Private<\/mark>). <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"616\" src=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.24.44-1024x616.png\" alt=\"RetirementAccount Event\" class=\"wp-image-659\" style=\"width:312px;height:auto\" srcset=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.24.44-1024x616.png 1024w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.24.44-300x180.png 300w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.24.44-768x462.png 768w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.24.44.png 1104w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n<\/div>\n\n\n<p>The object <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RetirementAccount<\/mark> knows one event (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">MaximumAmount<\/mark>). The Event Handler (what must be done if the deposit is greater than 1000.00?) can be added to the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RetirementAccount<\/mark>. The following screenshot shows the way how the Event Handler is made available.<\/p>\n\n\n\n<div style=\"height:4px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"537\" src=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.34.42-1024x537.png\" alt=\"Event selection window\" class=\"wp-image-660\" style=\"width:313px;height:auto\" srcset=\"https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.34.42-1024x537.png 1024w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.34.42-300x157.png 300w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.34.42-768x403.png 768w, https:\/\/xojo.itbib4you.be\/wp-content\/uploads\/2025\/07\/Schermafbeelding-2025-07-08-om-14.34.42.png 1160w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n<\/div>\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In this case, we chose to provide only an error message (&#8220;Amount &gt; 1000.00!&#8221;) to indicate that this deposit will not be accepted. This piece of code can be added to the Event Handler:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/MaximumAmount<\/mark><br>MessageBox(\"Amount &gt; 1000.00!\")<\/pre>\n\n\n\n<p>The same process can be used to create a new <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MaximumBalance<\/mark> event for the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">LimitBalanceAccount<\/mark> subclass.<\/p>\n\n\n\n<p>The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Deposit<\/mark> method for the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">LimitBalanceAccount<\/mark> subclass will be:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/Deposit(amount As Double)<br>\/\/ Calling the overridden superclass method.<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Super<\/mark>.Deposit(amount)<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">If<\/mark> AccountBalance &gt; 5000.00 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Then<\/mark><br>  <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RaiseEvent<\/mark> MaximumBalance<br>  AccountBalance = AccountBalance - amount<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">End If<\/mark><br>MessageBox(Str(AccountBalance))<\/pre>\n\n\n\n<p>An Event Definition must be added to the subclass for the new Event <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MaximumBalance<\/mark> (Name <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MaximumBalance<\/mark>, no parameters, no Return).<\/p>\n\n\n\n<p>A new object can be added by dragging the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">LimitBalanceAccount<\/mark>subclass onto the Window. The new object is named <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">SavingsAccount<\/mark>, Super is <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">LimitBalanceAccount<\/mark> and Scope is <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Private<\/mark>.<\/p>\n\n\n\n<p>The code for the Event Handler <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MaximumBalance<\/mark> could be:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/MaximumBalance<\/mark><br>MessageBox(\"Balance Limit 5000.00!\")<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Create your class at runtime<\/h5>\n\n\n\n<p>In the previous lesson, we created the accounts at runtime with the statements <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RetirementAccount = New LimitAmountAccount<\/mark> and <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">SavingsAccount = New LimitBalanceAccount<\/mark>. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RetirementAccount<\/mark> and <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">SavingsAccount<\/mark> were two properties defined in <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AccountWindow<\/mark>. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/Opening<\/mark><br>RetirementAccount = <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">New<\/mark> LimitAmountAccount<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AddHandler<\/mark> RetirementAccount.MaximumAmount, <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AddressOf<\/mark> MaxAmountMethod<br><br>SavingsAccount = <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">New<\/mark> LimitBalanceAccount<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AddHandler<\/mark> SavingsAccount.MaximumBalance, <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AddressOf<\/mark> MaxBalanceMethod<\/pre>\n\n\n\n<p>We have now placed the above piece of code in the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Opening<\/mark> event of <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AccountWindow<\/mark>. The two accounts are created at runtime. Because these objects are created at runtime, it is not yet possible to handle the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MaximumAmount<\/mark> and <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">MaximumBalance<\/mark> events . <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AddHandler<\/mark> associates an event with a method that must be executed  when the event occurs.<\/p>\n\n\n\n<p>The following syntax is used:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-yellow-background-color has-background\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">AddHandler<\/mark> eventName, delegateMethod<\/pre>\n\n\n\n<p>A <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">delegateMethod<\/mark> is a pointer to a named method.  <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">AddressOf<\/mark> gets the address of the named method . This is the code of the referenced methods:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/MaxAmountMethod(sender As LimitAmountAccount)<\/mark><br>MessageBox(\"Amount > 1000!\")<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/MaxBalanceMethod(sender As LimitBalanceAccount)<br><\/mark>MessageBox(\"Balance > 5000!\")<\/pre>\n\n\n\n<p>An additional parameter (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">sender As LimitAmountAccount<\/mark>in MaxAmountMethod , <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">sender As LimitBalanceAccount<\/mark>in MaxBalanceMethod) is required for the methods that must be executed when the events occur. The first parameter of the referenced methods must always be of the type of  the original object.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-yellow-background-color has-background\">The first parameter of the method must always be of the type of the original object.<\/pre>\n\n\n\n<p>If you use <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Addhandler<\/mark>, you should always remove the handler when it is no longer needed. The handlers are removed in the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">Closing<\/mark> event of <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AccountWindow<\/mark>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-light-gray-background-color has-background has-small-font-size\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">\/\/Closing<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RemoveHandler<\/mark>  RetirementAccount.MaximumAmount, <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AddressOf<\/mark> MaxAmountMethod<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">RemoveHandler<\/mark>  SavingsAccount.MaximumBalance, <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">AddressOf<\/mark> MaxBalanceMethod<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In the previous lessons, we discussed in detail how to define classes and how to use objects created from these classes. In this lesson, we will learn how to create and use subclasses. A subclass inherits properties and methods from a parent class, called the superclass. Using some small examples, we will illustrate the &hellip; <a href=\"https:\/\/xojo.itbib4you.be\/index.php\/subclasses\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Subclasses&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-615","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/xojo.itbib4you.be\/index.php\/wp-json\/wp\/v2\/pages\/615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xojo.itbib4you.be\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/xojo.itbib4you.be\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/xojo.itbib4you.be\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xojo.itbib4you.be\/index.php\/wp-json\/wp\/v2\/comments?post=615"}],"version-history":[{"count":46,"href":"https:\/\/xojo.itbib4you.be\/index.php\/wp-json\/wp\/v2\/pages\/615\/revisions"}],"predecessor-version":[{"id":677,"href":"https:\/\/xojo.itbib4you.be\/index.php\/wp-json\/wp\/v2\/pages\/615\/revisions\/677"}],"wp:attachment":[{"href":"https:\/\/xojo.itbib4you.be\/index.php\/wp-json\/wp\/v2\/media?parent=615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}