zoukankan      html  css  js  c++  java
  • (原创) Delphi中LiveBinding 绑定非数据库类数据的时候显示字段自定义名称(补充)

    测试的时候又碰到一个小问题,不绑定不显示的域(但是这些域又必须存在于Entity类中,比如ID域等)。

    简单修改就可以实现,Entity增加一个Attribute,比如FieldNoLink,标记此属性不绑定;AddFields方法也修改下,把默认的FieldList 中的不绑定域去除。

    代码:

      //Not Link
      JkFieldNoLink = class(TJkBindAttribute);
    
    procedure TJkObjectBindSourceAdapter<T>.AddFields;
    var
      LType: TRttiType;
      //LFields: TArray<TRttiField>;
      //LField: TRttiField;
      LProps: TArray<TRttiProperty>;
      LProp: TRttiProperty;
      LAttrs: TArray<TCustomAttribute>;
      Lattr: TCustomAttribute;
      LRemoveField: TBindSourceAdapterField;
    begin
      inherited;
    
      LRemoveField := nil;
      CreateList;
    
      LType := GetObjectType;  
    
    // 规定要显示的数据域全部是Published的属性
    
      LProps := LType.GetProperties;
      for LProp in LProps do
      begin
        if LProp.Visibility = TMemberVisibility.mvPublished then
        begin
          LAttrs := LProp.GetAttributes;
          for Lattr in LAttrs do
          begin
            //No Link
            if Lattr is JkFieldNoLink then
            begin
              LRemoveField := Self.FindField(LProp.Name);
              if Assigned(LRemoveField) then
              begin
                Self.Fields.Remove(LRemoveField);
              end;
            end
            else
            //DisplayName
            begin
              if (Lattr is JkFieldLabel) and (not JkFieldLabel(Lattr).Name.IsEmpty) then
              begin
                FFieldLabelList.AddOrSetValue(LProp.Name, JkFieldLabel(Lattr).Name);
              end
              else if FFieldLabelList.ContainsKey(LProp.Name) then
              begin
                FFieldLabelList.Remove(LProp.Name);
              end;
            end;
          end;
        end;
      end;
    end;
    

    TJkListBindSourceAdapter<T>.AddFields;也做同样的修改,OK

  • 相关阅读:
    10年后编程还有意义吗?
    专访Jeffrey Richter:Windows 8是微软的重中之重
    x86汇编指令脚本虚拟机
    基于容器的持续交付管道
    NET Core 整合Autofac和Castle
    数据结构与算法1
    Redis集群
    react + iscroll5
    MongoDB
    WebComponent
  • 原文地址:https://www.cnblogs.com/jankerxp/p/13674700.html
Copyright © 2011-2022 走看看