⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wwdbgrid.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      controlType:= GetControlType;
      for i:= 0 to ControlType.count-1 do begin
         strBreakapart(ControlType[i], ';', parts);
         if parts.count<2 then continue;

         if isWWEditControl(parts[1]) or (parts[1]='RichEdit') then begin
            dbLookupComboBox:= GetComponent(parts[2]);
            if (dbLookupComboBox<>Nil) then begin
               if (csDesigning in ComponentState) then continue;
               dbLookupComboBox.visible:= False;
//               if (dblookupcombobox is TwwExpandButton) and
//                  (TwwExpandButton(dblookupcombobox).grid<>nil) then
//                  TwwExpandButton(dblookupcombobox).visible:= false;
               dbLookupComboBox.parent:= self;
               wwSetControlDataSource(dbLookupComboBox, self.dataSource);
               wwSetControlDataField(dbLookupComboBox, parts[0]);

               {  !!!!! Cheating casts to make protected properties public}
               wwSetBoolean(dbLookupComboBox, 'ctl3D', False);
//               TwwDBEdit(dbLookupComboBox).ctl3d:= False;
               TwwDBEdit(dbLookupComboBox).font:= self.font;
               if not wwIsClass(dblookupcombobox.classType, 'TwwDataInspector') then
                  wwSetBorder(dbLookupComboBox, False);
  //                TwwDBEdit(dbLookupComboBox).BorderStyle:= bsNone;

               // Don't support scrollbars for inspector as then text gets cutoff in csPaintCopyState
               // If find way to support csPaintCopy, then we can remove this restriction
               if wwIsClass(dblookupcombobox.classtype, 'TwwDataInspector') then
                  TDrawGrid(dblookupcombobox).ScrollBars:= ssNone;

            end
         end
      end;
   end;

   doneInitControls:= True;
   parts.free;
end;

procedure TwwDBGrid.CMCtl3DChanged(var Message: TMessage);
begin
   if csFramed in ControlStyle then redrawGrid;
end;

procedure TwwDBGrid.ColExit;
begin
   if patch[4]=True then inherited ColExit;

   if not (csDesigning in ComponentState) and
          ((ValidParentForm(Self).ActiveControl = Self) or
           (ValidParentForm(Self).ActiveControl = currentCustomEdit)) then  { Hide customedit }
   begin
      if currentCustomEdit<>Nil then
      begin
         HideControls;
         currentCustomEdit:= nil;
      end
   end;

   if patch[4]=false then inherited colExit;
end;

{ This code necessary to handle when column has changed when the combobox
  has focus }
procedure TwwDBGrid.TopLeftChanged;
var Loc: TRect;
    TempRect: TRect;
   Procedure ResetTopRow(val: integer);
   begin
      inTopLeftChanged:= True;
      TopRow:= val;
      inTopLeftchanged:= False;
   end;
   Procedure ResetLeftcol(val: integer);
   begin
      inTopLeftChanged:= True;
      LeftCol:= val;
//      AdjustLeftCol;
      inTopLeftchanged:= False;
   end;

begin
   if inTopLeftChanged then exit;

   if dgRowSelect in Options then begin { 8/13/96 Fix - Override toprow in case TCustomGrid changed it }
      if (dgTitles in Options) then begin
         if (TopRow<>1) then ResetTopRow(1)
      end
      else if (TopRow<>0) then ResetTopRow(0);
   end;

   if dgFixedEditable in Options then begin
//       ResetLeftCol(3);;
   end;

   inherited TopLeftChanged;

   if (currentCustomEdit<>Nil) then begin
     if currentCustomEdit.visible then begin
        Loc:= CellRect(Col, Row);
        if IsRectEmpty(Loc) then currentCustomEdit.Hide
        else begin
           TempRect:= CellRect(Col, Row);
           if AdjustBoundsRect(CurrentCustomEdit) then
              InflateRect(TempRect, -1,-1);

           if not sameRect(currentCustomEdit.BoundsRect, TempRect) then
           begin
              HideControls;
              Invalidate;
           end
        end
     end
   end;

