{"id":1470,"date":"2017-06-15T14:46:02","date_gmt":"2017-06-15T12:46:02","guid":{"rendered":"http:\/\/borkedcode.com\/wp\/?p=1470"},"modified":"2017-06-15T14:46:02","modified_gmt":"2017-06-15T12:46:02","slug":"a-delphi-primer-with-rad-studio-10-2","status":"publish","type":"post","link":"https:\/\/borkedcode.com\/wp\/?p=1470","title":{"rendered":"A Delphi Primer with RAD Studio 10.2"},"content":{"rendered":"<p>Hey hey, everyone!<\/p>\n<p>Today is a day off for a public holiday \u2013 couldn\u2019t tell you which one off the top of my head \u2013 in Germany.\u00a0 They do a few of these in May and June, and this time around one of them fell on this Thursday.\u00a0 I\u2019ll be back in the office tomorrow, but I wanted to take a few hours to put this together as the real start of my \u201crefresher\u201d with Delphi.<\/p>\n<p>A little personal background \u2013 the last version I did any serious work with was in 2009, while working for a company that did an automotive dealership ERP system.\u00a0 They were working with Delphi 7, and had started looking into Visual Studio, but at the time VS was still insisting a lot of repetitive code for data access and it just pissed everyone off.<\/p>\n<p>So \u2013 I went on after that and my memory of Delphi at that time was of the \u201cold school\u201d IDE (\u201cIDE\u201d = \u201cIntegrated Development Environment\u201d, which just means the app that is designed to host your programming effort and the tools that accompany it \u2013 as opposed to picking up a bundle of various unrelated stuff and working haphazardly with it), we still had BDE, and all that.\u00a0 I played around a little with XE3, but not enough to be re-proficient with it.\u00a0 So let\u2019s change that a bit, shall we?<\/p>\n<p>I\u2019m going to approach this as if I was a beginner, who has just signed on with a firm or just bought my own copy and plugged in my license key.<\/p>\n<p>As it happens, I\u2019m currently staying (temporarily living) in a teensy little cave of a one-bedroom apartment, and where I\u2019m sitting right now I don\u2019t have WiFi.\u00a0 As a result, I got a battery of errors when I started up \u2013 everything was trying to run scripts on the page, but none of the failures were of a fatal nature.\u00a0 I won\u2019t detail those, because it\u2019s entirely possible those were my own doing from a prior project.<\/p>\n<p>In the \u201cold school\u201d, the first thing you\u2019d get was a form designer, an object inspector, a VCL bar across the top, and probably a project manager.\u00a0 None of these were docked, it was a multi-window app (\u201cMDI\u201d in the terminology of programming, which I guess you\u2019d better get used to \u2013 MDI means \u201cmultiple-document interface\u201d).\u00a0 This was largely because of Delphi\u2019s origins as a construction site for Windows GUI applications \u2013 it later grew into much, much more, but kept to its heritage in how it presented itself with a first impression of \u201clet\u2019s build a Windows app\u201d.<\/p>\n<p>Here, we get a single-window app (an \u201cSDI\u201d \u2013 \u201csingle document interface\u201d) where all the tools are docked to one another.\u00a0 The most prominent visual that pulls you in is an almost-center section of \u2018new\u2019 options for making new projects:<\/p>\n<p><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-1472\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-1-300x295.jpg\" alt=\"\" width=\"300\" height=\"295\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-1-300x295.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-1.jpg 454w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>So\u2026as a new user, the first thing I\u2019d like to see is \u201cGetting Started\u201d.\u00a0 Except\u2026I\u2019m in an unusual state of not being connected to the Internet right now, this requires an internet connection to get to, so maybe we\u2019ll come back to that.<\/p>\n<p>I guess we\u2019ll just have to muscle through on our own.<\/p>\n<p>So as a programming system, most tools revolve around a concept of a project, or an app, or some similar goal-oriented thing which will eventually be built and run independently on a computer of some kind.\u00a0 In Delphi\u2019s case, it\u2019s a \u201cProject Group\u201d now (used to be just a \u201cproject\u201d, but around Delphi 5 time frame most apps built for business in Delphi had multiple independent components that talked to one another and shared work across platforms in something like n-tier architecture, or via Web Service in Delphi 6, etc.).<\/p>\n<p>Choosing \u201cCreate a new Project\u201d from the screen selections here results in a dialog helping you to determine what kind of project you want:<a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1473 alignright\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-2-300x230.jpg\" alt=\"\" width=\"223\" height=\"171\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-2-300x230.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-2-768x589.jpg 768w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-2.jpg 866w\" sizes=\"auto, (max-width: 223px) 100vw, 223px\" \/><\/a><\/p>\n<p>I\u2019ve never been a huge fan of C++ syntax, and since a beginner is going to be our target audience, let\u2019s go with a Delphi app.\u00a0 Highlighting \u201cDelphi Projects\u201d presents a list of various choices in the right-hand pane\u2026<\/p>\n<p><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft  wp-image-1474\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-3-300x266.jpg\" alt=\"\" width=\"238\" height=\"211\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-3-300x266.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-3.jpg 693w\" sizes=\"auto, (max-width: 238px) 100vw, 238px\" \/><\/a><\/p>\n<p>Some of these sound damned cool.\u00a0 An Android service?\u00a0 I\u2019ve got an Android phone\u2026as well as an NVidia Shield on my TV.\u00a0 But that\u2019s a little advanced for right now, so let\u2019s stick with the basics.\u00a0 Console apps are for black-and-white command-line stuff, generally with no UI, and that shit\u2019s for Linux chumps J.\u00a0 We\u2019re programming for a Real OS, Windows.\u00a0 Something people use daily.<\/p>\n<p>Which reminds me \u2013 what are we going to build?\u00a0 One of the things that people who want to learn to program generally don\u2019t think about is the answer to that question.\u00a0 \u201cWhat the hell am I gonna make with this thing?\u201d\u00a0 That was one of my big stumbling blocks too, way back in the \u201890s when I bought my first copy of Borland C++, its fifty 3.5\u201d floppy disks and its forty pounds of books.\u00a0 I played around with that thing, but that\u2019s all it was, I was playing.\u00a0 I didn\u2019t have the foggiest clue what to build then.<\/p>\n<p>So let\u2019s make up our minds.\u00a0 All programming starts simple, let\u2019s pay homage to the classics and do an old-fashioned \u201chello world\u201d.\u00a0 We\u2019ll look at the parts of the development environment that help us do that, and I\u2019ll highlight some advantages we get in Delphi that don\u2019t really come easy.<\/p>\n<p>The project that fits this description best for my purpose here is a VCL Forms App \u2013 as long as we\u2019re going back home, let\u2019s do it old-school style.<\/p>\n<p>VCL means \u201cVisual Component Library\u201d \u2013 and it means the framework of pre-built stuff that is in the development system.\u00a0 Frameworks are what drive programming systems.\u00a0 Without a framework, all you\u2019d really have is a compiler and text files, and you\u2019d have to build quite simply <em>everything <\/em>by yourself.<\/p>\n<p>And that would suck.\u00a0 A lot.<\/p>\n<p>So about five minutes after the first programmers started writing programs that could be stored on something other than a gigantic deck of #$%&amp;ing tarot cards, they started writing frameworks.\u00a0 Frameworks are pre-packaged blocks of code that represent things which get built a lot.\u00a0 For example, take the humble little button on your screen.<a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1475 alignright\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-4-300x215.jpg\" alt=\"\" width=\"254\" height=\"182\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-4-300x215.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-4.jpg 443w\" sizes=\"auto, (max-width: 254px) 100vw, 254px\" \/><\/a><\/p>\n<p>Buttons get used all over the place.\u00a0 So do things like text boxes, labels, even the window itself gets used quite a bit.\u00a0 A good framework will have pre-built code that contains these things, so you the programmer don\u2019t have to re-invent the damn wheel just so you can write \u201chello world\u201d or something.<\/p>\n<p>Delphi in its original state had VCL, and that was it.\u00a0 Borland C++ had OWL (\u201cObject Window Library\u201d), Microsoft had MFC or something for its C++ side, Visual Basic had a bunch of \u201cOCX\u201d controls (I can\u2019t remember if I ever even knew what OCX stood for).<\/p>\n<p>I\u2019m going to take a long tangent here.\u00a0 If you want to dive in with the \u201chello world\u201d, jump down a ways and skip all this talk about frameworks and libraries and stuff.\u00a0 This info will be useful though, if not now, then later.<\/p>\n<h2>About Frameworks\u2026<\/h2>\n<p>Originally VCL was one great big fat chunk of code that would get pulled into your app and you\u2019d have a 600k executable that would pop up your window and say \u201chello world\u201d.\u00a0 At the time, that was pretty freaking huge, despite being really fast.\u00a0 By the time Delphi 2 was released, it was even bigger, and because we had a forest of third-party controls one could buy, every one of those controls would have to be re-compiled into the original VCL code, which promised to become a real spaghetti mess.\u00a0 About two years \u2013 and two product versions \u2013 after the v1 release, the VCL got split into many smaller interoperating chunks we called \u201cpackages\u201d, so your 600k .exe file shrank down to a svelte 80-120k or so, and more importantly all those 3<sup>rd<\/sup>-party systems became self-contained bundles that didn\u2019t threaten to corrupt the core VCL.<\/p>\n<p>Another benefit to this was that it kept compile times reasonable.\u00a0 When Delphi crashed the party in 1995, Windows apps were largely C++ stuff \u2013 which includes Visual Basic.\u00a0 VB was built in C++, and itself was not a \u201ccompiled\u201d app until much later.\u00a0 The C++ compilers at the time, running on PC processors, could take <em>hours<\/em> to build an app and put it all together.\u00a0 In the case of really big ones, it might be <em>days<\/em>.\u00a0 Delphi popped up, and all that changed \u2013 Delphi could compile an app in <em>seconds.<\/em>\u00a0 Usually in the single- or low-two-digit seconds.\u00a0 And Delphi\u2019s IDE was written using the Delphi compiler, and all million-odd lines of code in that could compile in <em>minutes.<\/em>\u00a0 That was a really big deal.<\/p>\n<p>Oh yeah \u2013 let\u2019s talk for a sec about what \u201ccompiled\u201d means.\u00a0 Compilation at its most basic level means taking one kind of code and converting it into another.\u00a0 Usually that\u2019s in the context of taking something a human wrote and turning it into something that a PC chip and operating system can understand and act on.\u00a0 This is in contrast to \u201cinterpreted\u201d or \u201cscripted\u201d code, where something reads the instructions written and simply performs the actions described in them.\u00a0 In a compiled app, the <em>compiler<\/em> reads your code, and it builds a self-contained output \u2018thing\u2019 (in our case here, an executable file), and then it goes back to bed.\u00a0 The output is the actor, and it has within it all the instructions you gave, ready to go.\u00a0 In an interpreted app, an <em>interpreter<\/em> holds your code in the form of a \u201cscript\u201d and acts on it, line-by-line \u2013 it\u2019s the interpreter that does all the action.\u00a0 As a result, it is both slower and more limited in its possible actions.<\/p>\n<p>Today, with the current crop of processors, compile times aren\u2019t that big a deal any more.\u00a0 When you can throw six or eight cores with possibly two threads per at a compiler, there\u2019s not a whole lot out there which will take a great deal of time to build.\u00a0 Similarly, most interpreters, despite being a bit clunky, operate like they\u2019ve mainlined about a kilo of coke on a modern processor.\u00a0 They\u2019re still limited in a lot of ways (for example, one comes to mind which doesn\u2019t support using all those cores and threads \u2013 it still just fumbles along running one process per CPU), but the big differential between compiled and interpreted isn\u2019t quite the gulf it used to be.<\/p>\n<p>Back to building our app, and the frameworks involved.\u00a0 Today, pretty much everything Microsoft\u2019s environment works with is \u201c.NET\u201d.\u00a0 They have what\u2019s called the \u201c.NET Framework\u201d.\u00a0 Very original.\u00a0 (For quite some time before and well after release, Microsoft had some serious communication problems \u2013 most people inside and out simply didn\u2019t understand what \u2018.NET\u2019 was supposed to be about.)<\/p>\n<p>Delphi has VCL \u2013 and several other frameworks.\u00a0 These all appear as \u201ccomponents\u201d which can be dropped into an app, \u201cwired\u201d together with settings and code, and will be compiled into it when you tell the IDE to build your program.\u00a0 VCL has been, and probably always will be, largely about Windows.\u00a0 The framework makes the creation of windows and controls by calling functions in the Windows operating system which themselves call functions in the hardware of your PC \u2013 the disk, memory, chip(s), video card(s), etc.<\/p>\n<p>It also has \u201cRTL\u201d \u2013 the Run-Time Library.\u00a0 RTL is a set of non-visual code bundles that encompass common operations not necessarily involved with building visual applications.\u00a0 A good example of an RTL unit is \u201cMath\u201d.\u00a0 There\u2019s a unit actually called math, which is full of functions and procedures that all revolve around mathematical operations like rounding, modulus, sine\/cosine, and even things like figuring out payment schedules, net present value, future value, etc.\u00a0 I specifically call this out because one of my earliest self-designed apps used a lot of geometric functions to produce 2-dimensional graphics on demand, and I ended up reinventing a lot of Euclidian geometry in code to accomplish it \u2013 I was ignorant of the math unit in the RTL.\u00a0 If I\u2019d known about this thing, I\u2019d have saved myself <em>weeks<\/em> of coding time.\u00a0 Much of RTL doesn\u2019t hinge on the Windows system, but is independent of this.\u00a0 I mention <em>that<\/em>, because while Visual Studio is entirely about Windows\u2026<\/p>\n<p>Delphi doesn\u2019t just do Windows any longer.<\/p>\n<p>Delphi also has \u201cFireMonkey\u201d (don\u2019t look at me, I didn\u2019t name the thing), which is aimed at cross-platform programming \u2013 which means stuff built on the FM framework can run on Windows, iOS (Apple\u2019s OS for phones and Macs), and Android.\u00a0 There aren\u2019t quite as many components in FM as in VCL, but there are plenty to get the job done.\u00a0 And what you build for one, can then be built for each of the others \u2013 so a \u201chello world\u201d for Windows can also be compiled and delivered to an iPhone and an Android device without changing your code.\u00a0 Of course, if you use platform-exclusive functions (for example, Microsoft SQL Server might be your data repository), you will limit the cross-platform nature of FM to just that platform, so keep that in mind.<\/p>\n<p>Other, smaller frameworks that Delphi makes available include<\/p>\n<ul>\n<li>EMS \u201cEnterprise Mobility Services\u201d, which links to the \u2018mobile enterprise application platform\u2019, which I\u2019m not at all familiar with and smells strangely of CORBA. Basically, if you\u2019re starting up in Delphi and you don\u2019t recognize what this is, avoid it.<\/li>\n<li>DataSnap, a framework that enables you to divide your application\u2019s working parts among multiple packaged applications\/libraries, all of which can then connect to one another and trade data or invoke each others\u2019 functionality, either on the same PC or spread out over a network.<\/li>\n<li>Web Broker, a set of components that enable your apps to become web server extensions and generate content in the form of HTML or XML documents as responses to being called over HTTP.<\/li>\n<li>IntraWeb, an app framework that enables you to cook up web apps with a visual interface.<\/li>\n<\/ul>\n<p>In addition to these frameworks, Delphi also enables you to make calls directly to your platform API (which means making calls directly to the operating system of the computer on which you\u2019re running) either as a straight-through call or by using pass-through calls that are contained in code units supplied with the RTL.\u00a0 (These units don\u2019t quite amount to a library, but they are provided to simplify making the connection to the operating system.)<\/p>\n<h2>Back to the application\u2026<\/h2>\n<p>So, where were we?\u00a0 Oh yeah, we were going to do \u201chello world\u201d \u2013 and courtesy of all the work that went into building the VCL, it\u2019s going to be dirt-simple to create the window, complete with a button and a pop-up dialog that contains our message.\u00a0 We\u2019ll do it with only one line of code \u2013 without the framework, it would be <em>thousands<\/em> of lines.<\/p>\n<p>From the center pane of the IDE, choose \u201cCreate a new project\u2026\u201d and choose \u201cDelphi Projects,\u201d then \u201cVCL Forms Application\u201d; or alternatively you can use the menus File &gt; New &gt; VCL Forms Application\u2026<\/p>\n<p>Whichever route you chose, you land here:<\/p>\n<p><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-5.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-1476\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-5-300x154.jpg\" alt=\"\" width=\"300\" height=\"154\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-5-300x154.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-5-768x393.jpg 768w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-5-1024x524.jpg 1024w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-5.jpg 1697w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I\u2019m a bit of a stickler here, and despite my old-school start, I noticed over on the side there it says that my target platform is 32-bit Windows.<\/p>\n<p><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-6.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-1477\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-6.jpg\" alt=\"\" width=\"229\" height=\"30\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Well, to be truthful, I haven\u2019t had a 32-bit CPU or operating system in my house since what, 2006?\u00a0 Maybe 2007?\u00a0 So let\u2019s change that and add Win64 and make it our target.\u00a0 This laptop is on 64-bit Windows, and that fits my goals just fine.<\/p>\n<p>In the Project Manager on the right of the screen, right-click the \u201cTarget Platforms\u201d entry and select \u201cadd platform\u201d from the menu that appears.\u00a0 You\u2019ll be rewarded with this dialog:<a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-7.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-1478\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-7-300x150.jpg\" alt=\"\" width=\"300\" height=\"150\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-7-300x150.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-7.jpg 369w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Once you OK this, 64-bit Windows will be added to the targets, and it will be made \u201cactive\u201d (it\u2019ll be bold in that list).\u00a0 Active means that when you compile, the executable that gets built will be for the target platform currently bolded.\u00a0 I\u2019m going to remove the 32-bit windows target, just because it clutters up my space and I don\u2019t have anywhere right now where I need a 32-bit app.\u00a0 Right-click on the unneeded one and delete it if you want to do the same.<\/p>\n<p>In times gone by the VCL would be stretched out across the bottom of the menu bar as a set of square icons in a tabbed interface at the top of my IDE.\u00a0 This got a bit unwieldy towards the Delphi 8 time frame (mid 2000s), because a vanilla install would end up with more than a dozen tabs, easily.\u00a0 Since then it has grown to something like fifty categories, and there\u2019s no really good way to present that many options in a GUI interface.\u00a0 The current version packs the VCL controls as well as a bunch of 3<sup>rd<\/sup>-party and multi-framework options into a long expandable list called the \u201cTool Palette,\u201d currently found at the bottom right of the IDE.<a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-8.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1479 alignright\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-8-174x300.jpg\" alt=\"\" width=\"174\" height=\"300\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-8-174x300.jpg 174w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-8.jpg 416w\" sizes=\"auto, (max-width: 174px) 100vw, 174px\" \/><\/a><\/p>\n<p>What we want is just a button\u2026so how do we find it from among all these things?<\/p>\n<p>Happily, that\u2019s going to be easy.\u00a0 There\u2019s a \u2018search\u2019 box at the top of the Palette, just type \u201cbutton\u201d into that and see what pops up in the list.<\/p>\n<p><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-9.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft  wp-image-1480\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-9-294x300.jpg\" alt=\"\" width=\"233\" height=\"238\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-9-294x300.jpg 294w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-9.jpg 374w\" sizes=\"auto, (max-width: 233px) 100vw, 233px\" \/><\/a><\/p>\n<p>TButton is what we want.\u00a0 Either press \u201center\u201d or double tap that with a mouse, and Delphi will drop a TButton right in the center of your app window.<\/p>\n<p>It deserves note that the \u201cT\u201d at the beginning of pretty much every component Delphi has ever seen stands for \u201cType\u201d.\u00a0 It represents a <em>class<\/em> of object \u2013 I\u2019ll give you the broad rundown on \u201cobject\u201d and \u201cobject orientation\u201d some other time \u2013 and the class is what defines the object.\u00a0 Think of a \u201cclass\u201d as the same sort of thing as a \u201cblueprint\u201d or \u201crecipe\u201d or \u201cdesign\u201d.\u00a0 It isn\u2019t the object itself, but instructions of how to make that object.\u00a0 Java totally fucked up in naming both their recipes and their existing elements classes, and that has caused who knows how much confusion for beginners over the years.\u00a0 But that\u2019s Java, and it hasn\u2019t ever made a whole lot of sense outside of \u201chow can we get Windows programmers to build stuff to run on Sun boxes?\u201d\u00a0 Another day for that, my prejudice is showing.<\/p>\n<p>So \u201cTButton\u201d is the class which is used to create buttons.\u00a0 Delphi dropped one on our form.\u00a0 What now?<\/p>\n<p>Now, we configure the button to look and feel the way we want.\u00a0 To do this, we can drag it around the window, we can also grab its sides and corners to resize it.\u00a0 Go ahead and do some of that.\u00a0 I\u2019ll wait.<\/p>\n<p>All done?\u00a0 Okay, when we want to change some of the more nitty-gritty bits about the stuff in our visual designers, we need the Object Inspector.\u00a0 By default this is located in the lower-left corner of the IDE.\u00a0 It shows you the <em>properties<\/em> and the <em>events<\/em> of the currently-selected item on the form.<\/p>\n<p>(By the way, \u201cForm\u201d in Delphi terminology represents a \u201cWindow\u201d of an app \u2013 so when you\u2019re working on a \u201cform\u201d you\u2019re working on what amounts to a window.\u00a0 There\u2019s some extra nuance to this, but for now when you\u2019re starting it\u2019s best to think of it that way.)<\/p>\n<p>Select the button, and look at the Object Inspector.\u00a0 A whole bunch of <em>properties <\/em>of the button are listed there.\u00a0 \u201cProperties\u201d of a thing in the Delphi world are the qualities of that thing, the settings that make it look and feel and behave the way it does.\u00a0 In the real world, things have properties too \u2013 your shirt for example, has properties \u201cmaterial,\u201d \u201ccolor,\u201d \u201csleeve length.\u201d \u00a0These properties for my shirt are \u201ccotton,\u201d \u201cblack,\u201d and \u201cshort\u201d.\u00a0 The descriptor of the attribute of a property is called its <em>value.\u00a0 <\/em>Think about the properties of the things around you.\u00a0 How would you describe them to someone?<\/p>\n<p>Back to the button.\u00a0 Its most commonly used property is \u201cCaption\u201d which is the text that appears on the surface of the button shown to the user.\u00a0 By default, the caption of the button is the same as its name.\u00a0 We\u2019re going to change these <em>values<\/em> now.<\/p>\n<p>Change the property Caption to \u201cSay &amp;Hello\u201d.\u00a0 Notice that as you do, the form shows your change in real-time.\u00a0 Also take note that the \u201c&amp;\u201d didn\u2019t show up \u2013 instead, the next character, the \u201cH\u201d, got underlined.\u00a0 This indicates that the H will become a \u2018hotkey\u2019 when your app runs, and in addition to pressing it with a mouse click, the button will also respond to the key combination Alt+H.<a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-10.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-1481\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-10-300x157.jpg\" alt=\"\" width=\"300\" height=\"157\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-10-300x157.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-10-768x401.jpg 768w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-10.jpg 825w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Find the property \u201cName\u201d in the Object Inspector.\u00a0 By default components added to a Delphi app will be named as their class plus a number, iterating the numbers based on how many others of that class there are.\u00a0 So we might see \u201cMenu3\u201d, \u201cButton12\u201d, and so on.\u00a0 When you\u2019re writing code, these default names are really hard to cope with, so get in the habit of naming things sensibly \u2013 try to keep in mind what they do and what they are, because your code can\u2019t \u201csee\u201d when it is running.<\/p>\n<p>For now, rename this button to \u201cbtnHello\u201d \u2013 btn being an abbreviation of \u201cbutton\u201d and Hello telling us what this thing is supposed to do.<\/p>\n<p>Do you see, in the top of the Object Inspector, there are actually two tabs there?\u00a0 Properties and Events?\u00a0 \u201cEvents\u201d are things that happen to your objects, like mouse clicks, keyboard presses, and so on.\u00a0 Take a scroll through the available events of a button just to get a feel for what they might be.<\/p>\n<p>Each component will have a default event, and if you double-click on the component in the form you\u2019ll automatically create an event of that type, which will be assigned in the Object Inspector to that event.\u00a0 It basically opens up a little \u201chole\u201d for your code to appear in, and when that event happens your code will be executed.<\/p>\n<p><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-11.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-1482\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-11-300x27.jpg\" alt=\"\" width=\"300\" height=\"27\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-11-300x27.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-11.jpg 356w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Double click either on the button itself, or in its \u201cOnClick\u201d event in the Object Inspector.\u00a0 Both actions will result in the same outcome, you\u2019ll end up in the code editor, your cursor itching to write a bit of code for a routine entitled \u201cbtnHelloClick\u201d.<\/p>\n<p><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-12.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-1483\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-12-300x69.jpg\" alt=\"\" width=\"300\" height=\"69\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-12-300x69.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-12.jpg 561w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>In that line, enter the following code:<\/p>\n<p>Showmessage(&#8216;Hello World&#8217;);<\/p>\n<p>Capitalization doesn\u2019t make any difference in the Delphi world, I just use it to make things look a little more sensible.\u00a0 \u201cShowMessage\u201d is a little routine from the VCL \u201cdialogs\u201d library that will take a single string value (strings are characters) and pop a dialog up with that string in it.\u00a0 Our app is already referencing the dialogs part of the VCL, so we don\u2019t have to add anything to this.\u00a0 Our app is ready to run!<\/p>\n<p>Up in the menu bar, there are two buttons with green right-pointing arrows that can be used to run the app \u2013 \u201crun\u201d and \u201crun without debugging\u201d.\u00a0 Either one will work, but as a developer you\u2019re going to want to use \u201crun\u201d most often, because debugging is what developers spend a very great deal of time doing, and your users won\u2019t like it if you never debug your programs.\u00a0 Fortunately, we won\u2019t need any debugging in this app, because it\u2019s very simple and you will get it right the first time.<a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-15.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1486 alignright\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-15.jpg\" alt=\"\" width=\"170\" height=\"110\" \/><\/a><\/p>\n<p>Press \u201crun\u201d or hit the F9 key (same thing).\u00a0 Delphi will compile your app \u2013 you\u2019ll see a dialog indicating its progress \u2013 and will run it.\u00a0 You will end up with this:<\/p>\n<p><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/graphic-13.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-1484\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/graphic-13-300x157.jpg\" alt=\"\" width=\"300\" height=\"157\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/graphic-13-300x157.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/graphic-13.jpg 635w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>That\u2019s your app!\u00a0 You just wrote, compiled, and ran your first Windows application!\u00a0 Congratulations!<\/p>\n<p>Go ahead and press the button, see what happens.\u00a0 I\u2019ll be here.<\/p>\n<p>Up pops a centered little dialog saying \u201cHello World\u201d, right?\u00a0 Pretty cool.\u00a0 Note while you are pressing this, if you used \u201crun\u201d rather than \u201crun without debugging\u201d that at the bottom of the Delphi IDE there is a pane called the Event Log that registered things like \u201cthread exit,\u201d \u201cthread start,\u201d etc. \u2013 these are part of the integrated debugger, which we won\u2019t talk about in this article, but is a really super-cool and very useful tool for when you\u2019re writing more complex programs.<\/p>\n<p><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-14.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-1485\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-14-300x87.jpg\" alt=\"\" width=\"300\" height=\"87\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-14-300x87.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-14.jpg 720w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Go ahead and close down your app \u2013 you can either press the \u201cX\u201d button on the top-right corner or enter the Alt+F4 key combination, both will close the app and return you to the IDE.<\/p>\n<p>Last thing for this article, let\u2019s save this project.\u00a0 It\u2019s not a big deal to lose this, because it\u2019s so simple, but saving it will let you know what files we\u2019re dealing with.<\/p>\n<p>There\u2019s a couple of save buttons on the top of the IDE, one disk for \u201csave\u201d and two disks for \u201csave all\u201d \u2013 those are disk icons, by the way.\u00a0 For the younger readers, those look like what we used to use to transfer data and programs around on, called \u201cfloppy disks.\u201d\u00a0 Ask your parents what they were.<a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-16.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1487 alignright\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-16.jpg\" alt=\"\" width=\"117\" height=\"96\" \/><\/a><\/p>\n<p>Either choose the two-disk \u201csave all\u201d, or go to the menus and choose File &gt; Save All.<\/p>\n<p>Your first prompt will be to save \u201cUnit1\u201d \u2013 we didn\u2019t rename this unit, because it\u2019s the only one in your project.\u00a0 Later, when there are more units in more complex projects, you\u2019ll want to rename units as soon as you create them, for the same reason you rename components when you drop them on a form.\u00a0 If you have a directory where you want to keep your code projects, navigate there and save Unit1 in the directory where you want to keep your Hello World project.\u00a0 Note that if you don\u2019t keep your projects separate, you\u2019re likely to overwrite files and lose your work, so definitely use different directories for each project.\u00a0 Get in that habit now.<a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-17.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1488 alignright\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-17-300x172.jpg\" alt=\"\" width=\"300\" height=\"172\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-17-300x172.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-17-768x442.jpg 768w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-17-1024x589.jpg 1024w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-17.jpg 1028w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>After being prompted for Unit1, you\u2019ll be prompted to save \u201cProject1\u201d as well.\u00a0 Project1 is the name of the program you\u2019ve just written, and Delphi will name its executable the same as your project file name.\u00a0 So if you want to call this something else, now\u2019s a good time to change its name.\u00a0 \u201cHelloWorld\u201d would be a good, if not very original, title J.\u00a0 (Delphi doesn\u2019t like spaces in project names, by the way, that\u2019s why there isn\u2019t one in my suggestion.)<\/p>\n<p><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-18.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-1489\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-18-300x173.jpg\" alt=\"\" width=\"300\" height=\"173\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-18-300x173.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-18-768x442.jpg 768w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-18-1024x589.jpg 1024w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-18.jpg 1029w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>We\u2019ll talk about what all those files are another time.\u00a0 What\u2019s important is that now when you compile your app (go ahead and do so now that you\u2019ve saved the project \u2013 Ctrl+F9 will compile it, or you can go through the menus and choose Project &gt; Compile HelloWorld), the executable will be found in this directory, in a &#8220;Win64\u201d subdirectory.<\/p>\n<div id=\"attachment_1490\" style=\"width: 310px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-19.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1490\" class=\"wp-image-1490 size-medium\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-19-300x73.jpg\" alt=\"\" width=\"300\" height=\"73\" srcset=\"https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-19-300x73.jpg 300w, https:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-19.jpg 732w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1490\" class=\"wp-caption-text\">We&#8217;ll deal with these&#8230;later<\/p><\/div>\n<p>You can take that executable and run it on any 64-bit Windows computer you want now, it\u2019s all yours and you get to do with it whatever you want.<\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_1491\" style=\"width: 264px\" class=\"wp-caption alignright\"><a href=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-20.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1491\" class=\"wp-image-1491 size-full\" src=\"http:\/\/borkedcode.com\/wp\/wp-content\/uploads\/2017\/06\/Graphic-20.jpg\" alt=\"\" width=\"254\" height=\"82\" \/><\/a><p id=\"caption-attachment-1491\" class=\"wp-caption-text\">That&#8217;s the one that matters.<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>So you\u2019re done \u2013 you\u2019ve built your first app in Delphi and you\u2019re ready to tackle the world!\u00a0 Congratulations again.<\/p>\n<p>I think the next one of these I do, we\u2019ll do a little bit with some data, and tap into a Microsoft SQL Server.\u00a0 But for now, I\u2019m going to go have a beer and build a model or something.\u00a0 I\u2019ll raise a glass for you, and hopefully I\u2019ll see you next time!<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey hey, everyone! Today is a day off for a public holiday \u2013 couldn\u2019t tell you which one off the top of my head \u2013 in Germany.\u00a0 They do a few of these in May and June, and this time &hellip; <a href=\"https:\/\/borkedcode.com\/wp\/?p=1470\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":1428,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[112,30,44,111,43],"tags":[113,117,114,116,106,115],"class_list":["post-1470","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","category-it","category-pc-stuff","category-programming","category-software","tag-dephi","tag-hello-world","tag-prgramming","tag-primer","tag-rad-studio","tag-starter"],"_links":{"self":[{"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1470"}],"version-history":[{"count":2,"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1470\/revisions"}],"predecessor-version":[{"id":1492,"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1470\/revisions\/1492"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=\/wp\/v2\/media\/1428"}],"wp:attachment":[{"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/borkedcode.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}