Author Topic: Calling Application.ReadTextFile from js in App  (Read 1620 times)

lenmerkel

  • Full Member
  • **
  • Posts: 107
  • Don't Panic!
Calling Application.ReadTextFile from js in App
« on: August 11, 2014, 08:46:59 PM »
In an App, I'd like to call the Application.ReadTextFile method from JavaScript, to get the contents of a text sidecar file. I can call it just fine, and it returns a boolean to indicate success/failure of the read. However, even on a successful read, I'm unable to get the content. I suspect this is because the content is attempting to be set in the 2nd argument passed to the ReadTextFile method, and the JavaScript <> IMatch object model handshake isn't being handled for that 2nd argument.

JavaScript sends intrinsic type arguments (like string) by value when calling a function. So, I would not expect this to work (and it doesn't):
Code: [Select]
// Pass in intrinsic string type
var s = "Initial value";
IMatchLib.application().ReadTextFile("C:\\temp\\dummy.txt", s);
alert(s);  // Shows initial value, not text file content
(OK, technically, a JavaScript string is an immutable object, passed by reference - same non-changeable effect as being passed by value).

JavaScript sends object arguments by copy-of-reference. So, I thought that sending in an object reference might do the trick. However, neither of these work either (in all cases, the ReadTextFile returns true - success):
Code: [Select]
// Convert intrinsic string type to object reference
var s = "Initial value";
s = Object(s);
IMatchLib.application().ReadTextFile("C:\\temp\\dummy.txt", s);
alert(s);  // Shows initial value, not text file content
Code: [Select]
// Create explicit String object
var s = new String("Initial value");
IMatchLib.application().ReadTextFile("C:\\temp\\dummy.txt", s);
alert(s);  // Shows initial value, not text file content

Any ideas, anyone?
« Last Edit: August 12, 2014, 02:53:37 AM by lenmerkel »
Over the hill, and enjoying the glide.

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 30082
Re: Calling Application.ReadTextFile from js in App
« Reply #1 on: March 23, 2015, 11:50:50 AM »
You can use the JavaScript FileReader class for this. See the Web for examples.