解决方案 »
- delphi xe2 序列号谁能告诉我的一下
- 请教Delphi ADO访问Oracle的CLOB字段
- onshow的问题
- dbgrid的问题
- 将SQL数据库中某一个字符型字段的值的第一个字符去掉,应该怎样写SQL语句?
- 怎么使窗体在所有应用程序之前,保持在最顶部
- 请问高手使用什么VCL控件可以解读IP包?谢谢
- 50分的问题:为什么我的sorketconnection总是找不到servername呢?
- 如何解决在保存数据库时出现“查询过于复杂”的错误(ACCESS数据库)
- 特急:请问如何把Button1,Button2...Button9设置为一个数组Button[8]?不够可加分!!
- 请问OFFICE里哪个CHM文件是ACCESS的有关SQL的HELP文件??
- 随机的优先级问题
private
FData: Pointer;
FRows: Pointer;
FCols: Pointer;
FUpdating: Boolean;
FNeedsUpdating: Boolean;
FEditUpdate: Integer;
procedure DisableEditUpdate;
procedure EnableEditUpdate;
procedure Initialize;
procedure Update(ACol, ARow: Integer); reintroduce;
procedure SetUpdateState(Updating: Boolean);
function GetCells(ACol, ARow: Integer): string;
function GetCols(Index: Integer): TStrings;
function GetObjects(ACol, ARow: Integer): TObject;
function GetRows(Index: Integer): TStrings;
procedure SetCells(ACol, ARow: Integer; const Value: string);
procedure SetCols(Index: Integer; Value: TStrings);
procedure SetObjects(ACol, ARow: Integer; Value: TObject);
procedure SetRows(Index: Integer; Value: TStrings);
function EnsureColRow(Index: Integer; IsCol: Boolean): TStringGridStrings;
function EnsureDataRow(ARow: Integer): Pointer;
protected
procedure ColumnMoved(FromIndex, ToIndex: Longint); override;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState); override;
function GetEditText(ACol, ARow: Longint): string; override;
procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
procedure RowMoved(FromIndex, ToIndex: Longint); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Cells[ACol, ARow: Integer]: string read GetCells write SetCells;
property Cols[Index: Integer]: TStrings read GetCols write SetCols;
property Objects[ACol, ARow: Integer]: TObject read GetObjects write SetObjects;
property Rows[Index: Integer]: TStrings read GetRows write SetRows;
end;implementationconstructor TStringGrid.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Initialize;
end;destructor TStringGrid.Destroy;
function FreeItem(TheIndex: Integer; TheItem: Pointer): Integer; far;
begin
TObject(TheItem).Free;
Result := 0;
end;begin
if FRows <> nil then
begin
TSparseList(FRows).ForAll(@FreeItem);
TSparseList(FRows).Free;
end;
if FCols <> nil then
begin
TSparseList(FCols).ForAll(@FreeItem);
TSparseList(FCols).Free;
end;
if FData <> nil then
begin
TSparseList(FData).ForAll(@FreeItem);
TSparseList(FData).Free;
end;
inherited Destroy;
end;procedure TStringGrid.ColumnMoved(FromIndex, ToIndex: Longint); function MoveColData(Index: Integer; ARow: TStringSparseList): Integer; far;
begin
ARow.Move(FromIndex, ToIndex);
Result := 0;
end;begin
TSparseList(FData).ForAll(@MoveColData);
Invalidate;
inherited ColumnMoved(FromIndex, ToIndex);
end;procedure TStringGrid.RowMoved(FromIndex, ToIndex: Longint);
begin
TSparseList(FData).Move(FromIndex, ToIndex);
Invalidate;
inherited RowMoved(FromIndex, ToIndex);
end;function TStringGrid.GetEditText(ACol, ARow: Longint): string;
begin
Result := Cells[ACol, ARow];
if Assigned(FOnGetEditText) then FOnGetEditText(Self, ACol, ARow, Result);
end;procedure TStringGrid.SetEditText(ACol, ARow: Longint; const Value: string);
begin
DisableEditUpdate;
try
if Value <> Cells[ACol, ARow] then Cells[ACol, ARow] := Value;
finally
EnableEditUpdate;
end;
inherited SetEditText(ACol, ARow, Value);
end;procedure TStringGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState);
begin
if DefaultDrawing then
Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+2, Cells[ACol, ARow]);
inherited DrawCell(ACol, ARow, ARect, AState);
end;procedure TStringGrid.DisableEditUpdate;
begin
Inc(FEditUpdate);
end;procedure TStringGrid.EnableEditUpdate;
begin
Dec(FEditUpdate);
end;procedure TStringGrid.Initialize;
var
quantum: TSPAQuantum;
begin
if FCols = nil then
begin
if ColCount > 512 then quantum := SPALarge else quantum := SPASmall;
FCols := TSparseList.Create(quantum);
end;
if RowCount > 256 then quantum := SPALarge else quantum := SPASmall;
if FRows = nil then FRows := TSparseList.Create(quantum);
if FData = nil then FData := TSparseList.Create(quantum);
end;procedure TStringGrid.SetUpdateState(Updating: Boolean);
begin
FUpdating := Updating;
if not Updating and FNeedsUpdating then
begin
InvalidateGrid;
FNeedsUpdating := False;
end;
end;procedure TStringGrid.Update(ACol, ARow: Integer);
begin
if not FUpdating then InvalidateCell(ACol, ARow)
else FNeedsUpdating := True;
if (ACol = Col) and (ARow = Row) and (FEditUpdate = 0) then InvalidateEditor;
end;function TStringGrid.EnsureColRow(Index: Integer; IsCol: Boolean):
TStringGridStrings;
var
RCIndex: Integer;
PList: ^TSparseList;
begin
if IsCol then PList := @FCols else PList := @FRows;
Result := TStringGridStrings(PList^[Index]);
if Result = nil then
begin
if IsCol then RCIndex := -Index - 1 else RCIndex := Index + 1;
Result := TStringGridStrings.Create(Self, RCIndex);
PList^[Index] := Result;
end;
end;function TStringGrid.EnsureDataRow(ARow: Integer): Pointer;
var
quantum: TSPAQuantum;
begin
Result := TStringSparseList(TSparseList(FData)[ARow]);
if Result = nil then
begin
if ColCount > 512 then quantum := SPALarge else quantum := SPASmall;
Result := TStringSparseList.Create(quantum);
TSparseList(FData)[ARow] := Result;
end;
end;function TStringGrid.GetCells(ACol, ARow: Integer): string;
var
ssl: TStringSparseList;
begin
ssl := TStringSparseList(TSparseList(FData)[ARow]);
if ssl = nil then Result := '' else Result := ssl[ACol];
end;function TStringGrid.GetCols(Index: Integer): TStrings;
begin
Result := EnsureColRow(Index, True);
end;function TStringGrid.GetObjects(ACol, ARow: Integer): TObject;
var
ssl: TStringSparseList;
begin
ssl := TStringSparseList(TSparseList(FData)[ARow]);
if ssl = nil then Result := nil else Result := ssl.Objects[ACol];
end;function TStringGrid.GetRows(Index: Integer): TStrings;
begin
Result := EnsureColRow(Index, False);
end;procedure TStringGrid.SetCells(ACol, ARow: Integer; const Value: string);
begin
TStringGridStrings(EnsureDataRow(ARow))[ACol] := Value;
EnsureColRow(ACol, True);
EnsureColRow(ARow, False);
Update(ACol, ARow);
end;procedure TStringGrid.SetCols(Index: Integer; Value: TStrings);
begin
EnsureColRow(Index, True).Assign(Value);
end;procedure TStringGrid.SetObjects(ACol, ARow: Integer; Value: TObject);
begin
TStringGridStrings(EnsureDataRow(ARow)).Objects[ACol] := Value;
EnsureColRow(ACol, True);
EnsureColRow(ARow, False);
Update(ACol, ARow);
end;procedure TStringGrid.SetRows(Index: Integer; Value: TStrings);
begin
EnsureColRow(Index, False).Assign(Value);
end;
别吓着,其实就在这里:[delphi目录]\source\vcl\grids.pas
其中的TStringGrid类
另外我需要的不是一个新类,我只是想对Delphi现有的StirngGrid这个类操作,合并FORM上某一StringGrid指定的Cell而已,可以给出操作代码吗?
Rect: TRect; State: TGridDrawState);
begin
if ((acol=1) and (arow=1)) or ((acol=1) and (arow=2)) then
begin
//showmessage(inttostr(rect.Bottom) + ' ' +inttostr(rect.Top));
rect.Bottom:=rect.Bottom + (rect.Bottom-rect.Top);
//showmessage(inttostr(rect.Bottom) + ' ' +inttostr(rect.Top));
end;
if (not((acol=1) and (arow=2))) or (not((acol=1) and (arow=1))) then
begin
stringgrid1.Canvas.FillRect(Rect);
stringgrid1.canvas.textout(rect.left,rect.top+18,StringGrid1.cells[acol,arow]);
end;
end;