Update 5-Oct-2006: This article is for Delphi 2005 Personal. The new free Turbo Delphi Express comes with Indy already installed, so you can skip the Installing Indy section below.
I recently worked on a couple of projects involving the great Flickr API. My first project was postponed and became my second due to delays in getting the Delphi Flickr component dFlickr installed and working. This was due to a combination of my inexperience, outdated documentation, and bad luck.
Flickr is a picture sharing site. Their API lets programmers upload and download images within their programs. In simple terms, the program sends a request in a URL's querystring, and Flickr returns the results in XML. I am using Delphi 2005 Personal, which doesn't include any facilities for accessing the internet or processing XML, so I am reliant on external components for this. dFlickr fits the bill perfectly.
Installing Indy
To prepare Delphi for Indy, you need to install a special file. Without this, Indy will not compile.
Now to Indy itself. The first step is to install Indy(.Sockets) 10. I used the latest development snapshot. The instructions on the Indy web site for installation through the Delphi IDE didn't work for me. Luckily, they also provide some batch files that do work. Before that, though, you need to compile Lib/Computil.dpr. You can do this in the IDE, just open it and choose Project | Compile. This will create the Computil.exe file. Note that if you close the IDE without saving then the Computil.exe mysteriously disappears, so save it.
Now you can run the correct batch file. Those in the know will be aware that Delphi 2005 is really just Delphi 9, so you need to run Lib/Fulld9.bat. That should complete with a few unimportant warnings.
Finally, go into the IDE and go to Component | Install Packages. Here you should add Lib/Core/dclIndyCore and then Lib/Protocols/dclIndyProtocols. They should then appear as new items in your Tool Palette. Oh, and absolutely finally, you need to set the paths as mentioned in the otherwise outdated Indy documentation.
Installing and using dFlickr
That's the hard stuff out of the way. Nothing else needs to be installed, just referenced when needed. That is, just use 'Add to project' to use dFlickr.pas. If necessary, it'll ask to be pointed to the other components included in the dFlickr download, which you can similary 'Add to project'.
An important note is that the version of Indy currently available seems out of sync with dFlickr, resulting in all dFlickr calls failing with an Assert error. The latest dFlickr, 0.9.3b uses POST, whereas previous versions used GET. Indy objects to the way that dFlickr does its POST, so you must either use an old dFlickr, or change the line about 1055 back from POST to GET (just uncomment the GET line and add a comment to the POST line). The author of dFlickr has been very responsive to my queries, so watch for a better solution in 0.9.4.
Finally, the sample code on the dFlickr page is outdated, and no longer works. Here's my sample. If shows the number of photos which are tagged as 'puppy' or 'beach', and gives the URL of the small thumbnail image of the first of those photos.
var
Flickr: TFlickr;
PhotoList: TFlickrPhotoList;
begin
Flickr := TFlickr.Create('YOUR_FLICKR_API_KEY','');
try
PhotoList := Flickr.PhotosSearch('','beach,microsoft');
ShowMessage(inttostr(PhotoList.Total) + ' photos found');
ShowMessage(PhotoList.GetPhoto(0).Sizes.GetSize(0).Source);
except
on E: Exception do ShowMessage('Error: ' + E.Message);
end;
end;