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

📄 wzgrid.pas

📁 delphi控件的使用
💻 PAS
📖 第 1 页 / 共 4 页
字号:
end;

//
//
//
constructor TColumn.Create(Collection: TCollection);
var
  Grid: TWzGrid;
begin
  Grid := nil;
  if Assigned(Collection) and (Collection is TWzGridColumns) then
    Grid := TWzGridColumns(Collection).Grid;
  if Assigned(Grid) then Grid.BeginLayout;
  try
    inherited Create(Collection);
    FDropDownRows := 7;
    FButtonStyle := cbsAuto;
    FFont := TFont.Create;
    FFont.Assign(DefaultFont);
//    FFont.OnChange := FontChanged;
    FTitle := CreateTitle;
{
    FImeMode := imClose;}
    FOrgIndex := Index;
    FWidth := 10;
//    FMask := '';
    FAutoSelect := TRUE;
{    FDataType := eggStr;
    FSL := 0;
    FSmode := FALSE;
    FDL := 0;}
  finally
    if Assigned(Grid) then Grid.EndLayout;
  end;
end;

procedure TColumn.Assign(Source: TPersistent);
begin
  if Source is TColumn then
  begin
    if Assigned(Collection) then Collection.BeginUpdate;
    try
      RestoreDefaults;
//      FieldName := TColumn(Source).FieldName;
      if cvColor in TColumn(Source).AssignedValues then
        Color := TColumn(Source).Color;
      if cvWidth in TColumn(Source).AssignedValues then
        Width := TColumn(Source).Width;
{      if cvFont in TColumn(Source).AssignedValues then
        Font := TColumn(Source).Font;}
      if cvAlignment in TColumn(Source).AssignedValues then
        Alignment := TColumn(Source).Alignment;
      if cvReadOnly in TColumn(Source).AssignedValues then
        ReadOnly := TColumn(Source).ReadOnly;

{      if cvImeMode in TColumn(Source).AssignedValues then
        ImeMode := TColumn(Source).ImeMode;

      if cvMask in TColumn(Source).AssignedValues then
        Mask := TColumn(Source).Mask;
}
      if cvAutoSelect in TColumn(Source).AssignedValues then
        AutoSelect := TColumn(Source).AutoSelect;
{
      if cvDataType in TColumn(Source).AssignedValues then
        DataType := TColumn(Source).DataType;

      if cvSL in TColumn(Source).AssignedValues then
        SL := TColumn(Source).SL;

      if cvSmode in TColumn(Source).AssignedValues then
        Smode := TColumn(Source).Smode;

      if cvDL in TColumn(Source).AssignedValues then
        DL := TColumn(Source).DL;

      Title := TColumn(Source).Title;
      DropDownRows := TColumn(Source).DropDownRows;
      ButtonStyle := TColumn(Source).ButtonStyle;
      PickList := TColumn(Source).PickList;}
    finally
      if Assigned(Collection) then Collection.EndUpdate;
    end;
  end
  else
    inherited Assign(Source);
end;

//
//
//
constructor TWzGridColumns.Create(Grid: TWzGrid; ColumnClass: TColumnClass);
begin
  inherited Create(ColumnClass);
  FGrid := Grid;
end;

function TWzGridColumns.GetColumn(Index: Integer): TColumn;
begin
  Result := TColumn(inherited Items[Index]);
end;

procedure TWzGridColumns.SetColumn(Index: Integer; Value: TColumn);
begin
  Items[Index].Assign(Value);
end;

function TWzGridColumns.GetOwner: TPersistent;
begin
  Result := FGrid;
end;

function  TWzGridColumns.Add: TColumn;
begin
  Result := TColumn(inherited Add);
end;

procedure TWzGridColumns.Update(Item: TCollectionItem);
var
  Raw,W : Integer;
begin
  if (FGrid = nil) or (csLoading in FGrid.ComponentState) then Exit;
  if Item = nil then begin
    FGrid.LayoutChanged;
  end else begin
    try
      Raw := FGrid.DataToRawColumn(Item.Index);
      FGrid.InvalidateCol(Raw);
      Fgrid.Canvas.Font := Fgrid.Font;
      W := FGrid.Canvas.TextWidth( '0' );
      W := TColumn(Item).Width*W + 4;
      FGrid.ColWidths[Raw] := W;
    finally
      FGrid.LayoutChanged;
    end;
  end;
end;

//
//
//
function  TColumn.GetColor: TColor;
begin
  if cvColor in FAssignedValues then
    Result := FColor
  else
    Result := DefaultColor;
end;

procedure TColumn.SetColor(Value: TColor);
begin
  if (cvColor in FAssignedValues) and (Value = FColor) then Exit;
  FColor := Value;
  Include(FAssignedValues, cvColor);
  Changed(False);
end;

function  TColumn.IsColorStored: Boolean;
begin
  Result := (cvColor in FAssignedValues) and (FColor <> DefaultColor);
end;

function TColumn.DefaultColor: TColor;
var
  Grid: TWzGrid;
begin
  Grid := GetGrid;
  if Assigned(Grid) then
    Result := Grid.Color
  else
    Result := clWindow;
end;

function  TColumn.CreateTitle: TColumnTitle;
begin
  Result := TColumnTitle.Create(Self);
end;

function TColumn.GetGrid: TWzGrid;
begin
  if Assigned(Collection) and (Collection is TWzGridColumns) then
    Result := TWzGridColumns(Collection).Grid
  else
    Result := nil;
end;

function  TColumn.DefaultFont: TFont;
var
  Grid: TWzGrid;
