Accessing ExifTool with Delphi XE2

Started by BogdanH, November 08, 2011, 02:24:23 PM

Previous topic - Next topic

BogdanH

Hi,

I am using Delphi v7 (Pascal programming tool) since 2002 and many (me included) agree, this version is the best ever made. I've tried almost all versions since then, but was never really impressed enough to spend money for "upgrade" (after all, programming is only my hobby). Not because newer versions were worse than Delphi7. I would say, the problem was Windows OS: if we forget Windows Vista, nothing important happened since Windows XP introduction -hence, with Delphi7 (D7), I can do almost everything what could be done with more recent Delphi releases.

Anyway, now, here's Windows7, where many things changed/improved under hood. I can continue to use D7 and everything works as before (as in WinXP, that is). But reality is, in Win7, D7 is starting to be "outdated"... and I am curious person  :).
To keep story short: I just got latest Delphi XE2 (which is actually v16) -it's basic edition, but I don't need more.

Right now, I am working on ExifTool's stay_open feature, which I've started by using Delphi7. What I have right now is, few working functions, which serve me as a basis for "communication" with ExifTool. These will be enhanced over the time, but I'm happy with what I've made.
Anyway, this was a great chance to check my existing (working!) stay_open code in "new" Delphi. Ok, so I've just pasted my existing code into Delphi XE2 and started "compile" (for non-programmers: "create exe file")... and XE2 didn't complained. I was expecting that I would need to "adapt" at least some of my code, but that wasn't the case -except: resulting exe (=program) didn't work!
Now, this was about right time, to become disappointed... The same code, successfully(!) compiled in both Delphi versions: one works, another doesn't  :o And how to find the reason, why's that? How to make it work in Delphi XE2?

Magic word is: Unicode. In XE2, everything (characters related) is happening in Unicode. For example (I promise, I'll be short), when a string (=series of characters) is declared, it's done with:
var
  ETcmd: string;

-which, in D7, reserves space for Ansi encoded string.

And if I wish to send content of that string to ExifTool, I use (for example):
  WriteFile(PipeInWrite, ETcmd[1], Length(ETcmd), BytesCount, nil);
-and, as expected, ExifTool executes command sent.

In XE2, if exactly the same code is used, ExifTool won't recognize the content of ETcmd -with "Not Responding" results (aka. freezing).
Why's that? Because, in XE2, the same declaration:
var
  ETcmd: string;

-reserves space for Unicode string! That is, content in that space (characters) is Unicode (not Ansi) encoded.

Solution is obvious: convert string into some non-Unicode kind of string, just before sending to ExifTool. Yes, it sounds simple... the problem is, we (programmer) must keep that in mind all the time. Otherwise, stuff simply won't work -and programmer will keep saying "this simply must work! how come, it doesn't??".

Now, I think, there's no way I would move existing ExifToolGUI to XE2. There might be other XE2 specific issues, which I'm not aware of yet... and I don't need the torture. But, XE2 is here to be used and I have allready moved my stay_open code into it... maybe that's the beginning of total new GUI.

That's it. I just though, above experience is worth to share. I hope, it was a bit interesting...

Bogdan

Phil Harvey

Hi Bogdan,

It is interesting to read about some of your programming issues.  I understand completely with not wanting to upgrade.  It is a real pain having to fix things that break every time someone comes out with a new compiler.  I had similar problems with ExifTool because Perl started implementing built-in Unicode support with version 5.6 (which has been the biggest source of pain for me when ti comes to the Perl language).  Of course, the implementation changed with version 5.8, and it changed again with 5.10.  You will see lots of tests of the Perl version ($]) in my code to work around these differences because ExifTool is designed to work for all Perl versions from 5.004 on (currently version 5.14 is in the testing phase I believe).  Perl version 6 has been in the pipeline for a long time, but there are some big changes with this version that would make it necessary to rewrite substantial portions of ExifTool, so I probably won't be porting ExifTool to Perl 6 if/when it becomes available.

All these headaches are the main reason I try really hard to keep backward compatibility with all of the changes I make to exiftool.  I don't want ExifTool updates to cause you (and other ExifTool developers and users) extra work.  Especially since regular ExifTool updates are necessary if you want to keep up-to-date with new cameras and metadata specifications.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

BogdanH

Quote from: Phil Harvey on November 08, 2011, 03:43:32 PM
...but there are some big changes with this version that would make it necessary to rewrite substantial portions of ExifTool, so I probably won't be porting ExifTool to Perl 6 if/when it becomes available.
-I see "probably" here  :)

The thing is, that at some point (sooner or later), it can become harder to keep some app alive (by using "old" developing tool), than adapting application and continuing with newer dev tool. And the longer the hesitating, the harder it can become. Ok, my life doesn't depend on that, but I hope I'll be able to write some code in, say, ten years -so it's not "if", but "when" I will need to adapt.
Unicode stuff I have mentioned, is just a small (but quite important) part of all that. Yes, one can always use some "trick" to keep application usable in future. But at the end, the whole app can end as a bunch of tricks -not easy to maintain, though.

As mentioned, I will try to work on two lanes for a while: on one side, keep GUI v4 alive with Delphi7, new stuff however, I will try to do (and learn) with new Delphi version. I mean, hobby shouldn't become boring  :)

Quote..I don't want ExifTool updates to cause you (and other ExifTool developers and users) extra work.  Especially since regular ExifTool updates are necessary if you want to keep up-to-date with new cameras and metadata specifications.
That characteristic of ExifTool is quite important -especially for those (of us), who use ExifTool as "engine" in their applications.
But, when the time comes, you'll figure something out  ;)

Bogdan

MOL

Quote from: BogdanH on November 08, 2011, 02:24:23 PM
Solution is obvious: convert string into some non-Unicode kind of string, just before sending to ExifTool.
Much easier than you think. Just declare the string as an AnsiString, and you're good to go:

var
  MyStringThatWillBePassedToExifTool: ANSIString;