Home > Amiga, Delphi, JavaScript, Object Pascal, Smart Mobile Studio > Meeting other Spartans in person, a great day in Oslo

Meeting other Spartans in person, a great day in Oslo

It’s not often I meet people who actually use Delphi on a daily basis these days, and out of those I meet – it’s very rare to meet people in person which masters object pascal completely. But today I had the good fortune of meeting up with Paul Thornton, which I have only talked to a couple of times before in connection with Oslo Delphi Club and on Delphi Developer (FB group).

Best lunch in town, the nighthawk diner

Best lunch in town, the nighthawk diner

As the name hints Paul is originally from the UK but now lives in Oslo with his lovely family. Paul is a highly skilled and successful entrepreneur, with a very exciting project in the pipeline, written (as expected) from the ground up in Delphi. Just the idea of having a full system, custom hardware included, not just a server or a simple client– but the whole shabam written in Delphi sounds like xmas and new-years eve to me, so I was intrigued to learn more about this. And Paul really gave me the grand tour with visits to his top-secret “lair” where he cooks up all manner of awesome solutions, which then plays out on custom designed hardware.

His project really struck a tone because when I was leaving my mind was already busy building a Raspberry PI based data caching module. Which is the closest thing I can get to “custom hardware” 🙂 I mean, programming in general is 90% theory; We spend days, weeks, months working primarily in the realm of metaphysics. Sculpting ideas, assessing cause and effect, building hierarchies and data relationships — and there are days when I think to myself “oh why didn’t I finish those 3 years studying electronics!” because writing software that interacts with real, physical hardware is so cool!

The Raspberry PI phenomenon (which is the best word I can come up with) has really done wonders. I have 100 ideas what to use them for, but as of writing I don’t have the hardware skill to start designing my own stuff. So the results so far are variations of servers, linux based games machines in cool boxes (like the node segadrive I put together, which is the coolest server EVER). To remedy this I have ordered a starter pack with diodes, pins, cables and enough parts to build my own dr.evil robot (joking) and right now I can’t wait getting started on it!

Also turned out my fellow Spartan likewise has a passion for retro gaming, so I got a quick lesson in Jamma boards and arcade cabinets, a topic which has been bugging me for ages (since so few seem to know exactly what you need to buy). And we also had a chat about the good old Amiga. The world is not that big after all and I guess most of us now in our 40’s started programming on 16 bit computers; And in northern Europe, UK and Scandinavia being the high-seat of Commodore outside the US, that meant the Amiga.

So very inspiring day and truly impressed!

Oslo Delphi Club

I think I’m going to follow-up on their meetings from now on. I have been asked to present Smart Mobile Studio earlier, but being swamped with work I was unable to accept — but this is something I’m going to prioritize. Not sure how many attendees there are at every given meeting, but  it’s always good to meet new people. And as a bonus: we never run out of stuff to talk about because it’s all Delphi!

And the club does get a lot of known Delphi guys visiting. Earliner this month they had Cary Jensen and Ray Konopka visiting, which I’m really sad I missed out on.

So if you live around Oslo or within driving range (takes me 90 minutes to get there on a good day) why not join me on their next meetup? I have no idea what date that would be, but if I’ll be speaking or presenting Smart Mobile Studio programming I’ll post an update here for those interested. But every meeting sounds pretty cool so if you, like me, are a bit tired of working solo on projects with Delphi — Oslo Delphi club can be a good place to meet other developers and exchange ideas.

Now that I think of it, thats a good venue for the Smart Mobile Workshop as well. Guess I’ll contact them about that tomorrow.

Use the train Luke

I’ve worked in Oslo earlier for 2-3 years, and you should think I would remember — but I managed to get stuck for 2 hours in rush traffic today. So rule of thumb is — if you plan on driving out of Oslo, you can pretty much forget that between 15:00 – 17:30. So if you plan to stick around in the city to around 16:00 — you might as well get a good book and wait it out.

In my Hydro days I had the good wits to wait until the 17:00 train, but this completely slipped my mind.

3.5 hours in a car makes me grumpy

3.5 hours in a car makes me grumpy

After 2 hours stuck in dead-slow traffic I saw the Ikea complex at slependen and decided to give up. That should speak volumes when a man enters Ikea of his own free will (!) And like always I went in to buy 2 things: A USB keyboard light and a reading lamp for my son. But I came out with — I dont know, a ton of stuff I didn’t even knew I was missing! So the kids are happy since they got some stuffed animals, paint, more paint, stickers, slippers and definitively more lamps than God ever intended a man to carry — and spoons. Oh yes, why shoot yourself in just one leg when you can cap ’em both with a single shot. My wallet though — not so happy. Funny how all those cheap items sum up.

So next time I’m visiting Oslo I think I’ll take the train because just blindly spending 3 1/2 hour inside a car, when the trip normally (before E18 got re-routed) takes 45 minutes, is more than my brain was built to handle. I’m pretty sure I flipped off an old lady around Drammen out of pure road-raging frustration.

Traveling by train though is just pure delight. On the train you can catch a sleep, drink some coffee, read a paper — or if you are like me, look like you are meditating but you are really coding on auto-pilot in the back of your mind 🙂

Ye old examples

