如何从 Visual FoxPro 9 OLEPUBLIC 类返回数组?
作为 FoxPro 的新手(但是是 Clipper 的老手),我有点不知如何从以下 OLEPUBLIC 类返回数组。 编辑:我修改了下面的代码,以考虑下面 @Stuart 的评论。
DEFINE CLASS db AS CUSTOM OLEPUBLIC
DIMENSION ada(1) && public scope for later return
FUNCTION opendb( cpName )
SET MULTILOCKS ON
USE (cpName) EXCLUSIVE NOUPDATE
= CURSORSETPROP("Buffering",5)
RETURN ALIAS()
ENDFUNC
&& etc
FUNCTION getrecord( sAlias, nRecno )
SELECT (sAlias)
GOTO (nRecno)
fc = FCOUNT()
DIMENSION this.ada(fc)
FOR i = 1 TO fc
STORE CURVAL(FIELD(i)) to THIS.ada(i)
ENDFOR
RETURN @THIS.ada
ENDFUNC
ENDDEFINE
给定以下 VBScript 代码,我可以很好地打开该文件。 我似乎无法做的是返回任何比错误消息更有用的东西。
set sp = createobject("sloop.db")
al = sp.opendb("p:\testing\sloop\patient.dbf")
wscript.echo sp.getrecord(al,1)
这是错误消息:
c:\temp\foo.vbs(3, 1) sloop.db sloop.db: .getrecord p:\testing\sloop\sloop.prg 第 41 行错误 语法错误。 200
第 41 行,事实证明,是
<前><代码>返回@THIS.ada
这真的很奇怪,因为这是微软建议的语法。 有什么线索吗?
As a newbie to FoxPro (but an old-hand at Clipper), I'm a bit at a loss to figure out how to return an array from the following OLEPUBLIC class. edit: I've modified the code belw to take into consideration the remarks made by @Stuart below.
DEFINE CLASS db AS CUSTOM OLEPUBLIC
DIMENSION ada(1) && public scope for later return
FUNCTION opendb( cpName )
SET MULTILOCKS ON
USE (cpName) EXCLUSIVE NOUPDATE
= CURSORSETPROP("Buffering",5)
RETURN ALIAS()
ENDFUNC
&& etc
FUNCTION getrecord( sAlias, nRecno )
SELECT (sAlias)
GOTO (nRecno)
fc = FCOUNT()
DIMENSION this.ada(fc)
FOR i = 1 TO fc
STORE CURVAL(FIELD(i)) to THIS.ada(i)
ENDFOR
RETURN @THIS.ada
ENDFUNC
ENDDEFINE
Given the following bit of VBScript, I can open the file fine. What I can't seem to do is get back anything more useful than an error message.
set sp = createobject("sloop.db")
al = sp.opendb("p:\testing\sloop\patient.dbf")
wscript.echo sp.getrecord(al,1)
This is the error message:
c:\temp\foo.vbs(3, 1) sloop.db sloop.db: .getrecord p:\testing\sloop\sloop.prg Error in line 41 Syntax error. 200
Line 41, as it turns out, is
RETURN @THIS.ada
which is really weird as that's the syntax that Microsoft suggests. Any clues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
(晚了 5 年,但也许对那里的人仍然有用......)
更好的选择是让您的 VFP 代码创建一个 Collection 对象,然后解析数组并将所有元素添加到集合中(使用 .Add () 方法)。 然后您可以将集合对象传递回 VB,然后 VB 就可以愉快地使用它了。
(5 years late, but perhaps still useful to someone out there...)
A better option would be to have your VFP code create a Collection object instead, then parse the array and add all the elements to the collection (using the .Add() method). Then you can pass the collection object back to VB, which is then happy to play with it.
尝试“return @ada”,但 VFP 数组从未与其他语言很好地配合,尽管 尝试让他们这样做。
Try 'return @ada', but VFP arrays have never played nicely with other languages despite attempts to make them do so.
您修改后的代码在 VFP9SP2 中适用于我 - 我必须构建为 EXE,但设法从 VBSCript 访问数据。
这是我的 VBScript 代码:
Your revised code works for me in VFP9SP2 - I had to build as an EXE but managed to access data from VBSCript.
This was my VBScript code: