• DBGRIDEH保存"显示标题"


    //edit by cxg. 2008-04-19 10:01:52
    //增加保存"显示标题"
    procedure TCustomDBGridEh.SaveColumnsLayoutProducer(ARegIni: TObject; Section:
      String; DeleteSection: Boolean);
    var
      I: Integer;
      S: String;
    begin
      if (ARegIni is TRegIniFile) then
        TRegIniFile(ARegIni).EraseSection(Section)
      else if DeleteSection then
        TCustomIniFile(ARegIni).EraseSection(Section);

      with Columns do
      begin
        for I := 0 to Count - 1 do
        begin
          if ARegIni is TRegIniFile then
            TRegIniFile(ARegIni).WriteString(Section, Format('%s.%s', [Name, Items[I].FieldName]),
              Format('%d,%d,%d,%d,%d,%d,%d,%s', [Items[I].Index, Items[I].Width, Integer(Items[I].Title.SortMarker),
              Integer(Items[I].Visible), Items[I].Title.SortIndex, Items[I].DropDownRows, Items[I].DropDownWidth,Items[I].Title.Caption]))
          {
            TRegIniFile(ARegIni).WriteString(Section, Format('%s.%s', [Name, Items[I].FieldName]),
              Format('%d,%d,%d,%d,%d,%d,%d', [Items[I].Index, Items[I].Width, Integer(Items[I].Title.SortMarker),
              Integer(Items[I].Visible), Items[I].Title.SortIndex, Items[I].DropDownRows, Items[I].DropDownWidth]))
          }
          else
          begin
            S := Format('%d,%d,%d,%d,%d,%d,%d,%s', [Items[I].Index, Items[I].Width, Integer(Items[I].Title.SortMarker),
              Integer(Items[I].Visible), Items[I].Title.SortIndex, Items[I].DropDownRows, Items[I].DropDownWidth,Items[i].Title.Caption]);
          {
            S := Format('%d,%d,%d,%d,%d,%d,%d', [Items[I].Index, Items[I].Width, Integer(Items[I].Title.SortMarker),
              Integer(Items[I].Visible), Items[I].Title.SortIndex, Items[I].DropDownRows, Items[I].DropDownWidth]);
          }
            if S <> '' then
            begin
              if ((S[1] = '"') and (S[Length(S)] = '"')) or
              ((S[1] = '''') and (S[Length(S)] = '''')) then
                S := '"' + S + '"';
            end;
          end;
          if ARegIni is TCustomIniFile
            then TCustomIniFile(ARegIni).WriteString(Section, Format('%s.%s', [Name, Items[I].FieldName]), S);
        end;
      end;
    end;

    //edit by cxg. 2008-04-19 10:02:13
    //增加恢复"显示标题"
    procedure TCustomDBGridEh.RestoreColumnsLayoutProducer(ARegIni: TObject;
      Section: String; RestoreParams: TColumnEhRestoreParams);
    type
      TColumnInfo = record
        Column: TColumnEh;
        EndIndex: Integer;
        SortMarker: TSortMarkerEh;
        SortIndex: Integer;
      end;
      PColumnArray = ^TColumnArray;
      TColumnArray = array[0..0] of TColumnInfo;
    const
      Delims = [' ', ','];
    var
      I, J: Integer;
      S: string;
      ColumnArray: array of TColumnInfo;
      AAutoFitColWidth: Boolean;
    begin
      AAutoFitColWidth := False;
      BeginUpdate;
      try
        if (AutoFitColWidths) then
        begin
          AutoFitColWidths := False;
          AAutoFitColWidth := True;
        end;
        with Columns do
        begin
          SetLength(ColumnArray, Count);
          try
            for I := 0 to Count - 1 do
            begin
              if (ARegIni is TRegIniFile)
                then S := TRegIniFile(ARegIni).ReadString(Section, Format('%s.%s', [Name, Items[I].FieldName]), '')
                else S := TCustomIniFile(ARegIni).ReadString(Section, Format('%s.%s', [Name, Items[I].FieldName]), '');
              ColumnArray[I].Column := Items[I];
              ColumnArray[I].EndIndex := Items[I].Index;
              if S <> '' then
              begin
                ColumnArray[I].EndIndex := StrToIntDef(ExtractWord(1, S, Delims),
                  ColumnArray[I].EndIndex);
                if (crpColWidthsEh in RestoreParams) then
                  Items[I].Width := StrToIntDef(ExtractWord(2, S, Delims),
                    Items[I].Width);
                if (crpSortMarkerEh in RestoreParams) then
                  Items[I].Title.SortMarker := TSortMarkerEh(StrToIntDef(ExtractWord(3, S, Delims),
                    Integer(Items[I].Title.SortMarker)));
                if (crpColVisibleEh in RestoreParams) then
                  Items[I].Visible := Boolean(StrToIntDef(ExtractWord(4, S, Delims), Integer(Items[I].Visible)));
                if (crpSortMarkerEh in RestoreParams) then
                  ColumnArray[I].SortIndex := StrToIntDef(ExtractWord(5, S, Delims), 0);
                if (crpDropDownRowsEh in RestoreParams) then
                  Items[I].DropDownRows := StrToIntDef(ExtractWord(6, S, Delims), Items[I].DropDownRows);
                if (crpDropDownWidthEh in RestoreParams) then
                  Items[I].DropDownWidth := StrToIntDef(ExtractWord(7, S, Delims), Items[I].DropDownWidth);
                Items[I].Title.Caption:=ExtractWord(8, S, Delims);//add by cxg
              end;
            end;
            if (crpSortMarkerEh in RestoreParams) then
              for I := 0 to Count - 1 do
                Items[I].Title.SortIndex := ColumnArray[I].SortIndex;
            if (crpColIndexEh in RestoreParams) then
              for I := 0 to Count - 1 do
                for J := 0 to Count - 1 do
                  if ColumnArray[J].EndIndex = I then
                  begin
                    ColumnArray[J].Column.Index := ColumnArray[J].EndIndex;
                    Break;
                  end;

          finally
            //FreeMem(Pointer(ColumnArray));
            SetLength(ColumnArray, 0);
          end;
        end;
      finally
        EndUpdate;
        if (AAutoFitColWidth = True)
          then AutoFitColWidths := True
          else LayoutChanged;
      end;
    end;
     

  • 相关阅读:
    Vulnhub_DC4 记录
    文件上传(解析)漏洞
    开源情报搜集
    Vulnhub_DC3 记录
    “恶意”利用IPC$
    Vulnhub_DC2 记录
    Vulnhub_DC1 记录
    合天网安实验室 渗透测试项目二
    合天网安实验室 渗透测试项目一
    编程如写作
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940885.html
Copyright © 2020-2023  润新知