Lazarus

Programming => General => Topic started by: daveinhull on September 21, 2019, 05:04:37 am

Title: Passing arrays to PowerPoint routine
Post by: daveinhull 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
Title: Re: Passing arrays to PowerPoint routine
Post by: daveinhull 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
Title: Re: Passing arrays to PowerPoint routine
Post by: Thaddy 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
Title: Re: Passing arrays to PowerPoint routine
Post by: daveinhull on September 26, 2019, 07:47:55 am
Thaddy, excellent thank you.... :D
Title: Re: Passing arrays to PowerPoint routine
Post by: Thaddy 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
TinyPortal © 2005-2018