Scripting possible with arrays of records or 2D arrays?

Post Reply
mjbiggs
Posts: 6
Joined: 01 Oct 10 21:50

Scripting possible with arrays of records or 2D arrays?

Post by mjbiggs » 13 Jul 20 18:38

I'm attempting to write a Photo Supreme script that compares the Photo Date of an image with date-time strings stored either in an array of records or in a 2D array. I have a working pascal version which begins as follows:

Code: Select all

type
    recDateTime = Record
        Year, DT1, DT2: String;
    end;

const
    arrDateTime: array [ 1 .. 9 ] of recDateTime = (
        ( Year: '2001'; DT1: '2001-01-21 01:00'; DT2: '2001-07-21 01:00' ),
        ( Year: '2002'; DT1: '2002-01-21 02:00'; DT2: '2002-07-21 02:00' ),
        ( Year: '2003'; DT1: '2003-01-21 03:00'; DT2: '2003-07-21 03:00' ),
        //...
        ( Year: '2009'; DT1: '2009-01-21 09:00'; DT2: '2009-07-21 09:00' )
         );

//...
I've been testing by copying my pascal code into custom thumbnail fields (and also to Scripter) but Photo Supreme appears not to recognize (or just not like) the type statement or array declaration and initialization.

Is Photo Supreme able to handle arrays of records or 2D arrays? If possible, how should I code this?

Any help at all much appreciated.

Mike

Hert
Posts: 6250
Joined: 13 Sep 03 7:24

Re: Scripting possible with arrays of records or 2D arrays?

Post by Hert » 14 Jul 20 7:59

Photo Supreme's Scripter uses a subset of Object Pascal. You can't define Types in a script.

Here's one way of achieving what you want (a bit more cumbersome):

Code: Select all

  function AddArrayElem(AArray: TidElement; AYear, ADt1, ADt2: WideString): TidElement;
  begin
    result := AArray.Elements.Add;
    result.Prop['Year'] := AYear;
    result.Prop['DT1']  := ADt1;
    result.Prop['DT2']  := ADt2;

  end;

  function InitArray: TidElement;
  var
    AElem: TidElement;
  begin
    result := TidElement.Create(nil);
    AddArrayElem(result, '2001', '2001-01-21 01:00', '2001-07-21 01:00');
    AddArrayElem(result, '2002', '2002-01-21 02:00', '2002-07-21 02:00');
    AddArrayElem(result, '2003', '2003-01-21 03:00', '2003-07-21 03:00');
    AddArrayElem(result, '2004', '2004-01-21 04:00', '2004-07-21 04:00');
    AddArrayElem(result, '2005', '2005-01-21 05:00', '2005-07-21 05:00');
    AddArrayElem(result, '2006', '2006-01-21 06:00', '2006-07-21 06:00');
    AddArrayElem(result, '2007', '2007-01-21 07:00', '2007-07-21 07:00');
    AddArrayElem(result, '2008', '2008-01-21 08:00', '2008-07-21 08:00');
    AddArrayElem(result, '2009', '2009-01-21 09:00', '2009-07-21 09:00');
  end;

var
  arrDateTime, AElem: TidElement;
  i: Integer;
begin
  arrDateTime := InitArray();
  try
    for i := 0 to arrDateTime.Elements.Count - 1 do
    begin
      AElem := arrDateTime.Elements.Items[i];
      Say2(AElem.Prop['Year'], AElem.Prop['Dt1'] + ' -> ' + AElem.Prop['Dt2']);
    end;
  finally
    arrDateTime.Free;
  end;
end;
BTW; wouldn't it be easier to add dates typed TDateTime instead of strings? That would make it easier later to check if a date is in your defined date ranges.
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

mjbiggs
Posts: 6
Joined: 01 Oct 10 21:50

Re: Scripting possible with arrays of records or 2D arrays?

Post by mjbiggs » 14 Jul 20 8:40

That's excellent. Thanks very much Hertz.

I should be able to achieve what I want based on your example.
Will also investigate using dates typed TDateTime instead of strings as you suggest. Advice much appreciated.

Regards

Mike

Hert
Posts: 6250
Joined: 13 Sep 03 7:24

Re: Scripting possible with arrays of records or 2D arrays?

Post by Hert » 14 Jul 20 9:55

Code: Select all

  function AddArrayElem(AArray: TidElement; AYear: WideString; ADt1, ADt2: TDateTime): TidElement;
  begin
    result := AArray.Elements.Add;
    result.Prop['Year'] := AYear;
    result.Prop['DT1']  := ADt1;
    result.Prop['DT2']  := ADt2;

  end;

  function InitArray: TidElement;
  var
    AElem: TidElement;
  begin
    result := TidElement.Create(nil);
    AddArrayElem(result, '2001', EncodeDateTime(2001, 01, 21, 01, 00, 00, 000), EncodeDateTime(2001, 07, 21, 01, 00, 00, 000));
    AddArrayElem(result, '2002', EncodeDateTime(2002, 01, 21, 02, 00, 00, 000), EncodeDateTime(2002, 07, 21, 02, 00, 00, 000));
    AddArrayElem(result, '2003', EncodeDateTime(2003, 01, 21, 03, 00, 00, 000), EncodeDateTime(2003, 07, 21, 03, 00, 00, 000));
    AddArrayElem(result, '2004', EncodeDateTime(2004, 01, 21, 04, 00, 00, 000), EncodeDateTime(2004, 07, 21, 04, 00, 00, 000));
    AddArrayElem(result, '2005', EncodeDateTime(2005, 01, 21, 05, 00, 00, 000), EncodeDateTime(2005, 07, 21, 05, 00, 00, 000));
    AddArrayElem(result, '2006', EncodeDateTime(2006, 01, 21, 06, 00, 00, 000), EncodeDateTime(2006, 07, 21, 06, 00, 00, 000));
    AddArrayElem(result, '2007', EncodeDateTime(2007, 01, 21, 07, 00, 00, 000), EncodeDateTime(2007, 07, 21, 07, 00, 00, 000));
    AddArrayElem(result, '2008', EncodeDateTime(2008, 01, 21, 08, 00, 00, 000), EncodeDateTime(2008, 07, 21, 08, 00, 00, 000));
    AddArrayElem(result, '2009', EncodeDateTime(2009, 01, 21, 09, 00, 00, 000), EncodeDateTime(2009, 07, 21, 09, 00, 00, 000));
  end;

var
  arrDateTime, AElem: TidElement;
  i: Integer;
begin
  arrDateTime := InitArray();
  try
    for i := 0 to arrDateTime.Elements.Count - 1 do
    begin
      AElem := arrDateTime.Elements.Items[i];
      Say2(
            AElem.Prop['Year'],
            DateTimeToStr(AElem.Prop['Dt1']) + ' -> ' + DateTimeToStr(AElem.Prop['Dt2'])
          );
    end;
  finally
    arrDateTime.Free;
  end;
end;
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

mjbiggs
Posts: 6
Joined: 01 Oct 10 21:50

Re: Scripting possible with arrays of records or 2D arrays?

Post by mjbiggs » 14 Jul 20 10:48

That's great. All making sense now. Thank you.

Post Reply