本来就是用简单的功能实现的,有这种方法的控件只不过是把这些方法封装起来形成一个新控件而已,如果你有他的源码,去看一下就明白了
没什么神奇的
下面这个是封装后的stringgrid
ttestsg=class(TStringGrid)
public
Constructor Create(AOwner: TComponent);override;
Destructor Destroy;override;
protected
procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
end;
constructor ttestsg.Create(AOwner: TComponent);
var
i,j:integer;
begin
inherited Create(AOwner);
Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing];
RowCount:=5;
ColCount:=5;
FixedCols:=1;
FixedRows:=1;
Cells[1,0]:='S';
Cells[2,0]:='M';
Cells[3,0]:='L';
Cells[0,1]:='红';
Cells[0,2]:='绿';
Cells[0,3]:='蓝';
for i:=1 to 4 do
for j:=1 to 4 do
Cells[i,j]:='0';
end;
destructor ttestsg.Destroy;
begin
inherited Destroy ;
end;
procedure ttestsg.SetEditText(ACol, ARow: Integer;
const Value: String);
var
v,i,sv:integer;
begin
inherited SetEditText(ACol, ARow, Value);
if trystrtoint(value,v) then
begin
sv:=0;
for i:=1 to 3 do
if trystrtoint(Cells[i,arow],v) then
inc(sv,v);
Cells[4,arow]:=inttostr(sv);
sv:=0;
for i:=1 to 3 do
if trystrtoint(Cells[acol,i],v) then
inc(sv,v);
Cells[acol,4]:=inttostr(sv);
end;
end;