* * *

Author Topic: [SOLVED] Using CCR.Exif in Lazarus.  (Read 1033 times)

Hopestation

  • Full Member
  • ***
  • Posts: 132
[SOLVED] Using CCR.Exif in Lazarus.
« on: January 12, 2018, 08:16:24 pm »
Hi.

Has anyone used this Delphi program in Lazarus.

I tried converting some of the projects to Lazarus and got errors each time in every line in CCR.Exif.inc referring to compiling options.

Are these relevant to Lazarus?

Thanks
« Last Edit: January 15, 2018, 06:17:15 pm by Hopestation »

wp

  • Hero Member
  • *****
  • Posts: 4074
Re: Using CCR.Exif in Lazarus.
« Reply #1 on: January 12, 2018, 09:55:19 pm »
I tried, but was not successful either. Maybe gave up too early...

In the meantime I wrote my own Exif library (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/fpexif/) which was more rewarding than fixing compilation issues. There is one problem left before making a formal announcement: editing of Exif data may destroy the MakerNotes. But if you only want to read it should work, just look at the examples provided.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

molly

  • Hero Member
  • *****
  • Posts: 2214
Re: Using CCR.Exif in Lazarus.
« Reply #2 on: January 12, 2018, 10:11:29 pm »
Same results here. I end up with missing TWideString and TWideStringsList. Theoretically those can be added from mike's implementation, but i stopped there. fwiw using fpc compiler.

You can get a lot further by excluding the delphi specific stuff from the .inc file. Leaving you with some minor changes (except for the widestrings mentioned above).

Hopestation

  • Full Member
  • ***
  • Posts: 132
Re: Using CCR.Exif in Lazarus.
« Reply #3 on: January 13, 2018, 03:37:43 pm »
Hi. Thanks for your replies.

I am using Lazarus Version #: 1.6.2, FPC Version3.0.0, SVN Revision 53354, x86_64-wind64-wind32/wind64.

I have downloaded all the files on the web page into a directory called pfexif, apart from FPEXIF.pas,  with sub-directories: Simple and Metadata Viewer for two of the examples, where I have loaded the respective files.

I have tried to run the Simple example but get the message:

  fpeutils.pas(89,57) Error: Identifier not found "TStringArray"

Have I done something wrong?

Thaddy

  • Hero Member
  • *****
  • Posts: 5202
Re: Using CCR.Exif in Lazarus.
« Reply #4 on: January 13, 2018, 03:57:55 pm »
You are not using current versions. That's what is wrong (should be Laz1.8/FPC 3.0.4)
Anyway TStringArray is simply Array of string; so declare:
Code: Pascal  [Select]
  1. type
  2.   TStringarray = array of string;

But better to upgrade: it's free... And this declaration is not necessary...
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

molly

  • Hero Member
  • *****
  • Posts: 2214
Re: Using CCR.Exif in Lazarus.
« Reply #5 on: January 13, 2018, 04:08:52 pm »
Have I done something wrong?
uhm... no not really  :)

It is just that your lazarus/fpc is a little outdated (as mentioned by Thaddy).

You can make a quick fix though:
- inside fpeutils.pas around line 36 there is the definition "TStringArray = array of string;"
- directly underneath that line you can read "{$ENDIF}"
- make it so that the {$ENDIF} is above the line where it reads "TStringArray = array of string;"
- save your chnages
- build your project.

wp

  • Hero Member
  • *****
  • Posts: 4074
Re: Using CCR.Exif in Lazarus.
« Reply #6 on: January 13, 2018, 05:10:34 pm »
I added the declaration of TStringArray if the fpc is 3.0 or less. Now the package compiles with all versions down to Laz 1.2/fpc2.6.2. But like the others, I highly recommend the upgrade to Laz 1.8.

I don't fully understand what you were doing, but I get the impression that you are copying things around. Don't do this. The package files rely on the directory structure given. If you don't work with svn it may be a bit hard to download the files that I linked to: you must download the entire ccr repository and extract from the zip file only the projects that you need (here: components/fpexif). To help you I am attaching a zip of the current fpexif sources alone. Just unzip it, open and compile the file fpexif_pkg.lpk, no need to install anything. Then you can run the examples. Please note that I had to remove the test images and test projects in order to comply with the file size restriction of the forum.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Hopestation

  • Full Member
  • ***
  • Posts: 132
Re: Using CCR.Exif in Lazarus.
« Reply #7 on: January 13, 2018, 08:21:36 pm »
Thanks WP.

After installing version 1.8.0 I've got the Simple program working.

It's introduced me to some features I've not come across before:

   The use of MainForm.runbefore and ini files. You don't actually name the ini file in the file,
   but it finds it anyway.

   I tried to reduce the width of the main frame and found that the components all moved
   with the right hand side. I've always put controls where I wanted them. I found the main
   form property "ChildSizing". Is this what is proportioning the size of the memo when I
   reduce the form width?

wp

  • Hero Member
  • *****
  • Posts: 4074
Re: Using CCR.Exif in Lazarus.
« Reply #8 on: January 13, 2018, 10:17:15 pm »
The controls are anchored to each other. Use the anchor editor ('...' button next to property Anchors). See http://wiki.freepascal.org/IDE_Window:_Anchor_Editor or http://sheepdogguides.com/lut/lt2Nd.htm. A general and well-written article about auto-sizing is http://wiki.freepascal.org/Autosize_/_Layout.

