只剩下20分了
我想让StringGrid的每一行每一列都能有一个类似Tag的标识
于是我写了一个类如下:
type
TTagStrings = class(TStringList)
private
FTag: Integer;
procedure SetTag(const Value: Integer);
public
constructor Create;
destructor Destroy; override;
property Tag: Integer read FTag write SetTag;
end;
implementation
constructor TTagStrings.Create;
begin
inherited;
FTag := 0;
end;
destructor TTagStrings.Destroy;
begin
inherited;
end;
procedure TTagStrings.SetTag(const Value: Integer);
begin
FTag := Value;
end;
然后把stringgrid的每一列(stringgrid.cols[i]为TStrings类型)强制转换为TTagStrings在对其进行Tag的赋值,但是退出程序时会报错.
procedure TForm1.Button1Click(Sender: TObject);
var
FT:TTagStrings;
i:integer;
begin
for i:=0 to StringGrid1.ColCount-1 do
begin
FT:=TTagStrings(StringGrid1.Cols[i]);
ft.Tag:=i;
end;
end;
报错内容为:
Exception EAccessViolation in module Project1.exe at 00004454.Access violation at address 3F804454 in module Project1.exe. Read of address FFFFFFF9.
不可能在不改动stringgrid的情况下达到你的目的.
建议你另外建立一个List或数组单独保存你的tag变量, 然后通过行号或列号和stringgrid关联起来.