Wednesday 15 February 2017

Delphi Time Machine

- or how to communicate with the past is possible - kind of...




I am a bit late on congratulating Delphi's anniversary yesterday - so what would fit better than inventing a time machine - or communication setup that could communicated back in time.


There is a nice video by Paul TOTH out there from yesterday: https://www.youtube.com/watch?v=DDp8K3tUn_I, among others. I need to work on my French :)

So I thought that if I just did a simple application in Delphi 1 from 1995 and then compiled the same unchanged code with the latest Delphi 10.1 Berlin Update 2 from late last year, and these two versions could "communicate" that would be fun.

Delphi 1 was great and outstanding, but there were so many things that were in a different state than today - like the landscape of networking - so running my Delphi 1 in a DosBox on Win 3.1 to be as authentic as possible seemed not a good idea - if I wanted to do some "communication".

I ended up installing Delphi 1 on a virtual XP - created the application just using simple Postmessage - recompiled the unchanged code in Delphi 10.1 Berlin Update 2 on a 32-bit Windows 7 - otherwise I would have a problem running my 16-bit Delphi 1 application. The source code is below and the picture above show the two versions running side-by-side Delphi 1 on the left. There was no DatePicker control in Delphi 1, so I used two TMaskEdit :)

unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Mask;

type
  TForm1 = class(TForm)
    MaskEdit1: TMaskEdit;
    MaskEdit2: TMaskEdit;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure WndProc(var Message: TMessage); override;
  end;

const
  MyMessage = 'FutureMsg';

var
  Form1: TForm1;
  MyMessageID: cardinal;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  targetHandle: THandle;
  a: array[0..79] of char;
begin
  caption := MaskEdit1.Text;
  targetHandle := FindWindow(Pchar('TForm1'), StrPCopy(a, MaskEdit2.Text));
  if PostMessage(targetHandle, (MyMessageID), 0, 0) then
    showmessage('Receiver found.');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyMessageID := RegisterWindowMessage(MyMessage);
end;

procedure TForm1.WndProc(var Message: TMessage);
begin
  inherited WndProc(Message);
  if Message.Msg = MyMessageID then
  begin
    showmessage('Got message');
  end;
end;

end.

In newer versions of Delphi you would probably utilize some newer syntax features - I would.

A shout-out to some "developers" could also be in place - there are some people that keep using the past tense when speaking about Delphi - and have been doing that for at least the last 10 years - so either they are not very enlightened, unintelligent or simply to lazy to do their homework - or maybe this is just getting more common in these post factual times we live in.

While we are at the post factual - let me misquote Mark Twain: “The reports of my death are greatly exaggerated.” - which is very true for Delphi.

If it had not been for Delphi - I would probably not still have been a passionate develop@heart.

I have used various other languages before, during, under and besides Delphi over the years - but in most case Delphi has been (is) the best tool for the jobs I get involved in. If a customer dictates the tool I charged extra - and they even pay for an extended period of time because the ineffectiveness of many other tools compared to Delphi.

An old tagline of Borland's was Software Craftsmanship - and you should never dictate what tools a real craftsman uses - otherwise she/he will never give their best.

And I am not saying you should never learn anything new - you should everyday - just look at the "Delphi" stack alone - IoT, FireDAC, MicroServices, Mobile, Linux .... and the list goes on, Delphi has evolved a lot over the years - some have not been paying attention - and others like me just want more and want to enjoy what the future brings :)

BTW: Do you remember how great the help was in Delphi 1 :D

Happy late Valentines Day and Birthday - #ILoveDelphi

No comments:

Post a Comment