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

📄 wwdbgrid.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 5 页
字号:
       begin
         inherited DataLineColor:= sel;
         LayoutChanged;
       end
    end;
}
    procedure TwwDBGrid.SetScrollBars(scrollVal: TScrollStyle);
    begin
      ScrollBars:= scrollVal;
    end;

procedure TwwDBGrid.RedrawGrid;
var i: integer;
    haveCalculatedField: boolean;
//    form: TComponent;
begin
   if redrawingGrid then exit;
   if Selected = Nil then exit;
   if (dataSource=Nil) then exit;
   if (dataSource.dataSet=Nil) then exit;
   if not (wwDataSet(DataSource.dataSet)) then
   begin
      MessageDlg('wwGrid must use an InfoPower compatible TDataSet.',
          mtInformation, [mbok], 0);
      DataSource := Nil;
      exit;
   end;

   ResetProportionalWidths;

   if dgProportionalColResize in Options then
      LayoutChanged;  // resets number of columns

   InitControls;

   try
      dataSource.dataSet.disableControls;
      CurrentCustomEdit:= nil;  { 4/9/98 - Clear currentcustomedit when table is made active }
      if ControlInfoInDataSet then
         with datasource do
            wwDataSetRemoveObsolete(dataset,
               wwGetLookupFields(dataset), wwGetLookupLinks(dataset),
                wwGetControlType(dataSet));
//      if ecoSearchOwnerForm in FEditControlOptions then form:= wwGetOwnerFrameOrForm(self)
//      if ecoSearchOwnerForm in FEditControlOptions then form:= wwGetOwnerForm(self)
//      else form:= GetParentForm(self) as TCustomForm; { -ksw (6/22/98) }

//      if ControlInfoInDataSet then
//         wwDataSetRemoveObsoleteControls(form, datasource.dataset);

      redrawingGrid:= True;

      { If no selection then don't override }
      { If running program and have calculated field then don't change visibility }
      if selected.Count>0 then begin
         haveCalculatedField:= False;
         for i:= 0 to dataSource.dataSet.fieldCount-1 do begin
            if (datasource.dataset.fields[i].calculated) then
               haveCalculatedField:= True;
         end;

         if (csDesigning in ComponentState) or (not haveCalculatedField) then
         begin
            ApplySelected;
         end;

      end;

      {InitControls could change row height so update }
      if (csDesigning in ComponentState) then
      begin
         if useTFields then updateSelectedProperty;
         UpdateRowCount;
      end;


   finally
      dataSource.dataSet.enableControls;
      redrawingGrid:= False;
      initialized:= True;
   end;
end;


procedure TwwDBGrid.LinkActive(value: boolean);
begin
   inLinkActive:= True;

   if csDestroying in ComponentState then        {9/30/99 - Added to save when using datamodule}
      if FIniAttributes.Enabled then SaveToIniFile;

   if (FDateTimePicker<>Nil) then begin
      wwSetControlDataField(FDateTimePicker, ''); {8/5/98 }
   end;
   inherited linkActive(value);
   if value then
   begin
      redrawGrid;
   end;
   inLinkActive:= False;
end;

{ Don't allow insertion of record to cancel if combo is showing. }
Function TwwDBGrid.AllowCancelOnExit: boolean;
begin
   result:= True;
end;

procedure TwwDBGrid.DoExportSYLKFormat(Grid:TwwDBGrid; AField:TField; var SYLKFormat:String);
begin
  if Assigned(FOnExportSYLKFormat) then FOnExportSYLKFormat(self, AField, SYLKFormat);
end;

procedure TwwDBGrid.DoExportField(Grid:TwwDBGrid; AField:TField; var Accept:Boolean);
begin
  if Assigned(FOnExportField) then FOnExportField(self, AField, Accept);
end;

procedure TwwDBGrid.DoExit;
begin
   HideControls;
   HideEditor;
   inherited doExit;
end;

  procedure TwwDBGrid.UpdateSelectedProperty;
  var pf: TCustomForm;
  begin
    if redrawingGrid then exit;
    if Selected = Nil then exit;
    if dataSource=Nil then exit;
    if dataSource.dataSet = Nil then exit;

    if (initialized) then begin
       pf := GetParentForm(self);
       if pf=nil then exit;

       with pf do begin
          if (Designer<>Nil) then begin
             wwDataSetUpdateSelected(datasource.dataset, selected);
          end;
       end;
    end;
  end;

  procedure TwwDBGrid.ApplySelected;
  begin
    if Selected = Nil then exit;

    // Reset OrigColWidths
    ResetProportionalWidths;

    if UseTFields then begin
       if dataSource=Nil then exit;
       if dataSource.dataSet = Nil then exit;
       wwDataSetUpdateFieldProperties(dataSource.dataSet,  selected);
       if selected.count>0 then
          LayoutChanged;  // 4/8/01 - If selected was changed, we need to refresh in
                          // case scrollbars disappear - Otherwise rowcount is 1 too small
    end
    else begin
       RefreshDisplay;
    end;

    RefreshActiveControl; { 2/19/00 - Update control information }
  end;


procedure TwwDBGrid.AdjustLeftCol;
var i: Integer;
begin
   if (inherited FixedCols<> FFixedCols+xIndicatorOffset) and
      (datasource<>Nil) and (datasource.dataset<>nil) and
      (datasource.dataset.active) then
   begin
      if (FFixedCols+xIndicatorOffset<ColCount) and (FFixedCols>=0) then
      begin
         inherited FixedCols:= FFixedCols + xIndicatorOffset;
         if (dgFixedEditable in Options) and (LeftCol=inherited FixedCols) then
            SelectedIndex:= 0;

         for i:= 0 to FFixedCols+xIndicatorOffset do TabStops[i]:= False;
      end
   end;
end;

procedure TwwDBGrid.SetColumnAttributes;
var i: integer;
    customEdit: TWinControl;
    ControlType, Parameters: wwSmallString;
begin
  if useTFields and (not inLinkActive) then
     updateSelectedProperty;

   { Update fixed columns if changed }
   AdjustLeftCol;
{   if (inherited FixedCols<> FFixedCols+xIndicatorOffset) and
      (datasource<>Nil) and (datasource.dataset<>nil) and
      (datasource.dataset.active) then
   begin
      if (FFixedCols+xIndicatorOffset<ColCount) and (FFixedCols>=0) then
      begin
         inherited FixedCols:= FFixedCols + xIndicatorOffset;
         if (dgFixedEditable in Options) and (LeftCol=inherited FixedCols) then
            SelectedIndex:= 0;

         for i:= 0 to FFixedCols+xIndicatorOffset do TabStops[i]:= False;
      end
   end;
}
  inherited setColumnAttributes;

  { Enable tabstops for calculated columns with a lookup control attached to it }
  if not DataLink.active then exit;

  for I := 0 to FieldCount - 1 do begin
    with Fields[I] do
       if Calculated then begin
          if isCustomEditCell(i+xIndicatorOffset, 1, customEdit) then
          begin
             TabStops[I + xIndicatorOffset] := True
          end
          else if isSelectedCheckbox(i+xIndicatorOffset) then
          begin
             TabStops[I + xIndicatorOffset] := True;
          end
          else begin
             GetControlInfo(FieldName,
                    ControlType, Parameters);
             if (ControlType = 'Bitmap') or
                (ControlType = 'ImageIndex') then TabStops[I + xIndicatorOffset] := True;
          end
       end
  end;

  RefreshActiveControl;  // 1/30/01 - Need to call or first column can have problems if datetime field
end;
{
Function TwwDBGrid.IsSelectedCheckbox(ACol: integer): boolean;
var tempField: TField;
begin
    if isCheckBox(ACol, 1, dummy1, dummy2) then
    begin
       tempField:=GetColField(dbCol(ACol));
       if tempField=nil then result:= False
       else result:= (lowercase(tempField.fieldName)='selected');
    end
    else result:= False;
end;
}
function TwwDBGrid.MouseCoord(X, Y: Integer): TGridCoord;
{$ifdef wwdelphi4up}
var Loc: TRect;
    i:Integer;
{$endif}
begin
   result:= inherited MouseCoord(X,Y);

   {$ifdef wwdelphi4up}  { 10/27/98 }
   if UseRightToLeftAlignment and (FixedCols>0) then
   begin
      for i:= 0 to ColCount-1 do begin
         Loc:= CellRect(i, result.y);
         if loc.left<x then
         begin
            result.x:= i;
            break;
         end
      end
   end;
   {$endif}
end;

procedure TwwDBGrid.HideControls;
var TriedToSetFocus: boolean;
begin
   if (currentCustomEdit<>Nil) and currentCustomEdit.visible and
      (currentCustomEdit.parent=self) then  { 5/1/97 - Only hide if grid is parent of control }
   begin
      TriedToSetFocus:=false;
      if (currentCustomEdit.focused) or
         (GetParent(GetFocus)=currentCustomEdit.handle) then  // i.e. inplaceeditor of datainspector
      begin
         currentcustomedit.left:= clientwidth+10;
         TriedToSetFocus:=True;
         setFocus;
      end
      else if (screen.activecontrol<>nil) and
         (screen.activecontrol.parent=currentcustomedit) then
      begin
         currentcustomedit.left:= clientwidth+10;
         TriedToSetFocus:=True;
         setFocus;
      end;

      // 4/16/2002 - If an exception is raised in the onvalidate event of the tfield for a custom control
      // then the focus could still be the custom edit and this means the grid failed to
      // get focus and thus currentcustomedit should not be set to not visible.
      // 2/20/05 - Check currentCustomEdit for nil
      if Focused or (not TriedToSetFocus) and (currentCustomEdit<>nil) then
      begin
        SkipErase:= True;
        currentCustomEdit.visible:= False;
        SkipErase:= False;
      end
      else sysutils.abort; // Fail to set the focus so an exception was likely thrown, don't hide control
   end
end;

function TwwDBGrid.IsActiveControl: Boolean;
var
  H: Hwnd;
  ParentForm: TCustomForm;
begin
  Result := False;
  ParentForm := GetParentForm(Self);
  if Assigned(ParentForm) then
  begin
    if (ParentForm.ActiveControl = Self) then
      Result := True
  end
  else
  begin
    H := GetFocus;
    while IsWindow(H) and (Result = False) do
    begin
      if H = WindowHandle then
        Result := True
      else
        H := GetParent(H);
    end;
  end;
end;

Procedure TwwDBGrid.Paint;
var
   tempFldName: string;
   index: integer;
begin
   RefreshBookmarkList;

   if not ShowVertScrollBar then SetScrollRange(Self.Handle, SB_VERT, 0, 0, False);

   { combo field has disappeared so hide combo control }
   if (currentCustomEdit<>Nil) and currentCustomEdit.visible and
      (datasource<>Nil) and (datasource.dataset<>nil) and
      (datasource.dataset.active) then
   begin
       tempFldName:= wwGetControlDataField(currentCustomEdit);
       if tempFldName<>'' then begin
         if useTFields then begin
            if (datasource.dataset.findField(tempFldName)=Nil) or
               not dataSource.dataSet.fieldByName(tempFldName).visible then
                  HideControls;
         end
         else begin
            if not wwFindSelected(Selected, tempFldName, index) then
                HideControls;
         end
       end
   end;
   MakeCustomControlVisible:= False;

   inherited paint;
//   ShowCurrentControl;
end;

Function TwwDBGrid.CellColor(ACol, ARow: integer): TColor;
begin
   if ACol>FFixedCols then result:= Color
   else result:= TitleColor;

⌨️ 快捷键说明

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