The ini file is created from the name of exe, replacing the extension by '.ini'. See function CreateIni. Please note that this practice is not recommended for a "real" application because usually it is not allowed to write into its exe folder. In the general case, use GetAppConfigDir() (http://lazarus-ccr.sourceforge.net/docs/rtl/sysutils/getappconfigdir.html) instead.

"BeforeRun" is not a built-in method. It is declared in the public section of the form and called in the project file (.plr) before "Application.Run" - that's why it is named like this. At this time, the form is fully created, and I use this to read the ini file. Usually people do this in one of the form's events (OnCreate, OnActivate), but I think it is clearer this way.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Hopestation

  • Full Member
  • ***
  • Posts: 132
Re: Using CCR.Exif in Lazarus.
« Reply #9 on: January 14, 2018, 07:16:12 pm »
Thanks for that detailed explanations WP.

Iv'e now got my program to change photo file names to date-time+.jpg working.


« Last Edit: January 15, 2018, 10:24:20 am by Hopestation »

Hopestation

  • Full Member
  • ***
  • Posts: 132
Re: Using CCR.Exif in Lazarus.
« Reply #10 on: January 15, 2018, 10:38:14 am »
I thought that I had completed my program until I tried to use the RenameFile function and it failed. I thought that I might have made the jpg files read-only, but they are not. I thought that maybe the file I was trying to rename was still open, but as far as I can tell, using LoadfromFie is a single operation.

My form has a File List Box and a List Box. I load the file names from my chosen directory into the former and then take each file name in turn, find its original date from the Exif data and create a new name. finally I rename the original file. The List Box contains the original file name and new file name for each file.

My code is below:-

procedure TMainForm.BtnLoadClick(Sender: TObject);
var
  i, N: Integer;
  lTag: TTag;
begin
  ListBox.Clear;

  For N := 0 to FileCount - 1 Do
  begin
    OldName := FileListBox.Items[N];

    if FImgInfo = nil then FImgInfo := TImgInfo.Create;
    try
      FImgInfo.LoadFromFile(ExpandFileName(OldName));
      if FImgInfo.ExifData <> nil then
      begin
        if FImgInfo.HasExif then
        begin
          for i:=0 to FImgInfo.ExifData.TagCount-1 do
          begin
            lTag := FImgInfo.ExifData.TagByIndex;
            if lTag.Name = 'DateTimeOriginal' then
            begin
              NewName := lTag.AsString + EdtSuffx.Text + '.jpg';
              ListBox.AddItem(OldName + ':  ' + NewName, Nil);
              Continue;
            end;
          end;
        end;
      end;
    except
      EdtDatTim.Text := 'ERROR';
    end;
    if not RenameFile(OldName, NewName) then
     MessageDlgPos('Unable to rename file'+OLDNAME,mtWarning,[mbOK],0,100,200);
  end;
  FileListBox.UpdateFileList;
end;

Is there a mistake?

Thanks.

wp

  • Hero Member
  • *****
  • Posts: 4074
Re: Using CCR.Exif in Lazarus.
« Reply #11 on: January 15, 2018, 10:56:23 am »
At first, please edit your previous post and put the code part between [ code] and [ /code] tags (without the space after "[" - the sudden appearance of italic text indicates that some index [ i] has been swallowed by the forum software and been mis-used to start italic formatting.

Then, if possible, I'd appreciate if you'd assemble a little demo project which compiles and shows the same error. Pack *.pas, '*.lfm, '*.lpi and *.lpr files into a common zip which you can upload here under "Attachments and other options".
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 4074
Re: Using CCR.Exif in Lazarus.
« Reply #12 on: January 15, 2018, 03:38:09 pm »
I added a new example project, "file_renamer", to the fpexif project; it reads the EXIF date/time and adds it to the original filename of an image.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Hopestation

  • Full Member
  • ***
  • Posts: 132
Re: Using CCR.Exif in Lazarus.
« Reply #13 on: January 15, 2018, 06:16:18 pm »
Thanks for the renamer example. It gave me the answer to my problem.

I noticed that you had used:   DATETIME_MASK = 'yyyymmdd-hhnnss'; and this is the format that is used in the new file name.

I had taken the format straight from the date tag, which gave me a new file name of:

'yyyy-mm-dd hh:mm:ss.jpg'

When I changed the ':' to '-' the renaming worked.

Also, I have tried to use the ShellTreeView in the past without success, so that has been a help also.

I don't know why part of my code was in italics. It was a straight Cut&Paste from the Lazarus editor.

Thanks again for your help.

howardpc

  • Hero Member
  • *****
  • Posts: 2507
Re: Using CCR.Exif in Lazarus.
« Reply #14 on: January 15, 2018, 06:29:50 pm »
I don't know why part of my code was in italics. It was a straight Cut&Paste from the Lazarus editor.

The forum software treats [ i ] (without the spaces inserted between [  i and ]) as an instruction to start italicising text display.
So a Pascal array index using "i" as the index variable is doomed... unless you artificially insert spaces.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus