在持久性程序功能中打开STREAM [英] Opening a STREAM in a Persistent Procedure Function
问题描述
我有一个持久性过程,我试图在其中打开,写入和关闭流.
I have a persistent procedure, in which I am trying to open, write and close a stream.
我在程序的主要区域
DEFINE STREAM sOutFile.
OPEN STREAM sOutFile TO VALUE( outFileName ).
MESSAGE SEEK( sOutFile ).
,然后是持久性过程中的功能
and subsequently a function within the persistent procedure
FUNCTION example RETURN LOGICAL:
MESSAGE SEEK( sOutFile ).
PUT STREAM sOutFile UNFORMATTED someData.
END.
实例化持久性过程时,消息显示为"0",因此流已打开.但是,在调用example时,消息显示为?"并收到一条有关尝试写入封闭流的消息.
When the persistent procedure is instantiated, the message displays "0" so the stream has been opened. However, when example is called, the message displays "?" and I get a message about attempting to write to a closed stream.
我尝试声明流为"NEW SHARED"(新共享),但这没有任何区别.
I've tried declaring the stream NEW SHARED but that didn't make any difference.
我做错什么了吗,还是不可能在持久性过程中定义流?
Am I doing something wrong, or is it impossible to define streams within persistent procedures?
推荐答案
现在还很早,我的咖啡还没有加入,但是我认为您必须在PP体外打开水流.
It is early and my coffee hasn't kicked in yet but I think that you have to open the stream outside the body of the PP.
这有效:
/* ppstream.p
*
*/
define stream logStream.
session:add-super-procedure( this-procedure ).
/* end of PP init */
function initLog returns logical ( input lgFile as character ):
output stream logStream to value( lgFile ) unbuffered.
return true.
end.
function logStuff returns logical ( input msg as character ):
put stream logStream unformatted msg skip.
return true.
end.
,然后这样称呼它:
function initLog returns logical ( input lgFile as character ) in super.
function logStuff returns logical ( input msg as character ) in super.
run ./ppstream.p persistent.
initLog( "log.txt" ).
logStuff( "test" ).
(我使用了会话超级过程来避免必须定义句柄-您不一定需要这样做.)
(I used a session super-procedure to avoid having to define handles -- you would not necessarily need to do that.)
这篇关于在持久性程序功能中打开STREAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!