<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>vi-kan.net &#187; Delphi</title>
	<atom:link href="http://blog.vi-kan.net/category/delphi/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.vi-kan.net</link>
	<description>{ TODO -oVegar : insert clever text here}</description>
	<lastBuildDate>Mon, 28 Nov 2011 17:05:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Project Euler, Problem 6</title>
		<link>http://blog.vi-kan.net/2009/project-euler-problem-6/</link>
		<comments>http://blog.vi-kan.net/2009/project-euler-problem-6/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 20:40:10 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Euler]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/?p=97</guid>
		<description><![CDATA[Inspired by my brother over at geekality.net, I thought I should do an attempt on the various problems presented at projecteuler.net/.  Since he already solved the first five, I jumped right in at problem 6: The sum of the squares of the first ten natural numbers is, 12 + 22 + &#8230; + 102 = [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by my brother over at <a href="http://www.geekality.net/" target="_blank">geekality.net</a>, I thought I should do an attempt on the various problems presented at <a title="http://projecteuler.net/" href="http://projecteuler.net/">projecteuler.net/</a>.  Since he already solved the first five, I jumped right in at <a href="http://projecteuler.net/index.php?section=problems&amp;id=6" target="_blank">problem 6</a>:</p>
<blockquote>
<p align="left">The sum of the squares of the first ten natural numbers is,</p>
<p align="center">1<sup>2</sup> + 2<sup>2</sup> + &#8230; + 10<sup>2</sup> = 385</p>
<p align="left">The square of the sum of the first ten natural numbers is,</p>
<p align="center">(1 + 2 + &#8230; + 10)<sup>2</sup> = 552 = 3025</p>
<p align="left">Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is</p>
<p align="center">3025  385 = 2640.</p>
<p>Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.</p></blockquote>
<p><span id="more-97"></span></p>
<p>This problem has two distinct parts. First, there is the sum of a sequence of the squared natural numbers, then there is the sum of a sequence of natural numbers, squared.</p>
<h2>Sum of a series of squared natural numbers</h2>
<p>The problem tells to summarize the square of the first hundred natural numbers. That gives us the following sequence:</p>
<p align="center">1<sup>2</sup> + 2<sup>2</sup> + &#8230; 99<sup>2</sup> + 100<sup>2</sup></p>
<p align="left">The simplest solution would be a brute force loop like this one:</p>
<pre class="brush: delphi; title: ;">function sumSquaredNumbers( ): longword;
var
  i: integer;
begin
  result := 0;
  for i := 1 to 100 do
    result := result + (power(i, 2));
end;</pre>
<p>That wouldn’t be much fun, though. There has to be a more general, optimized algorithm for this kind of work. First of all, we should make the function workable for any series length. That should be easy – just switch the hardcoded 100 with an given parameter:</p>
<pre class="brush: delphi; title: ;">function sumSquaredNumbers(serieslength: integer): longword;
var   i: integer;
begin
  for i := 1 to seriesLength do
    result := …
end;</pre>
<p>But the code is still the same, though. Nothing was optimized in any way. We still have the loop, making our function <a href="http://en.wikipedia.org/wiki/Linear_time" target="_blank">linear</a>.</p>
<p>Google to the rescue!</p>
<p><a href="http://www.math.com">math.com</a> have a nice section on Series Expansions, which includes a table of <a href="http://www.math.com/tables/expansion/power.htm" target="_blank">power summations</a>. This table states that</p>
<blockquote>
<table border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td colspan="4" valign="top">n</td>
</tr>
<tr>
<td valign="vcenter"><span>∑</span></td>
<td valign="top">k<sup>2</sup></td>
<td valign="vcenter">= 1 + 4 + 9 + &#8230; + n<sup>2</sup></td>
<td valign="vcenter">= (1/3)n<sup>3</sup> + (1/2)n<sup>2</sup> + (1/6)n</td>
</tr>
<tr>
<td colspan="4" valign="top">k=1</td>
</tr>
</tbody>
</table>
</blockquote>
<p>Why this should be true, I honestly can’t tell, but a fast comparison to our brute force solution shows that it gives us the right numbers. That’s good enough for now:</p>
<pre class="brush: delphi; title: ;">function sumSquaredNumbers(seriesLength: integer): longword;
begin
  result := trunc(
                ((1/3) * power(seriesLength, 3))
              + ((1/2) * power(seriesLength, 2))
              + ((1/6) * seriesLength)
              );
end;</pre>
<p>I think this is a nice solution, and a <a href="http://en.wikipedia.org/wiki/Constant_time">constant one</a> as well. It doesn’t matter if the series is of length one, hundred or thousand – the computation should take the same amount of time.</p>
<h2>Sum of a series of natural numbers, squared</h2>
<p>This part should be a lot easier. We could start with a brute force solution to this part too, but I think we could come up with something smarter right away.</p>
<p>I already know of a simple optimization. If you add the first and last number in the series, you will get the same as if you add the second and next to last number:</p>
<blockquote>
<table border="0" cellspacing="0" cellpadding="2" width="145" align="center">
<tbody>
<tr>
<td width="13" valign="top"></td>
<td width="20" valign="top">1</td>
<td width="20" valign="top">2</td>
<td width="20" valign="top">3</td>
<td width="20" valign="top">4</td>
<td width="20" valign="top">5</td>
<td width="6" valign="top">6</td>
<td width="6" valign="top">7</td>
<td width="6" valign="top">8</td>
<td width="6" valign="top">9</td>
<td width="6" valign="top">10</td>
</tr>
<tr>
<td width="13" valign="top">+</td>
<td width="20" valign="top">10</td>
<td width="20" valign="top">9</td>
<td width="20" valign="top">8</td>
<td width="20" valign="top">7</td>
<td width="20" valign="top">6</td>
<td width="6" valign="top">5</td>
<td width="6" valign="top">4</td>
<td width="6" valign="top">3</td>
<td width="6" valign="top">2</td>
<td width="6" valign="top">1</td>
</tr>
<tr>
<td width="13" valign="top">=</td>
<td width="20" valign="top">11</td>
<td width="20" valign="top">11</td>
<td width="20" valign="top">11</td>
<td width="20" valign="top">11</td>
<td width="20" valign="top">11</td>
<td width="6" valign="top">11</td>
<td width="6" valign="top">11</td>
<td width="6" valign="top">11</td>
<td width="6" valign="top">11</td>
<td width="6" valign="top">11</td>
</tr>
</tbody>
</table>
</blockquote>
<p>As you can see, every pair of numbers makes the same sum when added together. So for any given series, you can take the first and the last number and add them together, then you can multiply the sum by the length of the series, and finally divide by two.</p>
<blockquote>
<table border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td colspan="4" valign="top">n</td>
</tr>
<tr>
<td valign="vcenter"><span>∑</span></td>
<td valign="top">k</td>
<td valign="vcenter">= 1 + 2 + 3 + &#8230; + n</td>
<td valign="vcenter">= (1 + n) * n / 2</td>
</tr>
<tr>
<td colspan="4" valign="top">k=1</td>
</tr>
</tbody>
</table>
</blockquote>
<p>I know there are other solutions to this, but this one will do.</p>
<pre class="brush: delphi; title: ;">function sumSquared(seriesLength: longword): longword;
begin
  result := trunc(power(((1 + seriesLength) * seriesLength / 2), 2));
end;</pre>
<h2>The solution</h2>
<p>Now that we have solved each of the two sub parts of the problem, I guess we’re ready to solve the main thing.</p>
<blockquote><p>Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.</p></blockquote>
<p>Since we know the sum of the squares, and we now the square of the sum, it’s just a matter of substract the one from the other:</p>
<pre class="brush: delphi; title: ;">function diff(serieslength: longword): longword;
begin
  result := sumSquared(serieslength) - sumSquaredNumbers(serieslength);
end;</pre>
<p>I have uploaded my complete solution to <a href="http://svn.vi-kan.net/euler">http://svn.vi-kan.net/euler</a>. The code also contains a simple stopwatch to time the code. This code is so simple, though, that it’s hard to get any measures.</p>
<p>And that’s it. Let’s see if we can solve the next one too.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/project-euler-problem-6/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Running FitNesse tests from the command line</title>
		<link>http://blog.vi-kan.net/2009/running-fitnesse-tests-from-the-command-line/</link>
		<comments>http://blog.vi-kan.net/2009/running-fitnesse-tests-from-the-command-line/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 22:52:00 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Fit4Delphi]]></category>
		<category><![CDATA[FitNesse]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/2009/running-fitnesse-tests-from-the-command-line/</guid>
		<description><![CDATA[Using FitNesse to write and run test is nice, but sometimes you want to run the tests as part of an automatic build cycle. FitNesse has this possibility, and fit4delphi comes with a testrunner that makes it possible with delphi code as well. In the fit4delphi package, inside the testrunner folder, you will find a [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-right-width: 0px; margin: 0px 0px 0px 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://blog.vi-kan.net/wp-content/uploads/2009/09/image.png" border="0" alt="image" width="240" height="136" align="right" /> Using FitNesse to write and run test is nice, but sometimes you want to run the tests as part of an automatic build cycle. FitNesse has this possibility, and fit4delphi comes with a testrunner that makes it possible with delphi code as well.</p>
<p><span id="more-96"></span></p>
<p>In the fit4delphi package, inside the testrunner folder, you will find a project named DelphiTestRunner.dproj. You can use this project to automatically run a test, or a suite of tests, and store the result as a file. To do his, you have to tell the testrunner where the FitNesse server is running, and which file and in what format the result should be store in. This is done with command line parameters in the given form:</p>
<blockquote><p>DelphiTestRunner.exe [options] host port page</p></blockquote>
<p>Host and port must be the same as specified when starting FitNesse. The page parameter is the url for the wiki page you want to test. All subpages of this page will also be tested.</p>
<p>There are multiple options you can specify.</p>
<ul>
<li>-debug<br />
This option will print FitNesse protocol actions to the console.</li>
<li>-v<br />
This option should give a verbose output about test progress to the console, but personally, I can’t make it work…</li>
<li>-results file<br />
The result of the testrun is saved to a textfile with the given name.</li>
<li>-html file<br />
The result of the testrun is saved to a html file with the given name.</li>
<li>-xml file<br />
The result of the testrun is saved to a xml file with the given name. The xml format is given <a title="FitNesse.UserGuide.RestfulTests" href="http://fitnesse.org/FitNesse.UserGuide.RestfulTests" target="_blank">in the userguide</a>.</li>
<li>-nopath<br />
This option will make FitNesse ignore !path options specified in the wiki pages.</li>
<li>-suiteFilter filter<br />
Specifying a filter will only run pages with tags matching the filter. You can read more about this <a title="FitNesse.UserGuide.TestSuites.TagsAndFilters" href="http://fitnesse.org/FitNesse.UserGuide.TestSuites.TagsAndFilters" target="_blank">in the userguide</a>.</li>
</ul>
<p>An example of a command line could be some thing like this:</p>
<blockquote><p>DelphiTestRunner.exe –html results.html localhost 80 MyTestSuite</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/running-fitnesse-tests-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FitNesse + Delphi –&gt; Fit4Delphi</title>
		<link>http://blog.vi-kan.net/2009/fitnesse-delphi-fit4delphi/</link>
		<comments>http://blog.vi-kan.net/2009/fitnesse-delphi-fit4delphi/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 13:59:28 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Fit4Delphi]]></category>
		<category><![CDATA[FitNesse]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/?p=76</guid>
		<description><![CDATA[I have been thinking about FitNesse for a couple of weeks now. It seems to be near to perfect for testing the type of code that I&#8217;m currently writing. A lot of calculations with a lot of rules, odd cases and exceptions. So I finally started to check it out, to see if it is [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-85" style="margin: 0px 0px 0px 10px; display: inline; border-width: 0px;" title="FitNesseLogo" src="http://blog.vi-kan.net/wp-content/uploads/2009/08/FitNesseLogo.gif" alt="FitNesseLogo" width="90" height="90" />I have been thinking about <a href="http://fitnesse.org/">FitNesse</a> for a couple of weeks now. It seems to be near to perfect for testing the type of code that I&#8217;m currently writing. A lot of calculations with a lot of rules, odd cases and exceptions. So I finally started to check it out, to see if it is possible to use FitNesse to test code written in delphi.<span id="more-76"></span> After some googling, I found a lot of references to the fact that it is possible, but not much on how. There ain’t much references to people actually using it either.  I found two projects, though, <a href="http://code.google.com/p/fit4delphi/">Fit4Delphi</a> and <a href="http://fitnesse.org/FrontPage.FitServers.DelphiFit">DelphiFIT</a>. It looks like DelphiFIT has been merged with the Fit4Delphi project, so there is only one solution left for FitNesse with Delphi. If it is any good, one is all you need, though.  At first, it’s a bit unclear what components are playing together in FitNesse. There are two main parts of the system, with two different roles. The first part is the one doing the actual testing bit. The second is a development environment in the form of a wiki, made for writing, invoking and maintaining tests.</p>
<h2>Get it running</h2>
<p>So let see if we can make this work. Fit4Delphi comes with a older version of FitNesse. You can choose to use this version, or you can get a newer version from <a href="http://fitnesse.org">fitnesse.org</a>. I like new shiny things, so I downloaded a brand new fitnesse.jar. Assuming that java already exists on your computer, fitnesse.jar is all you need to get going. Put it in a folder somewhere, e.g. c:\fitnesse\, and run</p>
<pre class="brush: plain; gutter: false; title: ;">c:\fitnesse\java -jar fitnesse.jar</pre>
<p>Fitnesse will now unpack it self before it starts. If you later want to upgrade to a newer version of FitNesse, you can download a new jar-file and new resources will be extracted next time you start FitNesse.  When FitNesse starts, it will tell you what version it is and what port it is running on. It will also tell you a couple of other things, but the port number is what we need right now. The port number defaults to 80, the standard http port. So fire up you webbrowser, and navigate to <a href="http://localhost:80">http://localhost:80</a>, and you will be presented with the default front page for FitNesse.  To the left, you have a tree-structure showing what pages exists in the wiki, and to the right you have the content for the current page. In the FitNesse branch of the tree, you can find the user guide for FitNesse amoung all the acceptance tests for FitNesse itself.  On the FrontPage, click the edit-button to the left. At the bottom of the page, write the name of your new testsuite, ‘DelphiTests’, or what ever. It need to be a <a href="http://fitnesse.org/FitNesse.UserGuide.WikiWord">‘WikiWord’</a>, though. When you save the document, you will see your inserted text together with a ‘[?]’. This means that the wiki sees your wikiword as a title for a page, but can’t find the page itself. When clicking on the questionmark, the wiki will create the page, and let you edit it.  So let’s start with a simple table. Fill out the new page with something like the following:</p>
<pre class="brush: plain; gutter: false; title: ;">|test table|
|in value|out value?|
|1|2|</pre>
<p>After saving, you will see your table nicely formatted. Is there a Test button to the left? If not, click the Properties-button, and choose Test as page type. Now, click the Test-button…  Nothing happends, right?  FitNesse finds the table and want it to be tested, but can’t find anyone willing to work. It needs to know who to call for the job. It is done by defining the <a href="http://fitnesse.org/FitNesse.UserGuide.CustomizingTestExecution">‘COMMAND_PATERN’</a> variable. When testing delphi code, we will need  DelphiFitServer.exe to do the work for us, so we give FitNesse the path to this executable. I have copied both DelphiFitServer.exe and fit.bpl to a ‘bin’-folder in my FitNesse-folder. You will find the source in \fit4delphi\fitserver\ and \fit4delphi\fit\.</p>
<pre class="brush: plain; gutter: false; title: ;">!define COMMAND_PATTERN {bin\DelphiFitServer.exe -v %p}</pre>
<p>The –v parameters tell DelphiFitServer to print out messages, and the %p parameter represents the <a href="http://fitnesse.org/FitNesse.UserGuide.MarkupPath">path</a> where DelphiFitServer should look for fixtures. FitNesse builds this path from classpath-settings in the wiki. Let’s include one in our page:</p>
<pre class="brush: plain; gutter: false; title: ;">!path bin\*.bpl</pre>
<p>Let’s hit that Test button again and see if there is any progress.  This time we get a lot of yellow on our page. While red tells us that a test did not pass, yellow tells us that something went wrong when trying execute the test. As you can see, DelphiFitServer couldn’t find fixture for our table. If you click the ‘Output Captured’ sign in the right corner, you will get some details on the execution. You can see what exe-file was used, and what bpl-files was loaded. We now need to add some testcode on our own.</p>
<h2>Writing our first fixture</h2>
<p>From the yellow text, we found that we need a class named ‘TestTable’. Acctually, FitNesse is quite flexible when it comes to naming. You can read more about it <a title="Graceful Naming" href="http://fitnesse.org/FitNesse.UserGuide.GracefulName">the documentation</a>, but I will disclose that a class named ‘TTestTable’ should be accepted.  So lets create a new delphi package. Add a reference to fit.bpl and the source path for fit4delphi\fit\source, fit4delphi\fit\source\exception and fit4delphi\RegExpr. Create a new unit, and define a new class deriving from TColumnFixture. You will need the file ColumnFixture in your uses section for this to compile. You will also need to enable detailed rtti for your class, and register it with a call to RegisterClass:</p>
<pre class="brush: delphi; title: ;">unit fitTestTable;

interface

uses
  ColumnFixture;

type
  {$M+}
  {$METHODINFO ON}
  TTestTable = class(TColumnFixture)
  published
  end;

implementation

uses
  Classes;

{ TTestTable }

initialization
  RegisterClass(TTestTable)

end.</pre>
<p>Build the new package, and move it to the bin folder of your FitNesse installation. Run the test again, and you will find that there is now three exceptions instead of one. Progress!  This time, it chokes on the column titles. Could not find field: in value. Well, lets add it, then. A published property named InValue of type double should do.  Compile… Copy… Test…  One down, two to go.  Of course it choked on the next column also. This time we need to add a function named OutValue returning a double.  Let’s fake the implementation for now, and just return 0.</p>
<pre class="brush: delphi; title: ;">   TTestTable = class(TColumnFixture)
  private
    FInnValue: double;
  published
    property InnValue: double read FInnValue write FInnValue;
    function OutValue: double;
  end;</pre>
<p>Now, that got rid of both the remaining exceptions, but leaves us with some ugly red spots. This is actually good though: Our test runs with out problems, but fails. I will leave it up to you to make the test pass. It shouldn’t be to hard, and the reward of green colour should be enough to make you wanna write some real tests.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/fitnesse-delphi-fit4delphi/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DUnit: Loading tests from dll’s</title>
		<link>http://blog.vi-kan.net/2009/dunit-loading-tests-from-dlls/</link>
		<comments>http://blog.vi-kan.net/2009/dunit-loading-tests-from-dlls/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 14:21:33 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[DUnit]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/?p=71</guid>
		<description><![CDATA[I wanted to split all my unittests for a project into separate packages to keep tings nice and clean. DUnit comes with a unit called TestModules.pas which helps you do that. The unit contains three public methods: function LoadModuleTests(LibName: string) :ITest; procedure RegisterModuleTests(LibName: string); procedure UnloadTestModules; The LoadModuleTests( )-function, dynamically loads the given library (dll [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to split all my unittests for a project into separate packages to keep tings nice and clean. <a title="DUnit: An Xtreme testframework for Delphi programs" href="http://dunit.sourceforge.net/">DUnit</a> comes with a unit called <a title="View testmodules.pas from sourceforge.net" href="http://dunit.svn.sourceforge.net/viewvc/dunit/trunk/src/TestModules.pas?revision=15&amp;view=markup">TestModules.pas</a> which helps you do that.<span id="more-71"></span></p>
<p>The unit contains three public methods:</p>
<pre class="brush: delphi; title: ;">function LoadModuleTests(LibName: string) :ITest;
procedure RegisterModuleTests(LibName: string);
procedure UnloadTestModules;</pre>
<p>The LoadModuleTests( )-function, dynamically loads the given library (dll or dtl files), and returns an interface to the tests defined within. RegisterModuleTests( ) does the same, but also calls RegisterTest( ) with the interface from the library.</p>
<p>There is one requirement that the library has to satisfy. It must export a function named ‘Test’ that returns a ITest-interface. Following is a basic project file showing how this can be done:</p>
<pre class="brush: delphi; title: ;">library OurUnitTests;

uses
  TestFramework;

function Test: ITest;
begin
  result := RegisteredTests;
end;

exports
  Test name 'Test';

end;</pre>
<p>The Test( )-function simply returns the result from the RegisteredTests( ) method from the TestFramework-unit. RegisteredTests( ) returns a ITestSuite containing all the test classes registered.</p>
<p>Here&#8217;s a samle project file that loads all dll-files from the executables folder, and runs all test through the GUITestRunner:</p>
<pre class="brush: delphi; title: ;">program RunTests;
uses
  Forms,
  TestFramework,
  GUITestRunner,
  TestModules,
  SysUtils,
  Windows,
  JclFileUtils,
  classes,
  Dialogs
  ;

  {$R *.RES}

procedure LoadTests;
var
  filelist: TStringList;
  str: string;
begin
  filelist := TStringList.Create;
  try
    BuildFileList('*.dll', faAnyFile, filelist);

    for str in filelist do
    begin
      try
        RegisterModuleTests(str)
      except
        on E: Exception do
          ShowMessage(e.Message);
      end;
    end;
  finally
    filelist.free;
  end;
end;

begin
  Application.Initialize;

  LoadTests;
  GUITestRunner.RunRegisteredTests;
  UnloadTestModules;
end.</pre>
<p>The BuildFileList( ) method comes from JCL, and simply fills a TStringList with filenames from the given mask. As I said, this is a very basic project, but it shows how to use the TestModules-unit to dynamically load tests. This can easily be expanded to a more flexible solution. You could use command parameters to control what folder should be searched for libraries, or what testrunner should be used, GUI or XML or custom runner.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/dunit-loading-tests-from-dlls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TDD, Unittesting and Delphi</title>
		<link>http://blog.vi-kan.net/2009/tdd-unittesting-and-delphi/</link>
		<comments>http://blog.vi-kan.net/2009/tdd-unittesting-and-delphi/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 11:04:50 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[UnitTesting]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/?p=60</guid>
		<description><![CDATA[Lately, I’ve been trying to learn TDD. In this post, I will collect the resources that I find.]]></description>
			<content:encoded><![CDATA[<p>Lately, I’ve been trying to learn TDD. In this post, I will collect some resources that I find helpfull. </p>
<p> <span id="more-60"></span>
</p>
<h2>Test Frameworks</h2>
<h3 style="padding-left: 30px">DUnit</h3>
<p style="padding-left: 30px"><a title="http://dunit.sourceforge.net/" href="http://dunit.sourceforge.net/">http://dunit.sourceforge.net/</a></p>
<h3 style="padding-left: 30px">DUnitLite</h3>
<p style="padding-left: 30px"><a title="http://code.google.com/p/dunitlite/" href="http://code.google.com/p/dunitlite/">http://code.google.com/p/dunitlite/</a></p>
<h3 style="padding-left: 30px">DSpec</h3>
<p style="padding-left: 30px"><a title="http://sourceforge.net/projects/dspec/" href="http://sourceforge.net/projects/dspec/">http://sourceforge.net/projects/dspec/</a></p>
<h2>Mocking/Faking</h2>
<h3 style="padding-left: 30px">Pascal Mock</h3>
<p style="padding-left: 30px"><a title="http://sourceforge.net/projects/pascalmock/" href="http://sourceforge.net/projects/pascalmock/">http://sourceforge.net/projects/pascalmock/</a></p>
<h3 style="padding-left: 30px">Delphi Mock Wizard</h3>
<p style="padding-left: 30px"><a title="http://code.google.com/p/delphi-mock-wizard/" href="http://code.google.com/p/delphi-mock-wizard/">http://code.google.com/p/delphi-mock-wizard/</a></p>
<h3 style="padding-left: 30px">Simple Mock</h3>
<p style="padding-left: 30px"><a title="http://delphixtreme.com/wordpress/?p=14" href="http://delphixtreme.com/wordpress/?p=14">http://delphixtreme.com/wordpress/?p=14</a></p>
<h3 style="padding-left: 30px">Ultra Basic MockObjects</h3>
<p style="padding-left: 30px"><a title="http://sourceforge.net/projects/ubmock/" href="http://sourceforge.net/projects/ubmock/">http://sourceforge.net/projects/ubmock/</a></p>
<h2>Code coverage</h2>
<h3 style="padding-left: 30px">Discover for Delphi</h3>
<p style="padding-left: 30px"><a title="http://www.cyamon.com/discover1.htm" href="http://www.cyamon.com/discover1.htm">http://www.cyamon.com/discover1.htm</a></p>
<h3 style="padding-left: 30px">AQ Time</h3>
<p style="padding-left: 30px"><a title="http://www.automatedqa.com/products/aqtime/" href="http://www.automatedqa.com/products/aqtime/">http://www.automatedqa.com/products/aqtime/</a></p>
<h2>Supporting tools</h2>
<h3 style="padding-left: 30px">DUnit IDE integration</h3>
<p style="padding-left: 30px"><a title="http://delphixtreme.com/wordpress/?page_id=8" href="http://delphixtreme.com/wordpress/?page_id=8">http://delphixtreme.com/wordpress/?page_id=8</a></p>
<h2>Websites</h2>
<h3 style="padding-left: 30px">Delphi-Extreme</h3>
<p style="padding-left: 30px"><a title="http://www.delphixtreme.com/" href="http://www.delphixtreme.com/">http://www.delphixtreme.com/</a></p>
<p style="padding-left: 30px"><a title="http://www.delphixtreme.com/forums/" href="http://www.delphixtreme.com/forums/">http://www.delphixtreme.com/forums/</a></p>
<h2>FitNesse</h2>
<h3 style="padding-left: 30px">FitNesse</h3>
<p style="padding-left: 30px"><a title="http://fitnesse.org/" href="http://fitnesse.org/">http://fitnesse.org/</a></p>
<h3 style="padding-left: 30px">Fit4Delphi</h3>
<p style="padding-left: 30px"><a title="http://code.google.com/p/fit4delphi/" href="http://code.google.com/p/fit4delphi/">http://code.google.com/p/fit4delphi/</a></p>
<h3 style="padding-left: 30px">FitNesse.Tutorials</h3>
<p style="padding-left: 30px"><a title="http://schuchert.wikispaces.com/FitNesse.Tutorials" href="http://schuchert.wikispaces.com/FitNesse.Tutorials">http://schuchert.wikispaces.com/FitNesse.Tutorials</a></p>
<h2>Books</h2>
<p><span style="font-size: xx-small"></span></p>
<table border="0" cellspacing="0" cellpadding="2" width="609">
<tbody>
<tr>
<td valign="top"><a href="http://my.safaribooksonline.com/0321269349"><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.vi-kan.net/wp-content/uploads/2009/08/image.png" width="76" height="100" /></a></td>
<td valign="top" width="506"><strong><a href="http://my.safaribooksonline.com/0321269349">Fit for Developing Software: Framework for Integrated Tests</a></strong>           <br /><span style="font-size: xx-small">by Rick Mugridge; Ward Cunningham </span>
<p><span style="font-size: xx-small">Publisher: Prentice Hall              <br />Pub Date: June 29, 2005               <br />Print ISBN-10: 0-321-26934-9               <br />Print ISBN-13: 978-0-321-26934-8 </span></p>
<p><span style="font-size: xx-small">Pages: 384</span></p>
</td>
</tr>
<tr>
<td valign="top" width="96"><a href="http://my.safaribooksonline.com/9781933988276"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" src="http://blog.vi-kan.net/wp-content/uploads/2009/08/image1.png" width="76" height="95" /></a></td>
<td valign="top" width="506"><strong><a href="http://my.safaribooksonline.com/9781933988276">The Art of Unit Testing: with Examples in .NET</a></strong>           <br /><span style="font-size: xx-small">by Roy Osherove </span>
<p><span style="font-size: xx-small">Publisher: Manning Publications              <br />Pub Date: June 28, 2009               <br />Print ISBN-10: 1-933988-27-4               <br />Print ISBN-13: 978-1-933988-27-6 </span></p>
<p><span style="font-size: xx-small">Pages: 320</span></p>
</td>
</tr>
<tr>
<td valign="top" width="96"><a href="http://my.safaribooksonline.com/0321146530"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" src="http://blog.vi-kan.net/wp-content/uploads/2009/08/image2.png" width="76" height="95" /></a></td>
<td valign="top" width="506"><a href="http://my.safaribooksonline.com/0321146530">Test Driven Development: By Example</a>           <br /><span style="font-size: xx-small">by Kent Beck </span>
<p><span style="font-size: xx-small">Publisher: Addison-Wesley Professional              <br />Pub Date: November 08, 2002               <br />Print ISBN-10: 0-321-14653-0               <br />Print ISBN-13: 978-0-321-14653-3 </span></p>
<p><span style="font-size: xx-small">Pages: 240</span></p>
</td>
</tr>
<tr>
<td valign="top" width="96"><a href="http://my.safaribooksonline.com/9780131495050"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" src="http://blog.vi-kan.net/wp-content/uploads/2009/08/image3.png" width="76" height="102" /></a></td>
<td valign="top" width="506"><a href="http://my.safaribooksonline.com/9780131495050">xUnit Test Patterns: Refactoring Test Code</a>           <br /><span style="font-size: xx-small">by Gerard Meszaros </span>
<p><span style="font-size: xx-small">Publisher: Addison-Wesley Professional              <br />Pub Date: May 21, 2007               <br />Print ISBN-10: 0-13-149505-4               <br />Print ISBN-13: 978-0-13-149505-0 </span></p>
<p><span style="font-size: xx-small">Pages: 944</span></p>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/tdd-unittesting-and-delphi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>1st particle-challenge: Getting something unto the screen</title>
		<link>http://blog.vi-kan.net/2009/1st-particle-challenge-getting-something-unto-the-screen/</link>
		<comments>http://blog.vi-kan.net/2009/1st-particle-challenge-getting-something-unto-the-screen/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 13:15:25 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Particle]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/2009/1st-particle-challenge-getting-something-unto-the-screen/</guid>
		<description><![CDATA[A couple of days ago, I took a challenge to show that making a particle engine is not that hard. I also stated that the first part of the challenge would be to get something unto the screen, and that is as far as I have come. I have enough code to emit particles unto [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.vi-kan.net/wp-content/uploads/2009/07/something.png"><img style="margin: 0px 0px 0px 5px; display: inline; border: 0px;" title="No firework, but it's something" src="http://blog.vi-kan.net/wp-content/uploads/2009/07/something_thumb.png" border="0" alt="No firework, but it's something" width="238" height="208" align="right" /></a>A couple of days ago, I took a <a title="The &quot;Particle-engines-is-not-that-hard'-challenge" href="http://blog.vi-kan.net/2009/the-“particle-engines-is-not-that-hard’-challenge/">challenge</a> to show that making a particle engine is not that hard. I also stated that the first part of the challenge would be to get something unto the screen, and that is as far as I have come. I have enough code to emit particles unto the screen, beautifully rendered as small triangles in various colors.</p>
<p>Well – its no firework, but it’s a start…</p>
<p>For those who are interested in the code, it’s available for  <a title="The code for particle challenge" href="http://svn.vi-kan.net/particle/0.1" target="_blank">download here</a>. The lib-folder contains two libraries that I use. First of all, there is the <a href="http://www.delphigl.com" target="_blank">Free Pascal OpenGL Headers</a> used for rendering. Second, there is a folder called ‘SDL’, which is a older version of the <a href="http://sourceforge.net/projects/decal/" target="_blank">Delphi Container and Algorithm Library</a> (DeCAL).  I started using it for many, many years ago, back when it was a commercial product. It was called Standard Delphi Library, but was renamed to avoid confusion with ‘<a title="Simple DirectMedia Library" href="http://www.libssld.org" target="_blank">Simple DirectMedia Library</a>’. I guess it’s time to find something else, and when I start using Delphi 2009, I will for sure.</p>
<p>So, how did I put something unto the screen?<span id="more-55"></span></p>
<p>I started off with a simple TParticle class with information about position, velocity, color, time to live and age.</p>
<pre class="brush: delphi; title: ;"> TParticle = class(TObject)
  public
    constructor Create;

    procedure Update(DeltaFrame: int64);

    property Position: TVector3D read FPosition write FPosition;
    property Velocity: TVector3D read FVelocity write FVelocity;

    property Color: TColorFA read FColor write FColor;

    property TimeToLive: int64 read FTimeToLive write FTimeToLive;
    property Age: int64 read GetAge;
    property Dead: boolean read FDead write FDead;
  end;</pre>
<p>Then followed a TParticleManager to hold all the particles.</p>
<pre class="brush: delphi; title: ;"> TParticleManager = class(TObject)
  public
    constructor Create;
    destructor Destroy; override;

    procedure AddEmitter(Emitter: TParticleEmitter);

    procedure ProcessFrame;

    property Particles: DArray read FPArticles;
  end;</pre>
<p>For each ‘game loop’, the particle manager will loop through all particles, destroying those that have lived their age, and telling the others to update them self. When calling Update( ) on the particle, it pass in the tickcount since update. This is to ensure a relatively smooth and natural movement even if the fps is not stable.</p>
<pre class="brush: delphi; title: ;"> procedure TParticleManager.ProcessFrame;
  var
    CurrentFrame: int64;
    FrameDelta: int64;
  begin
    CurrentFrame := GetTickCount;
    FrameDelta := CurrentFrame - FLastFrame;

    RemoveDeadParticles;
    EmittNewParticles(FrameDelta);
    ProcessParticles(FrameDelta);

    FLastFrame := CurrentFrame;
  end;</pre>
<p>It will also contain a list of TParticleEmitters. The particle emitter will get it’s chance to emit new particles once every loop. It is the emitters responsibility to give the new particles a initial position and velocity.</p>
<pre class="brush: delphi; title: ;"> TParticleEmitter = class(TObject)
  public
    constructor Create;
    procedure EmittParticles(TimeSinceLastFrame: int64; Particles: DArray);

    property ParticlesPrTick: extended read FParticlesPrTick write FParticlesPrTick;
  end;</pre>
<p>The rendering is separated into it’s own class, TRendrer. This class will to all the OpenGL initialization-stuff. It is given a list of objects to render, where each item must implement the IRenderItem interface. In this way, the rendrer do not need to know anything about what it renders. It just setup a place for the rendering to happend, and asks the item to draw it self.</p>
<pre class="brush: delphi; title: ;"> TRendrer = class(TObject)
  public
    constructor Create(AHandle: THandle);
    destructor Destroy; override;

    procedure Render(ItemsToRender: DArray);

    procedure HandleResize(NewSize: TRect);
  end;</pre>
<p>To make the particle able to render it self, I have made a sub class, TVisualParticle, which implements IRenderItem. For now, it just draws a small triangle in the particles color.</p>
<pre class="brush: delphi; title: ;">procedure TVisualParticle.Render;
begin
  glPushMatrix();
  glTranslatef(Position.x, Position.y, Position.z);

  glBegin(GL_TRIANGLES);
    glColor4f(Color.Red, Color.Green, Color.Blue, Color.Alpha);
    glVertex3f(-0.1,-0.1, 0);
    glVertex3f( 0.1,-0.1, 0);
    glVertex3f( 0.0, 0.1, 0);
  glEnd;

  glPopMatrix;
end;</pre>
<p>From here, there are a couple of things that needs improvements. I need to explore OpenGL a bit more to get control over ‘the world’ that the particles lives in. Maybe a camera-model or something is needed. I don’t know. I also need to look into ways of rendering a little more interesting particles then triangles… And then there are physics &#8211; particles should be able to react to gravity and other forces as well. I’m not sure where I will start though. Time will show…</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/1st-particle-challenge-getting-something-unto-the-screen/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The “Particle-engines-ain&#8217;t-that-hard’-challenge</title>
		<link>http://blog.vi-kan.net/2009/the-%e2%80%9cparticle-engines-is-not-that-hard%e2%80%99-challenge/</link>
		<comments>http://blog.vi-kan.net/2009/the-%e2%80%9cparticle-engines-is-not-that-hard%e2%80%99-challenge/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 15:35:55 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Particle]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/?p=46</guid>
		<description><![CDATA[The other day, a colleague and I where looking at a cool application, Machine Flow. It’s a visual development environment and interpreter for the programming language Machine Flow. The language it self is defined by small lua-scripts, which you visually connect together. The running of the program is illustrated by small marbles carrying data around. [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 5px; display: inline; border-top: 0px; border-right: 0px" title="particle firework" border="0" alt="particle firework" align="right" src="http://blog.vi-kan.net/wp-content/uploads/2009/07/image.png" width="235" height="240" /> The other day, a colleague and I where looking at a cool application, <a href="http://www.nitrogen.za.org/projectinfo.asp?id=38">Machine Flow</a>. It’s a visual development environment and interpreter for the programming language Machine Flow. The language it self is defined by small lua-scripts, which you visually connect together. The running of the program is illustrated by small marbles carrying data around. It&#8217;s quite fun to play with, and the source is open, so there should be one or two things to look at there to.</p>
<p>What caught my colleagues interest, was a small firework-effect when the development environment was cleared. So we started discussing it, and soon I was determined to show that it’s really not that hard to make such effects. Now, I have never before done anything like this before. I lack experience with both graphics programming and the necessary math/physics. But it can’t be that hard, can it?</p>
<p>Well, we&#8217;ll just have to wait and see, then. The first challenge will be to get something unto the screen, and than I can start look at how to make it look nice. I will try to steer away from available libraries and tutorials, and rather come up with something completely on my own. The visual part will require&#160; some reading though&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/the-%e2%80%9cparticle-engines-is-not-that-hard%e2%80%99-challenge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ownerdrawn menus in Delphi</title>
		<link>http://blog.vi-kan.net/2009/ownerdrawn-menus-in-delphi/</link>
		<comments>http://blog.vi-kan.net/2009/ownerdrawn-menus-in-delphi/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 11:52:07 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Delphi]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/?p=30</guid>
		<description><![CDATA[Just when I was thinking that what this blog really needed was some content, an old article that I wrote for delphi.about.com was pulled out unto the frontpage again. It was written back when Office 2007 was still in beta, but the principles of owner drawn components should still be the same. You can take [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="Owner drawn popup menu" border="0" alt="Owner drawn popup menu" align="right" src="http://blog.vi-kan.net/wp-content/uploads/2009/06/image.png" width="244" height="203" /> Just when I was thinking that what this blog really needed was some content, an <a href="http://delphi.about.com/od/vclusing/a/2007ownerdraw.htm">old article</a> that I wrote for delphi.about.com was pulled out unto the frontpage again. It was written back when Office 2007 was still in beta, but the principles of owner drawn components should still be the same.</p>
<p>You can take a look at it on the delphi.about.com-page: <a href=" http://delphi.about.com/od/vclusing/a/2007ownerdraw.htm">How to Mimic Office 2007 Rich Menus using Owner Drawn TMenuItems</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/ownerdrawn-menus-in-delphi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
