Recent

Author Topic: Passing arrays to PowerPoint routine  (Read 270 times)

daveinhull

  • Sr. Member
  • ****
  • Posts: 264
  • 1 divided by nothing must still be 1!
Passing arrays to PowerPoint routine
« on: September 21, 2019, 05:04:37 am »
Hi,

Hope someone can help. I've trying to work with PowerPoint from Pascal and can get most of the things to work, but I have a problem when a PowerPoint routine needs an array. I'm just not sure how to do this in Pascal, e.g.

Code: Pascal  [Select]
  1. ReDim Preserve MyTitleArray(1 To nCounter)
  2.  
  3. Set rngTitleSlides = ActivePresentation.Slides.Range(MyTitleArray)

How would I setup and pass the MyTitleArray?

Thanks in advance
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

daveinhull

  • Sr. Member
  • ****
  • Posts: 264
  • 1 divided by nothing must still be 1!
Re: Passing arrays to PowerPoint routine
« Reply #1 on: September 26, 2019, 03:16:44 am »
Hi,

Anyone got any thoughts? Would appear to be a simple mapping of data formats between Office VBA and Lazarus Pascal?

Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 8867
Re: Passing arrays to PowerPoint routine
« Reply #2 on: September 26, 2019, 07:41:39 am »
(Ole) Variant arrays. MyTitleArray is such an array.
Simple example:
Code: Pascal  [Select]
  1. uses variants;
  2. var
  3.   VarArray: Variant;
  4.   Value: Variant;
  5. begin
  6.    VarArray := VarArrayCreate([0, Length - 1], varVariant);
  7.    // or if the type is known something like: VarArray := VarArrayCreate([0, Length - 1], varInteger);
  8. end.

The scripting in the office suite always requires COM compatible  Ole variant types and these are fully supported by Freepascal.

There are several thousand examples on how to do Office automation with Delphi or FreePascal available on the web.

Michael can Canneyt wrote a good paper on office automation (word, but also applies to pwoerpoint)
https://www.freepascal.org/~michael/articles/word/word.pdf
« Last Edit: September 26, 2019, 07:50:28 am by Thaddy »
Most people that want to use threading should learn to patch their jeans first: use a needle.

daveinhull

  • Sr. Member
  • ****
  • Posts: 264
  • 1 divided by nothing must still be 1!
Re: Passing arrays to PowerPoint routine
« Reply #3 on: September 26, 2019, 07:47:55 am »
Thaddy, excellent thank you.... :D
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 8867
Re: Passing arrays to PowerPoint routine
« Reply #4 on: September 26, 2019, 08:10:20 am »
Also https://www.freepascal.org/~michael/articles/word2/word2.pdf which is an update to the first.
(Both still work with current versions of office)

Also note office comes with type libraries that you can import. In that case you can use early binding rather than late binding.

And here:
https://ntluna.blogspot.com/2013/09/delphi-powerpoint-with-ole-automation.html
« Last Edit: September 26, 2019, 08:19:24 am by Thaddy »
Most people that want to use threading should learn to patch their jeans first: use a needle.