begin
  Grid := GetGrid;
  if Assigned(Grid) then
    Result := Grid.Font
  else
    Result := FFont;
end;

function TColumn.GetReadOnly: Boolean;
begin
  if cvReadOnly in FAssignedValues then
    Result := FReadOnly
  else
    Result := DefaultReadOnly;
end;

function  TColumn.IsReadOnlyStored: Boolean;
begin
  Result := (cvReadOnly in FAssignedValues) and (FReadOnly <> DefaultReadOnly);
end;

procedure TColumn.SetReadOnly(Value: Boolean);
begin
  if (cvReadOnly in FAssignedValues) and (Value = FReadOnly) then Exit;
  FReadOnly := Value;
  Include(FAssignedValues, cvReadOnly);
  Changed(False);
end;

function TColumn.DefaultReadOnly: Boolean;
begin
  Result := False;
end;

destructor TColumn.Destroy;
begin
  FTitle.Free;
  FFont.Free;
//  FPickList.Free;
  inherited Destroy;
end;

function TColumn.GetWidth: Integer;
begin
  if cvWidth in FAssignedValues then
    Result := FWidth
  else
    Result := DefaultWidth;
end;

function TColumn.IsWidthStored: Boolean;
begin
  Result := (cvWidth in FAssignedValues) and (FWidth <> DefaultWidth);
end;

procedure TColumn.SetTitle(Value: TColumnTitle);
begin
  FTitle.Assign(Value);
end;

procedure TColumn.SetWidth(Value: Integer);
begin
  if (cvWidth in FAssignedValues) or (Value <> DefaultWidth) then begin
    FWidth := Value;
    Include(FAssignedValues, cvWidth);
  end;
  Changed(False);
end;

function TColumn.DefaultWidth: Integer;
begin
  Result := 10;
end;

procedure TColumn.RestoreDefaults;
var
  FontAssigned: Boolean;
begin
  FontAssigned := cvFont in FAssignedValues;
  FTitle.RestoreDefaults;
  FAssignedValues := [];
//  RefreshDefaultFont;
//  FPickList.Free;
//  FPickList := nil;
//  ButtonStyle := cbsAuto;
  Changed(FontAssigned);
end;

function  TColumn.GetAutoSelect: boolean;
begin
  if cvAutoSelect in FAssignedValues then
    Result := FAutoSelect
  else
    Result := DefaultAutoSelect;
end;

procedure TColumn.SetAutoSelect(Value: boolean);
begin
  if (cvAutoSelect in FAssignedValues) or (Value <> DefaultAutoSelect) then begin
    FAutoSelect := Value;
    Include(FAssignedValues, cvAutoSelect);
  end;
  Changed(False);
end;

function  TColumn.IsAutoSelectStored: Boolean;
begin
  Result := (cvAutoSelect in FAssignedValues) and (FAutoSelect <> DefaultAutoSelect);
end;

function  TColumn.DefaultAutoSelect: boolean;
begin
  Result := TRUE;
end;

function  TColumn.GetAlignment: TAlignment;
begin
  if cvAlignment in FAssignedValues then
    Result := FAlignment
  else
    Result := DefaultAlignment;
end;

function  TColumn.IsAlignmentStored: Boolean;
begin
  Result := (cvAlignment in FAssignedValues) and (FAlignment <> DefaultAlignment);
end;

procedure TColumn.SetAlignment(Value: TAlignment);
begin
  if (cvAlignment in FAssignedValues) and (Value = FAlignment) then Exit;
  FAlignment := Value;
  Include(FAssignedValues, cvAlignment);
  Changed(False);
end;

procedure TColumn.SetFieldName(Value: String);
begin
  FFieldName := Value;
  Changed(False);
end;

function TColumn.GetOrgIndex : Integer;
var Grid: TWzGrid;
begin
  Grid := GetGrid;
  if  Assigned( Grid )
  and ( csDesigning in Grid.ComponentState ) then
    FOrgIndex := Index;
  Result := FOrgIndex;
end;

procedure TColumn.SetOrgIndex(Value: integer);
var Grid: TWzGrid;
begin
  Grid := GetGrid;
  if  Assigned( Grid )
  and ( csDesigning in Grid.ComponentState ) then
    FOrgIndex := Value;
end;

function  TColumn.DefaultAlignment: TAlignment;
begin
  Result := taLeftJustify;
end;

//
//
//
procedure SelectNextCtrl( CurCtrl: TWinControl; goForward: boolean );
var
  i : integer;
  List : TList;
  Form : TCustomForm;
begin
  Form := GetParentForm(CurCtrl);
  if Form <> nil then begin
    List := TList.Create;
    try
      Form.GetTabOrderList(List);
      if List.Count > 0 then begin
        i := List.IndexOf(CurCtrl);
        if ( i = -1 ) and not goForward then i := List.Count;
        while TRUE do begin
          if goForward then inc(i) else dec(i);
          if not between( i, 0, List.Count-1 ) then break;
          with TWinControl(List.Items[i]) do begin
            if CanFocus and TabStop then begin
              SetFocus;
              break;
            end;
          end;
        end;
      end;
    finally
      List.Free;
    end;
  end;
end;

function between( d, d1,d2 : double ) : boolean;
begin
  Result := ( d >= d1 ) and ( d <= d2 );
end;

function IsActiveControl(Sender : TObject): Boolean;
var
  H: Hwnd;
  ParentForm: TCustomForm;
begin
  Result := False;
  ParentForm := GetParentForm(TControl(Sender));
  if Assigned(ParentForm) then
  begin
    if (ParentForm.ActiveControl = Sender) 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;


end.

⌨️ 快捷键说明

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