Recent

Author Topic: Strings in VBA in Lazarus Pascal?  (Read 841 times)

daveinhull

  • Full Member
  • ***
  • Posts: 100
Strings in VBA in Lazarus Pascal?
« on: April 16, 2018, 03:36:55 pm »
Hello,

I'm having some problems with OLE and the use of strings in VBA.
I try to set a string parameter in an OLE connection using a String variable in Pascal, but it errors - there may well be other problems, but if I set the parameter hard it works, but not as a string variable so I'm just wanting to check what type I should beusing in Pascal for a VBA string variable.

So in the code below
Code: Pascal  [Select]
  1.              NewFileName := PowerPointFilename + FilenamePart;
  2.              Label11.caption := NewFileName;
  3.              PPServer.ActivePresentation.Slides.Item(i).Shapes.Item(j).LinkFormat.SourceFullName := NewFileName;
  4.  

if I break point after the first line the variable NewFileName contains a valid text string, 'D:\....etc'.
However going on to the third line it errors with 777E9ABA eb33 jmp 0x777e9aef <ntdll!RtlIsNonEmptyDirectoryReparsePointAllowed+223>

If I hardwire the value to a file string it works ok?

Any thoughts?

Many thanks
Dave
« Last Edit: April 16, 2018, 03:42:40 pm by daveinhull »
Version #:1.6.4 Date 2017/02/17 FPC Version: 3.0.2 and SVN Revision 54278 for i386-win32-win32/win64

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: Strings in VBA in Lazarus Pascal?
« Reply #1 on: April 16, 2018, 03:40:49 pm »
I'm having some problems with OLE and the use of strings in VBA.

You probably want to use WideString.

http://wiki.lazarus.freepascal.org/Office_Automation


daveinhull

  • Full Member
  • ***
  • Posts: 100
Re: Strings in VBA in Lazarus Pascal?
« Reply #2 on: April 16, 2018, 04:22:40 pm »
Phil,

Many thanks, didn't even know WideString existed, but it did the trick.

I must say this is one of the best forums I've ever used.

Thanks
Dave
Version #:1.6.4 Date 2017/02/17 FPC Version: 3.0.2 and SVN Revision 54278 for i386-win32-win32/win64

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: Strings in VBA in Lazarus Pascal?
« Reply #3 on: April 16, 2018, 05:02:55 pm »
Many thanks, didn't even know WideString existed, but it did the trick.

Are you only working on Windows?

You can also script MS Office apps on Mac:

https://macpgmr.github.io/ObjP/MacAutomationWithPascal.html

Mr.Madguy

  • Sr. Member
  • ****
  • Posts: 390
Re: Strings in VBA in Lazarus Pascal?
« Reply #4 on: April 16, 2018, 05:51:37 pm »
Unfortunately FPC/Lazarus has constant problems with wide strings. I have to use clunky constructions like this in order to solve this problem:
Code: Pascal  [Select]
  1. Document := WordObject.Documents.Open(WideString(UTF8Decode(GetCurrentDir + '\Data\Source.dat')));
  2.  
DynamicData 2.0 Released! Many optimizations: 15% smaller sources, 10% smaller code! Improved scalability!
Developing version 2.1.
Crazy unit testing

Thaddy

  • Hero Member
  • *****
  • Posts: 7178
Re: Strings in VBA in Lazarus Pascal?
« Reply #5 on: April 16, 2018, 06:23:41 pm »
Shouldn't that be
Code: Pascal  [Select]
  1. Document := WordObject.Documents.Open(PWideChar(ExludeTrailingPathDelimiter(GetCurrentDir) + '\Data\Source.dat'));
Not tested.
inline variables like in D10.3 are a bit like Brexit: if you are given the wrong information it sounds like a good idea. Every kid loves candy, but it makes you fat and your teeth will disappear.