{"id":311,"date":"2022-01-21T10:54:49","date_gmt":"2022-01-21T09:54:49","guid":{"rendered":"https:\/\/wiskunst.hjgsoft.nl\/?page_id=311"},"modified":"2022-01-24T13:09:24","modified_gmt":"2022-01-24T12:09:24","slug":"oeps","status":"publish","type":"page","link":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/oeps\/","title":{"rendered":"Oeps"},"content":{"rendered":"<h2>Inleiding<\/h2>\n<p>In dit hoofdstuk zal ik proberen de basis-principes van Object Oriented Programming uit te leggen.<\/p>\n<p>Ik zal dat doen aan de hand van een viertal voorbeelden.<\/p>\n<p>Als uitgangspunt neem ik de uitbreiding van Records naar Classes.<\/p>\n<p>Overigens is dit hoofdstuk bedoeld voor mensen die al wat langer met Delphi programmeren.<\/p>\n<p>In dit hoofdstuk leer je:<\/p>\n<ul>\n<li><a href=\"https:\/\/wiskunst.nl\/index.php\/delphi-lazarus\/oeps\/#1\">Begrippen<\/a><\/li>\n<li><a href=\"https:\/\/wiskunst.nl\/index.php\/delphi-lazarus\/oeps\/#2\">Eerst Delphi zelf<\/a><\/li>\n<li><a href=\"https:\/\/wiskunst.nl\/index.php\/delphi-lazarus\/oeps\/#3\">Op weg naar een eigen Class<\/a><\/li>\n<li><a href=\"https:\/\/wiskunst.nl\/index.php\/delphi-lazarus\/oeps\/#4\">Overerving<\/a><\/li>\n<li><a href=\"https:\/\/wiskunst.nl\/index.php\/delphi-lazarus\/oeps\/#5\">Polymorfisme<\/a><\/li>\n<li><a href=\"https:\/\/wiskunst.nl\/index.php\/delphi-lazarus\/oeps\/#6\">Encapsulation<\/a><\/li>\n<li><a href=\"https:\/\/wiskunst.nl\/index.php\/delphi-lazarus\/oeps\/#7\">Dynamische componenten<\/a><\/li>\n<\/ul>\n<p><a name=\"1\"><\/a><\/p>\n<h2>Begrippen<\/h2>\n<p>Bij oop (Object Oriented Programming; spreek uit als oep) zijn een aantal begrippen van belang.<\/p>\n<ol>\n<li>Encapsulation of Inkapseling<\/li>\n<li>Inheritance of Overerving<\/li>\n<li>Polymorfism of Polymorfisme<\/li>\n<li>Class of klasse<\/li>\n<li>Object of Instantie<\/li>\n<\/ol>\n<p>Ad. 1: Encapsulation betekent zoveel als dat je de velden kunt verbergen voor de buitenwereld.<br \/>\nAd. 2: Inheritance betekent dat je van bestaande Classes gebruik kan maken en daar naar eigen believen functionaliteit aan kunt toevoegen.<br \/>\nAd. 3: Polymorfism betekent dat verschillende methodes toch dezelfde naam kunnen hebben.<br \/>\nAd. 4: Een Class is niets anders dan de definitie van een object, zeg maar de blauwdruk.<br \/>\nAd. 5: Een Object is een &#8216;instantie&#8217; van een Class. Werken doe je met Objecten en niet met Classes. Van een Class kunnen meerdere Objecten bestaan, andersom niet!<\/p>\n<p>De voorbeelden moeten \u00e9\u00e9n en ander duidelijk gaan maken. Voor het merendeel maak je van bovenstaande al impliciet gebruik, ervan uitgaande dat je al in Delphi of een andere Windows-taal programmeert.<\/p>\n<p><a name=\"2\"><\/a><\/p>\n<h2>Eerst Delphi zelf<\/h2>\n<p>We gaan eerst eens kijken wat Delphi zelf doet met Classes e.d..<\/p>\n<p>&#8211;\u00a0<i>Start eens een nieuw project in Delphi en kijk naar de code:<\/i><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">unit Unit1;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">interface<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">uses<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Windows, Messages, SysUtils, Classes, Graphics, Controls,\u00a0 \u00a0Forms, Dialogs;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TForm1 = class(TForm)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 private<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 { Private declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 public<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 { Public declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Form1: TForm1;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">implementation<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">{$R *.DFM}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><\/p>\n<p>Wat hopelijk opvalt is dat Delphi een Class TForm1 heeft aangemaakt. TForm1 stamt af van TForm. Dit betekent dat TForm1 dezelfde eigenschappen en functionaliteit heeft als TForm. Laat dit project maar eens runnen. Je krijgt nu een scherm die je kunt verplaatsen, vergroten, verkleinen, maximaliseren etc., etc..<\/p>\n<p>&#8211;\u00a0<i>Zet eens een button op het form en kijk weer naar de code:<\/i><\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TForm1 = class(TForm)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Button1: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 private<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 { Private declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 public<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 { Public declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><b><br \/>\n<\/b><\/span><br \/>\nDe button staat in de Class-definitie van TForm1. Dit is nu het wezenlijke van overerving of inheritance: Maak (her)gebruik van bestaande functionaliteit en voeg en implementeer alleen nieuwe functionaliteiten toe, ofwel: ga niet opnieuw het wiel uitvinden.<\/p>\n<p>&#8211;\u00a0<i>Dubbelklik op de Button en voeg de volgende regel toe:<\/i><br \/>\n<b>ShowMessage(\u2018Knop geklikt\u2019);<\/b><\/p>\n<p>&#8211;\u00a0<i>Kijk weer naar de code:<\/i><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<br \/>\nTForm1 = class(TForm)<br \/>\nButton1: TButton;<br \/>\nprocedure Button1Click(Sender: TObject);<br \/>\nprivate<br \/>\n{ Private declarations }<br \/>\npublic<br \/>\n{ Public declarations }<br \/>\nend;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Form1: TForm1;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">implementation<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">{$R *.DFM}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Knop geklikt&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p>De procedure Button1Click is toegevoegd aan de Class-definitie. In de implementation-sectie staat de implementatie van de procedure. Kijk goed naar de heading van de implementatie. Je moet altijd expliciet aangeven van welke Class je iets implementeerd.<\/p>\n<p>&#8211;\u00a0<i>Probeer de opbouw van de code, zoals Delphi die zelf aanmaakt, goed te begrijpen.<\/i><\/p>\n<p>&#8211;\u00a0<i>Wanneer je denkt dat je het begrijpt kijk dan eens naar onderstaande code:<\/i><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">unit Unit1;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">interface<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">uses<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Windows, Messages, SysUtils, Classes, Graphics, Controls,\u00a0 \u00a0 Forms, Dialogs,<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 StdCtrls;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TForm1 = class(TForm)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Button1: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit1: TEdit;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Label1: TLabel;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 private<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 { Private declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 public<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 { Public declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Form1: TForm1;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">implementation<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">{$R *.DFM}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">function AantalCijfers : Integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var a,t : Integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 a := 0;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for t := 1 to Length(Edit1.Text) do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 if Edit1.Text[t] in [&#8216;0&#8217;..&#8217;9&#8242;]<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 then Inc(a);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 AantalCijfers := a;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Label1.Caption := IntToStr(AantalCijfers);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><\/p>\n<p>&#8211;\u00a0<i>Voorspel waar de compiler met een foutmelding komt, en welke dat is.<\/i><\/p>\n<p>&#8211;\u00a0<i>Geef twee oplossingen voor dit probleem.<\/i><\/p>\n<p><a name=\"3\"><\/a><\/p>\n<h2>Op weg naar een eigen Class<\/h2>\n<p>Wanneer we verschillende typen variabelen tot \u00e9\u00e9n logisch geheel willen maken, kunnen we in Pascal, en dus ook in Delphi, gebruik maken van Record&#8217;s.<\/p>\n<p>Nog logischer zou zijn om ook functionaliteit betreffende die variabelen hierin te kunnen onderbrengen.<br \/>\nHelaas biedt standaard Pascal hiervoor geen mogelijkheden. Delphi echter wel!<\/p>\n<p>In de volgende twee voorbeelden zullen we zien hoe een en ander in zijn werk gaat.<\/p>\n<p>Het eerste voorbeeld gaat uit van de oude vertrouwde record, het tweede gaat uit van een Class-definitie. Beide programma\u2019s doen hetzelfde en hebben dus dezelfde functionaliteit.<\/p>\n<p>De programma\u2019s houden Naam, Adres, Plaats en Leeftijd van personen bij en hebben daarbij de volgende functionaliteit: Naar volgende gaan, naar vorige gaan, indien nodig een nieuwe toevoegen, bewaren op schijf, halen van schijf.<\/p>\n<p><strong><span class=\"collapseomatic \" id=\"id69de275d2b586\"  tabindex=\"0\" title=\"Voorbeeld 1\"    >Voorbeeld 1<\/span><div id=\"target-id69de275d2b586\" class=\"collapseomatic_content \"><\/strong><\/p>\n<div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">unit vbU1;<\/span><\/div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">interface<\/span><\/div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">uses<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 StdCtrls;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TNAW = Record<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Naam, Adres, Plaats : ShortString;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Leeftijd : Byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TNamen = Array of TNAW;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TForm1 = class(TForm)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Edit1: TEdit;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Edit2: TEdit;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Edit3: TEdit;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Edit4: TEdit;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Label1: TLabel;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Label2: TLabel;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Label3: TLabel;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Label4: TLabel;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Button1: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Button2: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Button3: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Button4: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure FormCreate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Button2Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Edit1Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Edit2Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Edit3Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Edit4Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure FormActivate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Button3Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Button4Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 private<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 { Private declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure UpdateScreen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 public<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 { Public declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Form1: TForm1;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">implementation<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen : TNamen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 NamenFile : File of TNAW;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 AantalNamen,HuidigeNaam : Integer;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">{$R *.DFM}<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.FormCreate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 AantalNamen := 1;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 HuidigeNaam := 0;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 SetLength(Namen,AantalNamen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.UpdateScreen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit1.Text := Namen[Huidigenaam].Naam;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit2.Text := Namen[Huidigenaam].Adres;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit3.Text := Namen[Huidigenaam].Plaats;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit4.Text := IntToStr(Namen[Huidigenaam].Leeftijd);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button2Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Inc(HuidigeNaam);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If HuidigeNaam = AantalNamen <\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Inc(AantalNamen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 SetLength(Namen,AantalNamen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Edit1.Text := &#8221;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Edit2.Text := &#8221;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Edit3.Text := &#8221;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Edit4.Text := &#8221;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 End<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Else UpdateScreen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If HuidigeNaam &gt; 0 <\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Dec(HuidigeNaam);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 UpdateScreen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 End<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Edit1Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen[Huidigenaam].Naam := Edit1.Text;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Edit2Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen[Huidigenaam].Adres := Edit2.Text;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Edit3Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen[Huidigenaam].Plaats := Edit3.Text;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Edit4Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var c : Integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Val(Edit4.Text,Namen[Huidigenaam].Leeftijd,c);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.FormActivate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit1.SetFocus;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button3Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var f : Integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 AssignFile(NamenFile,&#8217;vb1.rec&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Rewrite(NamenFile);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 For f := 0 To AantalNamen &#8211; 1 Do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Write(NamenFile,Namen[f]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 CloseFile(NamenFile);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button4Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var f : Integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 SetLength(Namen,0);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 AssignFile(NamenFile,&#8217;vb1.rec&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Reset(NamenFile);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 f := 0;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 While not Eof(NamenFile) Do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 SetLength(Namen,Succ(f));<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Read(NamenFile,Namen[f]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Inc(f);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 End;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 CloseFile(NamenFile);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 AantalNamen := f;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 HuidigeNaam := 0;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 UpdateScreen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><\/div><\/div>\n<\/div>\n<p>&#8211;\u00a0<i>Probeer dit programma te doorgronden. Dit moet niet al te veel moeite kosten.<\/i><\/p>\n<p>&#8211;\u00a0<i>Merk ook op dat in dit programma gebruik wordt gemaakt van een dynamische array.<\/i><\/p>\n<p>In bovenstaand voorbeeld behoren naast de variabelen Naam, Adres, Plaats en Leeftijd, die we in een Record velden noemen, ook de functionaliteiten Naar volgende, Bewaar op schijd e.d. tot \u00e9\u00e9n logisch geheel.<\/p>\n<p>In het nu volgende voorbeeld gaan we dit voor elkaar maken d.m.v. een Class-definitie.<\/p>\n<p>&#8211;\u00a0<i>Bekijk de volgende type-declaraties:<\/i><\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TNawRec =\u00a0\u00a0Record<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Naam, Adres, Plaats : ShortString;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Leeftijd : Byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TNAW = class<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Namen : Array of TNawRec;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 AantalNamen,HuidigeNaam : Integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 constructor Init;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Nieuw;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Volgende;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Vorige;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure SaveToFile(FileName: ShortString);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure LoadFromFile(FileName: ShortString);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><b><br \/>\n<\/b><\/span><br \/>\nHet Record uit het vorige voorbeeld bestaat nog steeds.<\/p>\n<p>Maar in plaats van alles vervolgens onder te brengen in losse variabelen, procedures en functies, brengen we nu alles onder in een Class-definitie.<\/p>\n<p>De Class TNAW bezit alles wat we willen: alle velden, alle namen en alle functionaliteit.<\/p>\n<p>Uiteraard is het zo dat we de definitie nog wel moeten uitwerken, ofwel moeten implementeren.<\/p>\n<p>En dat gaat analoog aan hoe Delphi dat doet met de opbouw van een venster!<\/p>\n<p>Laten we bijvoorbeeld gaan kijken naar de implementatie van de procedure Nieuw.<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TNAW.Nieuw;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Inc(AantalNamen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 SetLength(Namen,AantalNamen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><b><br \/>\n<\/b><\/span><br \/>\nIn de aanhef van de procedure moet expliciet worden vermeld bij welke Class de procedure hoort.<\/p>\n<p>Vandaar procedure\u00a0<b>TNAW.<\/b>Nieuw.<\/p>\n<p>Binnen de procedure kunnen we vrij gebruik maken van alle velden en functionaliteiten van de Class.<\/p>\n<p>Nadat we de implementatie hebben gemaakt kunnen we de Class gaan gebruiken.<\/p>\n<p>Hiervoor dienen we van de Class een Object of Instantie te maken.<\/p>\n<p>Dat doen we door allereerst een variabele te definieren van het Class-type, in ons voorbeeld dus van het type TNAW.<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen: TNAW;<\/span><b><br \/>\n<\/b><\/span><br \/>\nVervolgens maken we de instantie als volgt:<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Namen := TNAW.Create;<\/span><b><br \/>\n<\/b><\/span><br \/>\nDus aan de variabele kennen we toe de naam van de Class gevolgd door\u00a0<b>.Create<\/b>.<\/p>\n<p>De methode (procedure) Create stamt af van het moeder-Object in Delphi genaamd TObject.<\/p>\n<p>Iedere Class stamt hier direct of indirect vanaf.<\/p>\n<p>Om het Object of Instantie weer op te ruimen maken we gebruik van de methode Free, ook van TObject.<\/p>\n<p>Nu zal het vaak voorkomen dat we bij het maken van een Object meteen een aantal zaken willen regelen.<\/p>\n<p>In ons voorbeeld willen we ervoor zorgen dat de variabelen Aantalnamen en Huidigenaam een startwaarde krijgen en dat er een eerste naam tot onze beschikking staat.<\/p>\n<p>Met de methode Create gaat dit niet lukken.<\/p>\n<p>In Delphi kunnen we dit voor elkaar krijgen door een Constructor-methode te maken die dan in plaats komt van de Create-methode.<\/p>\n<p>De aanmaak van een Object wordt in ons voorbeeld dan:<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen := TNAW.Init;<\/span><b><br \/>\n<\/b><\/span><br \/>\n,omdat Init de naam van onze Constructor is.<\/p>\n<p>Het is overigens toegestaan om aan een Constructor ook parameters mee te geven. Wat dat betreft is een Constructor dus gewoon te beschouwen als een normale procedure.<\/p>\n<p>Zo zouden we ook een Destructor kunnen maken die dan in plaats komt van de methode Free.<\/p>\n<p>Om, tot slot, gebruik te kunnen maken van de functionaliteit van ons Object, roepen we die functionaliteit aan d.m.v. de variabele gevolgd door een punt met daarachter de naam van de methode, net zoals het gebruik van ieder ander Object in Delphi.<\/p>\n<p>Dus bijvoorbeeld\u00a0<b>Namen.SaveToFile(&#8216;vb2.rec&#8217;);<\/b>.<\/p>\n<p>En voor de volledigheid volgt hier het gehele tweede voorbeeld:<\/p>\n<p><strong><span class=\"collapseomatic \" id=\"id69de275d2b64c\"  tabindex=\"0\" title=\"Voorbeeld 2\"    >Voorbeeld 2<\/span><div id=\"target-id69de275d2b64c\" class=\"collapseomatic_content \"><\/strong><\/p>\n<div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">unit vbU2;<\/span><\/div>\n<div id=\"vb2\">\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">interface<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">uses<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Windows, Messages, SysUtils, Classes, Graphics, Controls,\u00a0 \u00a0 Forms, Dialogs,<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 StdCtrls;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TNawRec =\u00a0\u00a0Record<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Naam, Adres, Plaats : ShortString;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Leeftijd : Byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TNAW = class<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Namen : Array of TNawRec;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 AantalNamen,HuidigeNaam : Integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 constructor Init;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Nieuw;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Volgende;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Vorige;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure SaveToFile(FileName: ShortString);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure LoadFromFile(FileName: ShortString);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TForm1 = class(TForm)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Edit1: TEdit;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Edit2: TEdit;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Edit3: TEdit;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Edit4: TEdit;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Label1: TLabel;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Label2: TLabel;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Label3: TLabel;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Label4: TLabel;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Button1: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Button2: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Button3: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Button4: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure FormCreate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Button2Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Edit1Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Edit2Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Edit3Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Edit4Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure FormActivate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Button3Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure Button4Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure FormClose(Sender: TObject; var Action: TCloseAction);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 private<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 { Private declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure UpdateScreen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 public<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 { Public declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Form1: TForm1;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">implementation<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen : TNAW;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">{$R *.DFM}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">constructor TNAW.Init;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 AantalNamen := 1;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 HuidigeNaam := 0;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 SetLength(Namen,AantalNamen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TNAW.Nieuw;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Inc(AantalNamen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 SetLength(Namen,AantalNamen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TNAW.Volgende;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Inc(HuidigeNaam);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If HuidigeNaam = AantalNamen <\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Then<br \/>\n<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Nieuw;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TNAW.Vorige;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If HuidigeNaam &gt; 0 <\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Dec(HuidigeNaam);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TNAW.LoadFromFile(FileName: ShortString);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 f : Integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 NamenFile: File of TNawRec;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 SetLength(Namen,0);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 AssignFile(NamenFile,&#8217;vb2.rec&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Reset(NamenFile);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 f := 0;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 While not Eof(NamenFile) Do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 SetLength(Namen,Succ(f));<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Read(NamenFile,Namen[f]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Inc(f);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 End;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 CloseFile(NamenFile);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 AantalNamen := f;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 HuidigeNaam := 0;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TNAW.SaveToFile(FileName: ShortString);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 f : Integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 NamenFile: File of TnawRec;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 AssignFile(NamenFile,&#8217;vb2.rec&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Rewrite(NamenFile);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 For f := 0 To AantalNamen &#8211; 1 Do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Write(NamenFile,Namen[f]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 CloseFile(NamenFile);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.FormCreate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen := TNAW.Init;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.UpdateScreen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit1.Text := Namen.Namen[Namen.Huidigenaam].Naam;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit2.Text := Namen.Namen[Namen.Huidigenaam].Adres;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit3.Text := Namen.Namen[Namen.Huidigenaam].Plaats;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit4.Text := IntToStr(Namen.Namen[Namen.Huidigenaam].Leeftijd);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button2Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen.Volgende;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 UpdateScreen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen.Vorige;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 UpdateScreen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Edit1Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen.Namen[Namen.Huidigenaam].Naam := Edit1.Text;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Edit2Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen.Namen[Namen.Huidigenaam].Adres := Edit2.Text;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Edit3Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen.Namen[Namen.Huidigenaam].Plaats := Edit3.Text;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Edit4Change(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var c : Integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Val(Edit4.Text,Namen.Namen[Namen.Huidigenaam].Leeftijd,c);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.FormActivate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Edit1.SetFocus;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button3Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen.SaveToFile(&#8216;vb2.rec&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button4Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen.LoadFromFile(&#8216;vb2.rec&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 UpdateScreen;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Closing&#8230;&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Namen.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><\/div>\n<\/div>\n<\/div>\n<p>Denk eraan alles weer netjes op te ruimen zoals hierboven gebeurt in de procedure FormClose.<\/p>\n<p><a name=\"4\"><\/a><\/p>\n<h2>Overerving<\/h2>\n<p>E\u00e9n van de grote voordelen van het werken met Classes is Overerving.<br \/>\nIedere Class stamt af van een andere Class en erft daarmee meteen alle functionaliteit van de Ouder-Class.<\/p>\n<p>Het enige wat dan nog moet gebeuren is het toevoegen van nieuwe functionaliteit.<\/p>\n<p>Zoals reeds eerder opgemerkt, doe je niets anders wanneer je in Delphi een programma schrijft.<\/p>\n<p>Het nu volgende voorbeeld is iewat gekunsteld maar is slechts ter illustratie bedoeld.<\/p>\n<p>We gaan een Class TVervoerMiddel maken met wat algemene velden en functionaliteiten.<\/p>\n<p>Daarna gaan we een aantal Classes hiervan afleiden.<\/p>\n<p>We gaan er vanuit dat ieder vervoermiddel een aantal wielen heeft (al zijn dit er misschien nul) en dat een vervoermiddel zich op een bepaalde manier voortbeweegt.<\/p>\n<p>Verder willen we bij initialisatie de waarden van de velden meegeven, en willen we methodes hebben om \u00e9\u00e9n en ander te kunnen uitlezen.<\/p>\n<p>Hier komt de definitie:<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TSoort = (rijden, vliegen, varen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TVervoerMiddel = class<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Aantal_wielen: integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Soort: TSoort;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 constructor Init(aw: integer; srt: TSoort);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 function Hoe: string;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><b><br \/>\n<\/b><\/span><br \/>\nNu gaan we een afgeleide Class TAuto maken. De nieuwe functionaliteit is het soort auto, coupe, sedan e.d..<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TAutoType = (sedan,coupe,stationwagon,cabriolet);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TAuto = class(TVervoerMiddel)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Auto_type: TAutoType;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><b><br \/>\n<\/b><\/span><br \/>\nOm aan te geven dat TAuto afstamt van TVervoerMiddel staat achter het woord Class tussen haakjes de ouder-Class, TVervoerMiddel.<\/p>\n<p>Formeel zou achter TVervoerMiddel tussen haakjes TObject moeten staan, maar daar deze Class default is mag dat ook worden weggelaten.<\/p>\n<p>De implementatie van de Constructor Init is als volgt:<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Constructor TVervoerMiddel.Init(aw: integer; srt: TSoort);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Aantal_Wielen := aw;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Soort := srt<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><b><br \/>\n<\/b><\/span><br \/>\nDit is overigens vaak de manier om aan velden een waarde toe te kennen, dus d.m.v. een Constructor of een procedure!<\/p>\n<p>Nu volgen de twee andere implementaties van TVervoerMiddel:<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">function TVervoerMiddel.Hoe: string;<br \/>\nbegin<br \/>\nCase soort of<br \/>\nrijden: Hoe := &#8216;rijdt&#8217;;<br \/>\nvliegen: Hoe := &#8216;vliegt&#8217;;<br \/>\nvaren: Hoe := &#8216;vaart&#8217;;<br \/>\nend;<br \/>\nend;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TVervoerMiddel.WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Dit vervoermiddel &#8216; + Hoe + &#8216; en heeft &#8216; + inttostr(Aantal_wielen) + &#8216; wielen.&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p>Alleen bij TAuto hebben we meer functionaliteit en moeten we derhalve een eigen WatEnHoe-procedure maken:<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TAuto.WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var tp: string;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Case Auto_type of<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 sedan: tp := &#8216;sedan.&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 coupe: tp := &#8216;coupe.&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 stationwagon: tp := &#8216;stationwagon.&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 cabriolet: tp := &#8216;cabriolet.&#8217;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 else<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 tp := &#8216;onbekend.&#8217;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Dit vervoermiddel &#8216; + Hoe<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">+ &#8216; en heeft &#8216; + inttostr(Aantal_wielen) + &#8216; wielen, en is van het type &#8216;+ tp);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><b><br \/>\n<\/b><\/span><br \/>\nMet name de laatste regen (ShowMessage) lijkt iewat dubbelop, en dat is ook zo.<br \/>\nWe zouden dit als volgt kunnen oplossen:<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TAuto.WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var tp: string;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Case Auto_type of<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 sedan: tp := &#8216;sedan.&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 coupe: tp := &#8216;coupe.&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 stationwagon: tp := &#8216;stationwagon.&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 cabriolet: tp := &#8216;cabriolet.&#8217;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 else<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 tp := &#8216;onbekend.&#8217;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 inherited WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Deze auto is van het type &#8216; + tp);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><b><br \/>\n<\/b><\/span><br \/>\nHet woord inherited zoekt naar de eerst voorgaande versie van WatEnHoe in de Class-hierarchie.<br \/>\nHet is natuurlijk wel noodzakelijk dat deze bestaat!<\/p>\n<p>Voor de volledigheid volgt hier het complete programma:<\/p>\n<p><strong><span class=\"collapseomatic \" id=\"id69de275d2b69f\"  tabindex=\"0\" title=\"Voorbeeld 3\"    >Voorbeeld 3<\/span><div id=\"target-id69de275d2b69f\" class=\"collapseomatic_content \"><\/strong><\/p>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt; letter-spacing: -0.015em;\">unit Unit1;<\/span><\/div>\n<div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">interface<\/span><\/div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">uses<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, <\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">StdCtrls;<\/span><\/div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TSoort = (rijden, vliegen, varen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 TVervoerMiddel = class<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Aantal_wielen: integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Soort: TSoort;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 constructor Init(aw: integer; srt: TSoort);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 function Hoe: string;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TAutoType = (sedan,coupe,stationwagon,cabriolet);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 TAuto = class(TVervoerMiddel)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Auto_type: TAutoType;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TFiets = class(TVervoerMiddel)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TVliegtuig = class(TVervoerMiddel)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TBoot = class (TVervoerMiddel)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">TForm1 = class(TForm)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Button1: TButton; \/\/met caption &#8216;Auto&#8217;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Button2: TButton; \/\/met caption &#8216;Fiets&#8217;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Button3: TButton; \/\/met caption &#8216;Vliegtuig&#8217;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Button4: TButton; \/\/met caption &#8216;Boot&#8217;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure FormCreate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure FormClose(Sender: TObject; var Action: TCloseAction);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure Button2Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure Button3Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure Button4Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">private<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 { Private declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">public<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 { Public declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/div>\n<div>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Form1: TForm1;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">implementation<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">{$R *.DFM}<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Auto: TAuto;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Fiets: TFiets;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Vliegtuig: TVliegtuig;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Boot: TBoot;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Constructor TVervoerMiddel.Init(aw: integer; srt: TSoort);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Aantal_Wielen := aw;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Soort := srt<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">function TVervoerMiddel.Hoe: string;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Case soort of<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 rijden: Hoe := &#8216;rijdt&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 vliegen: Hoe := &#8216;vliegt&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 varen: Hoe := &#8216;vaart&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TVervoerMiddel.WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Dit vervoermiddel &#8216; + Hoe + &#8216; en heeft &#8216; + inttostr(Aantal_wielen) + &#8216; wielen.&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TAuto.WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var tp: string;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Case Auto_type of<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 sedan: tp := &#8216;sedan.&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 coupe: tp := &#8216;coupe.&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 stationwagon: tp := &#8216;stationwagon.&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 cabriolet: tp := &#8216;cabriolet.&#8217;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 else<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 tp := &#8216;onbekend.&#8217;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 inherited WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Deze auto is van het type &#8216; + tp);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.FormCreate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Auto := TAuto.Init(4,rijden);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Auto.Auto_type := coupe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Fiets := TFiets.Init(2,rijden);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Vliegtuig := TVliegtuig.Init(16,vliegen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Boot := TBoot.Init(0,varen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Auto.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Fiets.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Vliegtuig.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Boot.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0Auto.WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button2Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0Fiets.WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button3Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0Vliegtuig.WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button4Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0Boot.WatEnHoe;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><\/div>\n<\/div>\n<\/div>\n<p>Hoewel Delphi met het werken met Classes\/objecten het hele verhaal pointer-impliciet heeft gemaakt, moet je wel goed in de gaten houden dat een Object-variabele, zoals bv Auto hierboven, niets anders dan een pointer-variabele is!<br \/>\nDe vraag is dan ook gerechtvaardigd of we geen gebruik kunnen maken van \u00e9\u00e9n Object-variabele VervoerMiddel, die we naar believen kunnen gebruiken voor een auto, fiets, vliegtuig of boot.<br \/>\nHet antwoord op die vraag luidt: JA, maar niet zomaar naar believen.<\/p>\n<p>Vandaar&#8230;<\/p>\n<p><a name=\"5\"><\/a><\/p>\n<h2>Polymorfisme<\/h2>\n<p>Polymorfisme houdt in dat een methode van het ene object dezelfde naam heeft als een methode van een ander object, met dien verstande dat beide methodes min of meer dezelfde werking hebben.<br \/>\nDenk hierbij bijvoorbeeld aan de mehode Hide die zowel bij een label als een button voorkomt en in beide gevallen het object onzichtbaar maakt. En dit terwijl een label en een button toch echt twee verschillende objecten zijn.<\/p>\n<p>Een ander voorbeeld hebben we gezien in de vorige paragraaf met de methode WatEnHoe die we voor het type TAuto hebben aangepast.<\/p>\n<p>Belangrijk hierbij op te merken is dat deze aanpassing een zogenaamde statische vorm heeft. Tijdens het compileren is al bekend hoe de methode WatEnHoe voor de verschillende objecten eruit ziet.<\/p>\n<p>Het kan echter ook dynamisch ofwel tijdens run-time uitgemaakt worden.<br \/>\nVergeet de laatste opmerking van de vorige paragraaf niet: een object-variabele is niets anders dan een pointer-variabele, ofwel een variabele die naar een geheugenplaats wijst.<\/p>\n<p>En zolang er sprake is van overerfde objecten kunnen ze allemaal aan 1 object-variabele worden toegekend.<\/p>\n<p>Overigens spreken we in het eerste geval van &#8220;early-binding&#8221;, dus een koppeling tijdens compileren, en in het tweede geval van &#8220;late-binding&#8221;, een koppeling tijdens de uitvoer.<\/p>\n<p>Met het komende voorbeeld begint het dus ergens op te lijken.<\/p>\n<p>In het volgende voorbeeld maken we een Class TDier waar we de Class THond en TKat vanaf zullen leiden.<\/p>\n<p>De Class TDier zou er als volgt uit kunnen zien:<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TDier = class<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WatZegIk;virtual;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><b><br \/>\n<\/b><\/span><br \/>\nMet de methode WieBenIk moet duidelijk worden gemaakt om welk dier het gaat, en met de methode WatZegIk moet duidelijk worden gemaakt welk geluid het dier maakt.<\/p>\n<p>Verder is de methode WieBenIk statisch en is de methode WatZegIk dynamisch.<\/p>\n<p>Om aan te geven dat een methode dynamisch is, dus dat pas tijdens run-time bepaalt moet worden welke implementatie moet worden uitgevoerd, voegen we bij de ouder-klasse (of bron-klasse of root-class) het woordje\u00a0<b>virtual<\/b>\u00a0toe.<\/p>\n<p>Bij iedere afstammeling voegen we bij de dynamische methode het woordje\u00a0<b>override<\/b>\u00a0toe.<\/p>\n<p>Hier volgen de definitie&#8217;s van THond en TKat:<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">THond = class(TDier)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WatZegIk;override;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">TKat = class(TDier)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><b><br \/>\n<\/b><\/span><br \/>\nMerk op dat bij THond de methode WatZegIk dynamisch is, maar bij TKat niet!<\/p>\n<p>Dan volgen nu de implementatie&#8217;s van de verschillende classes:<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TDier.WieBenIk;<br \/>\nbegin<br \/>\nShowMessage(&#8216;Ik ben een dier&#8217;);<br \/>\nend;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TDier.WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik maak geluid&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure THond.WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik ben een hond&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure THond.WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik blaf&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TKat.WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik ben een kat&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TKat.WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik mauw&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p>Deze implementatie&#8217;s roepen hopelijk geen vragen op, behalve dan dat de woordjes virtual en override alleen maar in de class-definitie voorkomen.<\/p>\n<p>Maak nu eens een Delphi-project met een button waarin bovenstaande verwerkt is met een button-Click-Event zoals in het nu volgende uitgewerkte voorbeeld:<\/p>\n<p><strong><span class=\"collapseomatic \" id=\"id69de275d2b6cc\"  tabindex=\"0\" title=\"Voorbeeld 4\"    >Voorbeeld 4<\/span><div id=\"target-id69de275d2b6cc\" class=\"collapseomatic_content \"><\/strong><\/p>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt; letter-spacing: -0.015em;\">unit Unit1;<\/span><\/div>\n<div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">interface<\/span><\/div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">uses<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">TDier = class<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WatZegIk;virtual;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">THond = class(TDier)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WatZegIk;override;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">TKat = class(TDier)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">TForm1 = class(TForm)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Button1: TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 procedure Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 private<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 { Private declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 public<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 { Public declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Form1: TForm1;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">implementation<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">{$R *.DFM}<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TDier.WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik ben een dier&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TDier.WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik maak geluid&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure THond.WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik ben een hond&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure THond.WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik blaf&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TKat.WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik ben een kat&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TKat.WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;Ik mauw&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.Button1Click(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier : TDier;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Kat : TKat;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier := TDier.Create;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier.WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier.WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier.Free;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier := THond.Create;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier.WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier.WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier.Free;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Kat := TKat.Create;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Kat.WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Kat.WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Kat.Free;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier := TKat.Create;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier.WieBenIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier.WatZegIk;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dier.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><span style=\"font-family: NonBreakingSpaceOverride, 'Hoefler Text', Garamond, 'Times New Roman', serif; letter-spacing: normal;\"><\/div><\/span><\/div>\n<\/div>\n<p>&#8211;\u00a0<i>Probeer voordat je dit programma runt eerst de uitkomst te voorspellen<\/i><\/p>\n<p>Hoe werkt dit nu precies?<\/p>\n<p>De methode WieBenIk is in alle klasses statisch, d.i. iedere klasse heeft zijn eigen WieBenIk. De methode WatZegIk is bij TDier dynamisch gemaakt en wordt op dezelfde wijze overgenomen door THond. Bij TKat echter wordt de methode WatZegIk weer statisch. Afstammelingen van TKat kunnen geen dynamische WatZegIk-methode hebben!<\/p>\n<p>De variabele Dier in het voorbeeld wordt gedeclareerd als van het type TDier. Dat betekend dat bij iedere aanroep van de methode WieBenIk als antwoord \u2018Ik ben een dier\u2019 komt, omdat WieBenIk statisch is gedeclareerd. Dat laatste betekent dat de binding tijdens het compileer-proces plaats vindt (early-binding). De methode WatZegIk is echter dynamisch gedeclareerd wat betekent dat pas tijdens runtime bepaald wordt welke WatZegIk-methode moet worden gebruikt (late binding). Wanneer Dier een instantie van THond is zal WatZegIk als resultaat \u2018Ik blaf\u2019 geven. Bij TKat gaat dat verhaal niet meer op, omdat WatZegIk daar weer als statisch is gedeclareerd.<\/p>\n<p><a name=\"6\"><\/a><\/p>\n<h2>Encapsulation<\/h2>\n<p>Het is een goed gebruik binnen het werken met Classes om op een correcte wijze om te gaan met de scope of zichtbaarheid van velden en methodes.<br \/>\nEn hier onstaat, naar mijn mening, een probleem in Delphi, waarover zometeen meer.<\/p>\n<p>Een Class kent 4 soorten van scope:<\/p>\n<ul>\n<li>private<\/li>\n<li>protected<\/li>\n<li>public (default)<\/li>\n<li>published<\/li>\n<\/ul>\n<h6>private<\/h6>\n<p>Alle velden en methodes die onder private worden gedeclareerd zijn alleen zichtbaar in de implementatie van de Class zelf.<\/p>\n<p>Het is een goed gebruik alle interne velden en methodes private te declareren.<\/p>\n<h6>protected<\/h6>\n<p>Alle velden en methodes die onder protected worden gedeclareerd zijn alleen zichtbaar in de implementatie van de Class en zijn afgeleiden.<\/p>\n<h6>public<\/h6>\n<p>Alle velden en methodes die onder public worden gedeclareerd zijn altijd en overal zichtbaar.<\/p>\n<p>Wanneer geen gebruik wordt gemaakt van \u00e9\u00e9n van de directives wordt dit als public beschouwd.<\/p>\n<h6>published<\/h6>\n<p>Het gebruik van published heeft te maken met componenten en properties en wordt hier niet verder behandeld.<\/p>\n<h6>Verstoring scope in Delphi<\/h6>\n<p>Het probleem van bovenstaande is dat wanneer je e.e.a. in de praktijk wilt testen en je beperkt je daarbij tot \u00e9\u00e9n en dezelfde Unit, het hele scope-verhaal de mist in gaat, omdat de scope-regels van de unit preveleren boven die van de Classes.<br \/>\nNaar mijn mening is dit een ernstige tekortkoming in Delphi.<\/p>\n<p><a name=\"7\"><\/a><\/p>\n<h2>Dynamische componenten<\/h2>\n<p>Het volgende voorbeeld laat zien hoe je tijdens run-time componenten kunt aanmaken en weer weggooien. Dit kan erg handig zijn, denk maar bv. aan een report-generator of iets dergelijks.<\/p>\n<p>Bij het gebruik van dynamische componenten zijn een aantal zaken waarmee rekening moet worden gehouden:<\/p>\n<ol>\n<li>Bij Create aangeven wat de container is<\/li>\n<li>Expliciet de Parent-property vullen<\/li>\n<li>Eventueel andere properties vullen<\/li>\n<li>Eventueel voor unieke naamgeving zorgen<\/li>\n<li>Zelf Procedures aan Events koppelen<\/li>\n<\/ol>\n<p>Bij dynamische componenten heb je natuurlijk geen object-inspector tot je beschikking en zul je bovenstaande zaken dus zelf moeten regelen.<\/p>\n<p>&#8211;\u00a0<i>Start een nieuw project in Delphi en open het code-venster<\/i><\/p>\n<p>&#8211;\u00a0<i>Voeg bij de Uses-clausule toe:<br \/>\n<b>StdCtrls<\/b><\/i><\/p>\n<p>&#8211;\u00a0<i>Voeg via de Object-inspector de event-handlers FormCreate en FormClose toe<\/i><\/p>\n<p>&#8211;\u00a0<i>Voeg in het code-venster onder de procedure FormClose de volgende regel toe:<br \/>\n<b>procedure KnopKlik(Sender: TObject);<\/b><\/i><\/p>\n<p>&#8211;\u00a0<i>Voeg in het code-venster onder de directive private de volgende regel toe:<br \/>\n<b>Knop: TButton;<\/b><\/i><\/p>\n<p>&#8211;\u00a0<i>Voeg in het code-venster in de event-handler FormCreate de volgende regels toe:<br \/>\n<span style=\"font-family: courier new; font-size: small;\"><b><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Knop := TButton.Create(Self);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">with Knop do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Parent := Self;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Caption := &#8216;Klik me&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 OnClick := KnopKlik;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Top := 50;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Left := 150;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Hint := &#8216;This is what we call a button [&#8216;+IntToStr(SizeOf(Knop))+&#8217;]&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 ShowHint := True;<\/span><br \/>\n<\/b><strong><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><\/strong><b><br \/>\n<\/b><\/span><\/i><br \/>\n&#8211;\u00a0<i>Voeg in het code-venster in de event-handler FormClose de volgende regel toe:<br \/>\n<b>Knop.Free;<\/b><\/i><\/p>\n<p>&#8211;\u00a0<i>Voeg in het code-venster de event-handler KnopKlik toe:<br \/>\n<span style=\"font-family: courier new; font-size: small;\"><b><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Procedure TForm1.KnopKlik(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 showmessage(&#8216;Knop geklikt&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><br \/>\n<\/b><\/span><\/i><br \/>\n&#8211;\u00a0<em>R<\/em><i>un het project<\/i><\/p>\n<p>Je hebt nu, tijdens het runnen, een form met een knop erop. Wanneer je op de knop klikt wordt keurig de event-handler KnopKlik uitgevoerd.<\/p>\n<p>Omdat je in design-time niets op het form hebt gezet weet Delhi niet dat je tijdens run-time gebruik maakt van controls, vandaar dat je zelf de unit StdCtrls moet toevoegen aan de Uses-clausule.<\/p>\n<p>Het woordje Self refereert aan het ouder-object ofwel de container waar de control deel van uit gaat maken. En ondanks het feit dat je dat al aangeeft bij de creatie van de control moet dit ook nog expliciet worden toegekend aan de propertie (eigenschap) Parent.<\/p>\n<p>We gaan bovenstaand project uitbreiden met een listbox waarin items zitten waarop gedubbelklikt kan worden en een tiental labeltjes.<\/p>\n<p>Om die labeltjes te maken kun je natuurlijk gebruik maken van 10 object-variabelen, maar het kan gelukkig ook met 1. Het enige belangrijke is dan wel dat je kunt\/moet bijhouden waar zo&#8217;n label zich dan bevindt, bijvoorbeeld voor het vrijmaken van het label.<br \/>\nDaarvoor kun je gebruik maken van de TList-class, die precies bijhoudt waar een control zich in het geheugen bevindt. Via een object van TList kun je dus altijd bij het gewenste control komen.<\/p>\n<p>De procedure KnopKlik is in het volgende voorbeeld veranderd.<\/p>\n<p><strong><span class=\"collapseomatic \" id=\"id69de275d2b6f7\"  tabindex=\"0\" title=\"Voorbeeld 5\"    >Voorbeeld 5<\/span><div id=\"target-id69de275d2b6f7\" class=\"collapseomatic_content \"><\/strong><\/p>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt; letter-spacing: -0.015em;\">unit Unit1;<\/span><\/div>\n<div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">interface<\/span><\/div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">uses<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, <\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">StdCtrls;<\/span><\/div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TForm1 = class(TForm)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure FormCreate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure KnopKlik(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure ListBoxDubbelKlik(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 procedure FormClose(Sender: TObject; var Action: TCloseAction);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 private<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 { Private declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Knop : TButton;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 LabelLijst : TList;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Labeltje : TLabel;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 ListBox: TListBox;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 public<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 { Public declarations }<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Form1: TForm1;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">implementation<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">{$R *.DFM}<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.FormCreate(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var a : Byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 LabelLijst := TList.Create;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ListBox := TListBox.Create(Self);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 with ListBox do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Parent := Self;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 OnDblClick := ListBoxDubbelKlik;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 for a := 0 to 9 do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 Items.Add(&#8216;Item &#8216;+IntToStr(a));<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Top := 100;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Left := 150;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Hint := &#8216;This is a listbox: DubbleClick on Items [&#8216;+IntToStr(SizeOf(ListBox))+&#8217;]&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 ShowHint := True;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Knop := TButton.Create(Self);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 with Knop do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Parent := Self;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Caption := &#8216;Klik me&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 OnClick := KnopKlik;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Top := 50;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Left := 150;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Hint := &#8216;This is what we call a button [&#8216;+IntToStr(SizeOf(Knop))+&#8217;]&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 ShowHint := True;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for a := 1 To 10 do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Labeltje := TLabel.Create(Self);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 with Labeltje do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Parent := Self;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Caption := &#8216;Dynamisch aangemaakt&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 AutoSize := True;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Top := a*30;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Hint := &#8216;This is dynamic label &#8216;+IntToStr(a)+&#8217; [&#8216;+IntToStr(SizeOf(Labeltje))+&#8217;]&#8217;;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ShowHint := True;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LabelLijst.Add(Labeltje);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Labeltje.Color := clRed;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Labeltje := LabelLijst.Items[4];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Labeltje.Color := clBlue;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.KnopKlik(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var a : Byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If LabelLijst.Count &gt; 0 <\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 ShowMessage(&#8216;Labeltjes weghalen&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 For a := 0 To LabelLijst.Count &#8211; 1 do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Labeltje := LabelLijst.Items[a];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Labeltje.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LabelLijst.Items[a] := nil;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 LabelLijst.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.ListBoxDubbelKlik(Sender: TObject);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ShowMessage(&#8216;U koos &#8216;+ListBox.Items[ListBox.ItemIndex]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var a: Byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If LabelLijst.Count &gt; 0 <\/span><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 For a := 0 To LabelLijst.Count &#8211; 1 do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Labeltje := LabelLijst.Items[a];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Labeltje.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LabelLijst.Items[a] := nil;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 LabelLijst.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Knop.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ListBox.Free;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/div>\n<div><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><span style=\"font-family: NonBreakingSpaceOverride, 'Hoefler Text', Garamond, 'Times New Roman', serif; letter-spacing: normal;\"><\/div><\/span><\/div>\n<\/div>\n<p>Probeer bovenstaand programma te doorgronden. Dit verschaft je nu een flexibele techniek om je forms te kunnen bouwen, bijvoorbeeld je eigen report-generator gekoppel aan een of andere database o.i.d..<\/p>\n<h2>Tot slot<\/h2>\n<p>Veel van de voorbeelden komen uit een van de boeken van Marco Cant\u00f9, de Delphi-Goeroe!<\/p>\n<p>Ik hoop dat dit, misschien wat taaie, hoofdstuk je op weg heeft geholpen naar een nieuwe manier van programmeren en meer kennis van wat er zoal in de achtergrond van Delphi gebeurt.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Inleiding In dit hoofdstuk zal ik proberen de basis-principes van Object Oriented Programming uit te leggen. Ik zal dat doen aan de hand van een viertal voorbeelden. Als uitgangspunt neem ik de uitbreiding van Records naar Classes. Overigens is dit hoofdstuk bedoeld voor mensen die al wat langer met Delphi programmeren. In dit hoofdstuk leer [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":309,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"templates\/template-full-width.php","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"class_list":["post-311","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Oeps - Wiskunst<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/oeps\/\" \/>\n<meta property=\"og:locale\" content=\"nl_NL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oeps - Wiskunst\" \/>\n<meta property=\"og:description\" content=\"Inleiding In dit hoofdstuk zal ik proberen de basis-principes van Object Oriented Programming uit te leggen. Ik zal dat doen aan de hand van een viertal voorbeelden. Als uitgangspunt neem ik de uitbreiding van Records naar Classes. Overigens is dit hoofdstuk bedoeld voor mensen die al wat langer met Delphi programmeren. In dit hoofdstuk leer [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/oeps\/\" \/>\n<meta property=\"og:site_name\" content=\"Wiskunst\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-24T12:09:24+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Geschatte leestijd\" \/>\n\t<meta name=\"twitter:data1\" content=\"23 minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/delphi-lazarus\\\/oeps\\\/\",\"url\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/delphi-lazarus\\\/oeps\\\/\",\"name\":\"Oeps - Wiskunst\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/#website\"},\"datePublished\":\"2022-01-21T09:54:49+00:00\",\"dateModified\":\"2022-01-24T12:09:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/delphi-lazarus\\\/oeps\\\/#breadcrumb\"},\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/delphi-lazarus\\\/oeps\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/delphi-lazarus\\\/oeps\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/wiskunst.nl\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programmeren\",\"item\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Delphi\\\/Lazarus\",\"item\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/delphi-lazarus\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Oeps\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/#website\",\"url\":\"https:\\\/\\\/wiskunst.nl\\\/\",\"name\":\"Wiskunst\",\"description\":\"2\u221e\u2227&gt;\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wiskunst.nl\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"nl-NL\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Oeps - Wiskunst","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/oeps\/","og_locale":"nl_NL","og_type":"article","og_title":"Oeps - Wiskunst","og_description":"Inleiding In dit hoofdstuk zal ik proberen de basis-principes van Object Oriented Programming uit te leggen. Ik zal dat doen aan de hand van een viertal voorbeelden. Als uitgangspunt neem ik de uitbreiding van Records naar Classes. Overigens is dit hoofdstuk bedoeld voor mensen die al wat langer met Delphi programmeren. In dit hoofdstuk leer [&hellip;]","og_url":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/oeps\/","og_site_name":"Wiskunst","article_modified_time":"2022-01-24T12:09:24+00:00","twitter_card":"summary_large_image","twitter_misc":{"Geschatte leestijd":"23 minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/oeps\/","url":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/oeps\/","name":"Oeps - Wiskunst","isPartOf":{"@id":"https:\/\/wiskunst.nl\/#website"},"datePublished":"2022-01-21T09:54:49+00:00","dateModified":"2022-01-24T12:09:24+00:00","breadcrumb":{"@id":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/oeps\/#breadcrumb"},"inLanguage":"nl-NL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/oeps\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/oeps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wiskunst.nl\/"},{"@type":"ListItem","position":2,"name":"Programmeren","item":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/"},{"@type":"ListItem","position":3,"name":"Delphi\/Lazarus","item":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/delphi-lazarus\/"},{"@type":"ListItem","position":4,"name":"Oeps"}]},{"@type":"WebSite","@id":"https:\/\/wiskunst.nl\/#website","url":"https:\/\/wiskunst.nl\/","name":"Wiskunst","description":"2\u221e\u2227&gt;","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wiskunst.nl\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"nl-NL"}]}},"_links":{"self":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/comments?post=311"}],"version-history":[{"count":28,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/311\/revisions"}],"predecessor-version":[{"id":593,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/311\/revisions\/593"}],"up":[{"embeddable":true,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/309"}],"wp:attachment":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/media?parent=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}