Recent

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

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
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.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

Phil

  • Hero Member
  • *****
  • Posts: 2737
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

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
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.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

Phil

  • Hero Member
  • *****
  • Posts: 2737
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

  • Hero Member
  • *****
  • Posts: 844
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.  
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
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.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018