end;

{ Override so it allows column resizing in design mode even when DefaultFields is True }
procedure TwwDBGrid.CMDesignHitTest(var Msg: TCMDesignHitTest);
var yTitleOffset: integer;
begin
  Msg.Result := Longint(BOOL(Sizing(Msg.Pos.X, Msg.Pos.Y)));

  if dgTitles in Options then yTitleOffset:= 1
  else yTitleOffset:= 0;

  if Msg.Result = 0 then
    with MouseCoord(Msg.Pos.X, Msg.Pos.Y) do
      if (X >= xIndicatorOffset) and (Y < yTitleOffset) then Msg.Result := 1;

  if (Msg.Result = 1) and ((DataLink = nil) or
    not DataLink.Active) then
    Msg.Result := 0;
end;

procedure TwwDBGrid.SelectRecordRange(bkmrk1, bkmrk2: TBookmark);
var
   curBookmark: Tbookmark;
   res: CmpBkmkRslt;
   ScrollCount, currentrow, moveByCount: integer;
   accept: boolean;
   index: integer;

   Function LessThan(bookmark1, bookmark2: TBookmark): boolean;
   begin
       res:= wwDataSetCompareBookmarks(DataSource.DataSet, bookmark1, bookmark2);
{       dbiCompareBookmarks((datasource.dataset as TDBDataSet).handle, bookmark1, bookmark2, res);}
       if CompareBookmarksAltMethod then
          result:= integer(res)<0
       else
          result:= integer(res)=CmpLESS;
   end;

