当WSDL导入器向导生成接口时,所有属性都有Index选项,但是读取代码和InvokeRegistry单元,我找不到那个是什么,有人知道它是否真的有必要吗?

喜欢这个

  Login = class(TRemotable)
  private
    [...] 
  published
    property User: string Index (IS_OPTN) read GetUser write SetUser stored User_Specified;
    [...]
  end;

我问,因为我想更改此单元,为这些类添加一些接口,以便与MVP框架集成。

有帮助吗?

解决方案 2

我找到了这个问题的更详细的解释, 使用索引时,多个属性可以共享相同的访问方法。

一个很好的例子,来自Delphi 2009帮助:

type 
   TRectangle = class 
     private 
       FCoordinates: array[0..3] of Longint; 
       function GetCoordinate(Index: Integer): Longint; 
       procedure SetCoordinate(Index: Integer; Value: Longint); 
     public 
       property Left: Longint index 0 read GetCoordinate write SetCoordinate; 
       property Top: Longint index 1 read GetCoordinate write SetCoordinate; 
       property Right: Longint index 2 read GetCoordinate write SetCoordinate; 
       property Bottom: Longint index 3 read GetCoordinate write SetCoordinate; 
       property Coordinates[Index: Integer]: Longint read GetCoordinate write SetCoordinate; 
       ... 
   end;

注意,所有属性都共享相同的方法访问权。

其他提示

当您访问用户属性时,IS_OPTN通过'Index'参数传递给GetUser和SetUser。

getter / setter可能看起来像这样:

function GetUser(Index:Integer):String;
procedure SetUser(Index:Integer;const value:string);

所以,想一想:

MyString := MyLogin.user;
// is translated to:
MyString := getUser(IS_OPTN);

MyLogin.user := 'me'; 
// is translated to:
SetUser(IS_OPTN,'me');

是的,这是必要的。有了这些信息,例如,对于例如IS_OPTN,来自TRemotable的类知道当属性是可选的以构建XML时,因此如果是可选的,则仅在存储值时才添加节点。在你的情况下:

property User: string Index (IS_OPTN) read GetUser write SetUser stored User_Specified

如果 User_Specified 为true,则会在XML上添加元素 User 。将值设置为User时, User_Specified 会自动变为true,因为setter SetUser会这样做。

因此,当组件SOAP por示例将构建XML时,只有在存储元素时才会添加该元素,因为它是Optional(IS_OPTN)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top