Python in Delphi
I’ve been looking for a way to modularize my programs for some time now..
Most of the time, I ended up just using dynamic link libraries but this time around I decided to try a real scripting engine. It was either LUA or Python that I was considering.
In the end, Python won. Sadly, I could not find any decent way to use Python from Delphi that suited me, I found the ‘P4D’ (Python 4 Delphi) project but its limited to Windows only, and as far as I could tell, it simply wont compile on my 64bit OS (yet).
So whats next? Well, I could always just translate the python header files and work directly against the libraries.. But it would be too much effort involved, and h2pas didnt cut it.
I tried a really strange approach, it works.. but, its .. strange.
What I came up with was this, write the code that actually uses python in C, compile it with gcc and then link the output with the rest of my application.
I have thrown together a quick demo of the idea, it works.. but please dont flame me =/
Download link is here. written and tested in Linux with FPC 1.9.8 (yes, a bit old)
Code snippets
I have now opened a Code snippets section at winsbydefault.com
The idea here is to be able to released random code I’ve written, and so that people can use it and report the bugs they find.. or just post comments about my code.
Right now, The trac allows anyone to submit new tickets. I realize this might get abused a lot so if that happens I will have to figure something else out.
Please have a look
Trac page
note that the trac page allows svn browsing, so its the only really important page
SVN page
trac page will get some wiki love soon(tm) as well as some sort of logo I guess.
Lazarus
Its been years since I tried Lazarus the last time..
Lazarus, is for those of you who doesnt know, A FOSS Delphi IDE, its look is almost identical to Borland Delphi 7 which I normally use. I decided to give it a go and downloaded it last night to try it out.
First impressions, nice. looks professional now. The interface does not look like its from the 90s, code editor works pretty well, and unlike the last time, it actually is ok to work in and it compiles fine.
This is certainly a good alternative for those who seek to try Delphi and wants a good FOSS alternative for the IDE. By default, Lazarus will use the FPC (Free Pascal Compiler), which is an excellent compiler and works on a wide range of platforms as well.
You can get Lazarus at
Delphi hashmaps
Hashmaps are nice, everyone likes hashmaps.
I’ve wanted one for Delphi for a while, for no real reason. Been thinking of making one, how hard can it be?
(it turned out to be very easy heh heh)
I ended up with some spare time over this weekend, so I threw together a quick hashmap, written in Delphi 7.
The usage is pretty clear here. The hashmap will store a pointer to whatever value it wants to hold. Ill provide an example:
var
hashmap: THashmap;
ptr: ^TTest;
begin
hashmap := THashmap.Create();
new(ptr);
ptr^ := TTest.Create();
hashmap.SetValue('somekey', ptr);
ptr := nil;
ptr := hashmap.GetValue('somekey');
FreeAndNil(ptr^);
FreeAndNil(hashmap)
end;
The unit is available on my SVN here
Its worth noting that, due to the genericness of the hasmap, It only keeps a pointer to its value therefor has no clue
what data it points to and can thusly not be responsible for freeing the object it reference to, this has to be the responsibility
of the programmer.
Also, The unit is still very much work-in-progress, allthough it works, one sould be aware that I will update it as I get time to and
full usage will be available in the units comment at the top.