begin
   if (bkmrk1=nil) or (bkmrk2=nil) then exit; { 6/11/98 Invalid bookmarks so exit }

   with DataLink.Dataset do begin
      currentRow:= GetActiveRow;

      DisableControls;

     try

      if Lessthan(bkmrk1, bkmrk2) then
      begin
         RemoveSelected(bkmrk1, bkmrk2); { Remove all selected records in range before selecting}
         curBookmark:= GetBookmark;

         { 3/17/99 - Fire event }
         accept:= True;
         if Assigned(FOnSelectRecord) then FOnSelectRecord(self, True, Accept);

         // 11/16/03
         if patch[9]=False then
         begin
           if accept then begin
              if not Find(self, curBookmark, Index) then
                 bookmarks.Insert(Index, curBookmark)
           end;
         end
         else begin
           if accept then bookmarks.add(curBookmark);
         end;

         while Lessthan(curBookmark, bkmrk2) do
         begin
            Next;
            if Eof then break;
            curBookmark:= GetBookmark;

            { 3/17/99 - Fire event }
            accept:= True;
            if Assigned(FOnSelectRecord) then FOnSelectRecord(self, True, Accept);

            // 11/16/03
            if patch[9]=False then
            begin
              if accept then begin
                 if not Find(self, curBookmark, Index) then
                    bookmarks.Insert(Index, curBookmark)
              end;
            end
            else begin
               if accept then bookmarks.add(curBookmark);
            end;

         end;
         Gotobookmark(bkmrk1);
      end
      else try  {12/02/97 - Added try block on gotobookmark to catch exception when bkmrk2 is invalid}
         Gotobookmark(bkmrk2);
         RemoveSelected(bkmrk2, bkmrk1); { Remove all selected records in range before selecting}

         curBookmark:= GetBookmark;

         { 3/17/99 - Fire event }
         accept:= True;
         if Assigned(FOnSelectRecord) then FOnSelectRecord(self, True, Accept);
         // 11/16/03
         if Patch[9]=False then
         begin
           if accept then begin
              if not Find(self, curBookmark, Index) then
                 bookmarks.Insert(Index, curBookmark)
           end;
         end
         else begin
           if accept then bookmarks.add(curBookmark);
         end;

         while Lessthan(curBookmark, bkmrk1) do
         begin
            if DataLink.ActiveRecord<VisibleRowCount-1 then
               DataLink.ActiveRecord:= DataLink.ActiveRecord + 1
            else begin
               Next;
               if Eof then break;
            end;

            curBookmark:= GetBookmark;

            { 3/17/99 - Fire event }
            accept:= True;
            if Assigned(FOnSelectRecord) then FOnSelectRecord(self, True, Accept);
            // 11/16/03
            if Patch[9]=False then
            begin
              if accept then begin
                 if not Find(self, curBookmark, Index) then
                    bookmarks.Insert(Index, curBookmark)
              end;
            end
            else begin
                if accept then bookmarks.add(curBookmark);
            end;
         end
         except
      end;

      Freebookmark(bkmrk1);
     finally
      EnableControls;       { Updates display controls }
     end;

     try
      DisableControls;      { Disable them during setting of active row }

      { Maintain current row so grid doesn't jump}
      if GetActiveRow<currentRow then
      begin
         ScrollCount:= CurrentRow-GetActiveRow;
         MoveByCount:= -(GetActiveRow + ScrollCount);
         if MoveByCount<>0 then begin
            MoveBy(MoveByCount);
            SetActiveRow(CurrentRow);
         end;
      end
      else begin
         ScrollCount:= GetActiveRow-currentRow;
         MoveByCount:= ((VisibleRowCount-1)-GetActiveRow) + ScrollCount;
         If MoveByCount<>0 then begin
            MoveBy(MoveByCount);
            SetActiveRow(CurrentRow);
         end;
      end;
     finally
      EnableControls;
     end
   end;
end;

procedure TwwDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
var
  DrawInfo: TGridDrawInfo;
  NewSize: Integer;

  function ResizeLine(const AxisInfo: TGridAxisDrawInfo): Integer;
  var
    I: Integer;
  begin
    with AxisInfo do
    begin
      Result := 0; //FixedBoundary;
      for I := 0 to FSizingIndex - 1 do
        Inc(Result, GetExtent(I) + EffectiveLineWidth);
      Result := FSizingPos - Result;
    end;
  end;

begin
  if (dgFixedResizable in Options) and
     (FGridState = gsColSizing) and (FSizingIndex<>-1) then
  begin
//    NewSize:= 0;
    try
      CalcDrawInfo(DrawInfo);
      if UseRightToLeftAlignment then
        FSizingPos := ClientWidth - FSizingPos;
      NewSize := ResizeLine(DrawInfo.Horz);
      if NewSize > 1 then
      begin
        DrawSizingLine(DrawInfo);
        ColWidths[FSizingIndex] := NewSize;
        UpdateDesigner;
      end;
    finally
      // FGridState := gsNormal; // Done in ColWidthsChanged
      FSizingIndex:=-1;
    end
  end;
  inherited MouseUp(Button, Shift, X, Y);
end;

procedure TwwDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
var Coord: TGridCoord;
    lookupControl: TWinControl;
    doubleClicking: boolean;
    TempShiftSelectMode: boolean;
    TempShiftSelectBookmark: TBookmark;
    DrawInfo: TGridDrawInfo;
    FIndicatorOffset: integer;
    ValidCell: boolean;
//    OrigRowOffset: integer;
begin
   { Flush data }
   Coord:= MouseCoord(x,y);
//   OrigRowOffset:= RowOffset;

   if dgIndicator in Options then FIndicatorOffset:=1 else FIndicatorOffset:=0;

   if (dgFixedResizable in Options) or (dgFixedEditable in Options) then
   begin
     CalcDrawInfo(DrawInfo);
     CalcSizingState(X, Y, FGridState, FSizingIndex, FSizingPos, FSizingOfs,
        DrawInfo);
     if FSizingIndex-FIndicatorOffset>=FixedCols then
        FSizingIndex:=-1;
   end;


   TempShiftSelectMode:= ShiftSelectMode;
   TempShiftSelectBookmark:= ShiftSelectBookmark;
   Doubleclicking:= ssDouble in shift;  { save state before calling inherited class }

   inherited MouseDown(Button, shift, x, y);


   if (dgFixedEditable in Options) and (FGridState = gsNormal) and
      (Coord.X >= FIndi

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -