Archive

Posts Tagged ‘Delphi’

Firefox Addons, XUL, XPCOM, Delphi and a few headaches

November 30th, 2009

I wanted to share some information on creating Firefox addons/extensions (or however you care to refer to them). Not any old Firefox addons but XPCOM addons. It’s taken a couple of weeks of evening work to turn my Graabr Delphi application (www.graabr.com) into a Firefox Addon. Why bother?  Audience, I guess.

Anyhow, creating a non-XPCOM addon using javascript is relatively straightforward. But, an XPCOM is a different story. You need some Delphi-friendly Firefox header files which do not appear up-to-date. You also need a whole lot of patience. I found lots of snippets of info on Delphi XPCOM, but most ‘answers’ only raised further issues. Eventually, I rebuilt Graabr as a Delphi dll with three exposed interfaces. That is not enough for Firefox though. You cannot simply call a Delphi dll from Firefox, not without all the Firefox libs. So, what next? A download of the now free Visual C++ 2008 Express Edition (http://www.microsoft.com/Express/VC/). Incidentally, and one for another post, why is Delphi 2010 so expensive? After download and install, a lot of googling to get a XLRunner sample working in C++. Then, build a C++ dll wrapper, compatible with Firefox around the Delphi DLL. And voila, problem solved. Here is a link to the finished Graabr add-on:

https://addons.mozilla.org/en-US/firefox/addon/52178/

So, how does everything hang together? Well, after creating the extension framework, or environment, with all the required folders, files, etc (see here: https://developer.mozilla.org/en/Building_an_Extension), I created a small javascript app. which interfaces between Firefox and the C++ DLL. You can examine the source of this file by looking in the FF extension folder.  The javascript calls the C++ DLL which in turn calls the good old Delphi DLL where all the screen grabbing, uploading, etc work is done.  After creating the environment, files, structure, etc, you zip it all up into a .xpi file (zippy as they call it) and upload it to FireFox addons.

Oh, it’s oh so simple :)

Delphi, graabr , , , , ,

Getting the local ip address with Delphi

March 22nd, 2009

Ever wanted to get your computer’s local ip address?  Well here’s a code snippet to help you along!

{——————————————————————————}

function LocalIP: string;
type
TaPInAddr = array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: array[0..63] of Char;
I: Integer;
GInitData: TWSAData;

begin
WSAStartup($101, GInitData);
Result := ”;
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(buffer);
if phe = nil then Exit;

pPtr := PaPInAddr(phe^.h_addr_list);

I := 0;

while pPtr^[I] <> nil do
begin
Result := inet_ntoa(pptr^[I]^);
Inc(I);
end;

WSACleanup;
end;

Delphi ,

No Delphi Programmer should be without this resource

January 2nd, 2009

Time and time again my google delphi search leads me to this excellent resource of information on programming and the fundamentals of Delphi:

http://www.delphibasics.co.uk/index.html

Thanks Neil for a truly useful resource!

Delphi ,