re TDBGridColumns.RebuildColumns; var I: Integer; begin if Assigned(FGrid) and Assigned(FGrid.DataSource) and Assigned(FGrid.Datasource.Dataset) then begin FGrid.BeginLayout; try Clear; with FGrid.Datasource.Dataset do for I := 0 to FieldCount-1 do Add.FieldName := Fields[I].FieldName finally FGrid.EndLayout; end end else Clear; end;
procedure TDBGridColumns.SaveToFile(const Filename: string); var S: TStream; begin S := TFileStream.Create(Filename, fmCreate); try SaveToStream(S); finally S.Free; end; end;
procedure TDBGridColumns.SaveToStream(S: TStream); var Wrapper: TColumnsWrapper; begin Wrapper := TColumnsWrapper.Create(nil); try Wrapper.Columns := Self; S.WriteComponent(Wrapper); finally Wrapper.Free; end; end;
procedure TDBGridColumns.SetColumn(Index: Integer; Value: TColumn); begin Items[Index].Assign(Value); end;
procedure TDBGridColumns.SetState(NewState: TDBGridColumnsState); begin if NewState = State then Exit; if NewState = csDefault then Clear else RebuildColumns; end;
procedure TDBGridColumns.Update(Item: TCollectionItem); var Raw: Integer; begin if (FGrid = nil) or (csLoading in FGrid.ComponentState) then Exit; if Item = nil then begin FGrid.LayoutChanged; end else begin Raw := FGrid.DataToRawColumn(Item.Index); if FGrid.Vertical then begin FGrid.InvalidateRow(Raw); {FGrid.ColWidths[Raw] := TColumn(Item).Width;} end else begin FGrid.InvalidateCol(Raw); FGrid.ColWidths[Raw] := TColumn(Item).Width; end; end; end;
{ TBookmarkList }
constructor TBookmarkList.Create(AGrid: TCustomVDBGrid); begin inherited Create; FList := TStringList.Create; FList.OnChange := StringsChanged; FGrid := AGrid; end;
destructor TBookmarkList.Destroy; begin Clear; FList.Free; inherited Destroy; end;
procedure TBookmarkList.Clear; begin if FList.Count = 0 then Exit; FList.Clear; FGrid.Invalidate; end;
function TBookmarkList.Compare(const Item1, Item2: TBookmarkStr): Integer; begin with FGrid.Datalink.Datasource.Dataset do Result := CompareBookmarks(TBookmark(Item1), TBookmark(Item2)); end;
function TBookmarkList.CurrentRow: TBookmarkStr; begin if not FLinkActive then RaiseGridError(sDataSetClosed); Result := FGrid.Datalink.Datasource.Dataset.Bookmark; end;
function TBookmarkList.GetCurrentRowSelected: Boolean; var Index: Integer; begin Result := Find(CurrentRow, Index); end;
function TBookmarkList.Find(const Item: TBookmarkStr; var Index: Integer): Boolean; var L, H, I, C: Integer; begin if (Item = FCache) and (FCacheIndex >= 0) then begin Index := FCacheIndex; Result := FCacheFind; Exit; end; Result := False; L := 0; H := FList.Count - 1; while L <= H do begin I := (L + H) shr 1; C := Compare(FList[I], Item); if C < 0 then L := I + 1 else begin H := I - 1; if C = 0 then begin Result := True; L := I; end; end; end; Index := L; FCache := Item; FCacheIndex := Index; FCacheFind := Result; end;
function TBookmarkList.GetCount: Integer; begin Result := FList.Count; end;
function TBookmarkList.GetItem(Index: Integer): TBookmarkStr; begin Result := FList[Index]; end;
function TBookmarkList.IndexOf(const Item: TBookmarkStr): Integer; begin if not Find(Item, Result) then Result := -1; end;
procedure TBookmarkList.LinkActive(Value: Boolean); begin Clear; FLinkActive := Value; end;
procedure TBookmarkList.Delete; var I: Integer; begin with FGrid.Datalink.Datasource.Dataset do begin DisableControls; try for I := FList.Count-1 downto 0 do begin Bookmark := FList[I]; Delete; FList.Delete(I); end; finally EnableControls; end; end; end;
function TBookmarkList.Refresh: Boolean; var I: Integer; begin Result := False; with FGrid.DataLink.Datasource.Dataset do try CheckBrowseMode; for I := FList.Count - 1 downto 0 do if not BookmarkValid(TBookmark(FList[I])) then begin Result := True; FList.Delete(I); end; finally UpdateCursorPos; if Result then FGrid.Invalidate; end; end;
procedure TBookmarkList.SetCurrentRowSelected(Value: Boolean); var Index: Integer; Current: TBookmarkStr; begin Current := CurrentRow; if (Length(Current) = 0) or (Find(Current, Index) = Value) then Exit; if Value then FList.Insert(Index, Current) else FList.Delete(Index); FGrid.InvalidateRow(FGrid.Row); end;
procedure TBookmarkList.StringsChanged(Sender: TObject); begin FCache := ''''''''; FCacheIndex := -1; end;
{ TCustomVDBGrid }
var DrawBitmap: TBitmap; UserCount: Integer;
function IIF(expr: Boolean; caseTrue, caseFalse: variant): variant; begin if expr then Result := caseTrue else Result := caseFalse; end;
procedure UsesBitmap; begin if UserCount = 0 then DrawBitmap := TBitmap.Create; Inc(UserCount); end;
procedure ReleaseBitmap; begin Dec(UserCount); if UserCount = 0 then DrawBitmap.Free; end;
function Max(X, Y: Integer): Integer; begin Result := Y; if X > Y then Result := X; end;
procedure WriteText(ACanvas: TCanvas; ARect: TRect; DX, DY: Integer; const Text: string; Alignment: TAlignment); const AlignFlags : array [TAlignment] of Integer = ( DT_LEFT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX, DT_RIGHT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX, DT_CENTER or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX ); var B, R: TRect; I, Left: Integer; begin I := ColorToRGB(ACanvas.Brush.Color); if GetNearestColor(ACanvas.Handle, I) = I then begin { Use ExtTextOut for solid colors } case Alignment of taLeftJustify: Left := ARect.Left + DX; taRightJustify: Left := ARect.Right - ACanvas.TextWidth(Text) - 3; else { taCenter } Left := ARect.Left + (ARect.Right - ARect.Left) shr 1 - (ACanvas.TextWidth(Text) shr 1); end; ExtTextOut(ACanvas.Handle, Left, ARect.Top + DY, ETO_OPAQUE or ETO_CLIPPED, @ARect, PChar(Text), Length(Text), nil); end else begin { Use FillRect and Drawtext for dithered colors } DrawBitmap.Canvas.Lock; try with DrawBitmap, ARect do { Use offscreen bi 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> [聊天工具]让你的MSN Messenger好友看到你在干嘛__天极Yesky [聊天工具]让你的Foxmail不再撒谎 [聊天工具]IncrediMail让你的E-mail也作秀 [常用软件]让你的Blog拥有Google日历 [常用软件][网络]Stuff Plug 让你的MSN聊天与众不同 [Delphi程序]让你的DBGridEh的Column自动适应宽度
|