I posted a small example yesterday of creating reference counted objects “on the fly” and just letting them die out after being called once or twice. And interestingly it’s created a bit of a response flow. I should have underlined better that it was only “an example” and not a technique I propose people use at every given situation. Also, loads of cool feedback on how to slim it down, make it faster and that sort of thing — so thanks for all the good comments.

If you look closer you’ll notice that the example does not come with a destructor in place. So if you use that code under the impression that it’s a copy & paste thing, be warned that it will leak memory like mad! And this is first of all due to a difference between Smart Mobile Studio and Delphi which, I must admit, I completely forgot.

Smart Mobile Studio code compiles to JavaScript, which means your code is subject to the V8 garbage collector. Which is a really cool piece of engineering I must say. So objects that goes out of scope, with no valid references being held at all – will simply (and safely) vanish into thin air. But under Delphi that’s quite a different story.

Under Delphi, TInterfacedObject reference-counting is not activated until you associate an interface with a live instance. In other words, TInterfacedObject is ultimately unsuitable for the technique I was demonstrating! The correct way, or “closest” way, to how Smart Mobile Studio does it — would be to use records, not objects. Ordinary, non pointer allocated records are managed by the Delphi memory manager and will, similar to JavaScript, be released immediately when there are no operations being performed on it.

Anyways, I’m to tired now to re-write the whole thing, so I’m just going to post a working version of the example code. Which is now abundantly over-engineered for it’s initial purpose. But at least it’s no longer leaking memory, and yes – this can be copy & pasted and used out of the box. Oh and I renamed the “Get” function to “Read()” instead.


  ISourceParameter = Interface
    ['{5FE0929E-20E3-440E-85FE-9553B5DF392E}']
      function    Empty:Boolean;
      function    AsString:String;
      function    AsInteger:Integer;
      function    AsBool:Boolean;
      function    AsFloat:Double;
  end;
  
  TSourceParameters = Class(TObject)
  private
    FLUT: TDictionary<string,string>;
  public
    type
    TSourceParameter = Class(TInterfacedObject,ISourceParameter)
    private
      FData:      String;
    public
      function    Empty:Boolean;
      function    AsString:String;
      function    AsInteger:Integer;
      function    AsBool:Boolean;
      function    AsFloat:Double;
      Constructor Create(Data:String);virtual;
    end;

    function    Read(Name:String):ISourceParameter;
    Constructor Create(CommandText:String);virtual;
    Destructor  Destroy;Override;
  end;

//#############################################################################
// TSourceParameters.TSourceParameter
//#############################################################################

Constructor TSourceParameters.TSourceParameter.Create(Data:String);
begin
  inherited Create;
  FData:=trim(Data);
end;      

function TSourceParameters.TSourceParameter.Empty:Boolean;
begin
  result:=length(FData)<1;
end;      

function TSourceParameters.TSourceParameter.AsString:String;
begin
  result:=FData;
end;

function TSourceParameters.TSourceParameter.AsInteger:Integer;
begin
  TryStrToInt(FData,Result);
end;

function TSourceParameters.TSourceParameter.AsBool:Boolean;
begin
  TryStrToBool(FData,Result);
end;

function TSourceParameters.TSourceParameter.AsFloat:Double;
begin
  TryStrToFloat(FData,Result);
end;

//#############################################################################
// TSourceParameters
//#############################################################################

Constructor TSourceParameters.Create(CommandText:String);
var
  mList:  TStringlist;
  x:      Integer;
  mId:    String;
begin
  inherited Create;
  FLUT:=TDictionary<string,string>.Create;
  
  commandText:=trim(commandText);
  if length(commandText)>0 then
  Begin
    (* Populate our lookup table *)
    mlist:=TStringList.Create;
    try
      mList.Delimiter:=';';
      mList.Text:=CommandText;
      for x:=0 to mList.Count-1 do
      begin
        mId:=lowercase(trim(mList.Names[x]));
        FLut.AddOrSetValue(mId, trim(mList.ValueFromIndex[x]) );
      end;
    finally
      mList.Free;
    end;
  end;
end;

Destructor TSourceParameters.Destroy;
begin
  FLut.Free;
  inherited;
end;    

function TSourceParameters.Read(Name:String):ISourceParameter;
var
  mData:  String;
begin
  name:=lowercase(trim(name));
  if length(name)>0 then
  FLut.TryGetValue(name,mData);
  result:=TSourceParameter.Create(mData) as ISourceParameter;
end;    

Advertisements
  1. May 27, 2015 at 6:26 am

    Why not just use a variant for the value here?

    • Jon Lennart Aasenden
      June 1, 2015 at 9:17 am

      He he.. yeah i thought about that before i went to bed, but i was to tired to do anything about it

  2. May 27, 2015 at 6:38 am

    Still insist on using string lists, eh?
    Well, you’re using it wrong. The Delimiter isn’t used when you assign to TStrings.Text. You need to use TStrings.DelimitedText instead – and don’t forget to set StrictDelimiter=True.
    …or you could just use SplitString()

    • Jon Lennart Aasenden
      June 1, 2015 at 9:16 am

      Like I wrote I was uber-tired when i posted this, so there are probably errors there. I recently made a splitstring function myself after the PHP model, but .. focus here was not on stringlist, but rather on throwing managed objects into limbo safely.
      But your point is well taken, I’ll clean it up when im well again. Been out of order with flu + allergies + a reaction to wrong medication, so you will have to forgive me for the oversight this time 🙂

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: