TComponent::CanObserve - C++ Builder

C++ Builder 参考手册 ➙ TComponent ➙ CanObserve


头文件:#include
命名空间:System::Classes
类:TComponent
访问权限:protected:
函数原型:

virtual bool __fastcall CanObserve(const int ID);

System::Classes::TComponent::CanObserve 是 System::Classes::TComponent 的成员函数,返回 LiveBindings 的数据类型 (参数 ID) 是否支持

参数:

ID:以下 LiveBindings 的数据类型值:

  • TObserverMapping::EditLinkID
  • TObserverMapping::EditGridLinkID
  • TObserverMapping::PositionLinkID
  • TObserverMapping::ControlValueID

返回值:

  • 这个控件是否支持参数 ID 数据类型进行 LiveBindings;
  • 这是 LiveBindings 内部调用的函数,不必要直接调用;
  • 在写支持 LiveBindings 的控件时,需要重载这个函数;
  • 以下表格总结了 VCL 和 FMX 控件的 CanObserve 返回值,打勾为支持 (true),未打勾为不支持 (false)。
VCL 控件 ╲ ID EditLinkID EditGridLinkID PositionLinkID ControlValueID
TCustomEdit [√] [ ] [ ] [√]
TCustomCheckBox [√] [ ] [ ] [√]
TDateTimePicker [√] [ ] [ ] [√]
TCustomComboBox [√] [ ] [√] [√]
TCustomListBox [√] [ ] [√] [√]
TCustomListView [√] [ ] [√] [√]
TScrollBar [ ] [ ] [√] [√]
TCustomGrid [ ] [√] [√] [ ]
TImage [√] [ ] [ ] [ ]
FMX 控件 ╲ ID EditLinkID EditGridLinkID PositionLinkID ControlValueID
TCheckBox [√] [ ] [ ] [√]
TCustomSwitch [√] [ ] [ ] [√]
TArcDial [√] [ ] [ ] [√]
TCustomMemo [√] [ ] [ ] [√]
TCustomEdit [√] [ ] [ ] [√]
TCustomDateTimeEdit [√] [ ] [ ] [√]
TColorPanel [√] [ ] [ ] [√]
TComboColorBox [√] [ ] [ ] [√]
TCustomTrack [√] [ ] [√] [√]
TListViewBase [√] [ ] [√] [√]
TCustomListBox [√] [ ] [√] [√]
TCustomComboBox [√] [ ] [√] [√]
TScrollBar [ ] [ ] [√] [ ]
TImageControl [√] [ ] [ ] [ ]
TCustomGrid [ ] [√] [√] [ ]

例子:控件 TObservableTrackBar 支持 EditLinkID 和 ControlValueID

bool __fastcall TObservableTrackBar::CanObserve(const int ID)
{
    switch(ID)
    {
        case TObserverMapping::EditLinkID: // EditLinkID is the observer that is used for control-to-field links
        case TObserverMapping::ControlValueID:
            return true;
        default:
            return false;
    }
}

参考:

  • System::Classes::TComponent::Observers
  • System::Classes::TComponent
  • System::Classes::TPersistent
  • System::TObject
  • VCL 类继承关系

C++ Builder 参考手册 ➙ TComponent ➙ CanObserve

你可能感兴趣的:(TComponent::CanObserve - C++ Builder)