OBJECT PASCAL的问题(50分)

  • 主题发起人 主题发起人 ReallyFail
  • 开始时间 开始时间
R

ReallyFail

Unregistered / Unconfirmed
GUEST, unregistred user!
用了两年的DELPHI,感觉OBJECT PASCAL中有个OUT关键字,但从来没用过!
那为高人能说说他的用法!
 
OUT 是在定义一个过程 或 函数时 有来定义参数的类型的。
可以返回值,有点等同于 var。
不过是向下兼容以前的pascal吧。
这是我的理解。
欢迎指正
 
还有在做dcom时,好像有用到
 
我是说三层
 
Delphi帮助里说得非常明白了:
An out parameter, like a variable parameter, is passed by reference.
With an out parameter, however, the initial value of the referenced variable
is discarded by the routine it is passed to. The out parameter is for output
only; that is, it tells the function or procedure where to store output, but
doesn't provide any input.
For example, consider the procedure heading
procedure GetInfo(out Info: SomeRecordType);
When you call GetInfo, you must pass it a variable of type SomeRecordType:
var MyRecord: SomeRecordType;
...
GetInfo(MyRecord);
But you're not using MyRecord to pass any data to the GetInfo procedure;
MyRecord is just a container where you want
GetInfo to store the information it generates. The call to GetInfo immediately
frees the memory used by MyRecord, before program control passes to the
procedure.
Out parameters are frequently used with distributed-object models like COM and
CORBA. In addition, you should use
out parameters when you pass an uninitialized variable to a function or
procedure.

跟VAR一样,都是传引用,但它把初始值忽略了,表示这个参数是只用来输出用的
在COM及CORBA应用中用得比较多,你看Delphi自动生成的代码里,就经常用到这个参数
 
多人接受答案了。
 
公司现在做系统用的corba,服务器端写接口函数经常用到out,传出数据到客户端
其他方面的应用我就不清楚了
 
后退
顶部