在 DELPHI 离 . InsertObject(index, s, nil) 这种用法起何作用?
它的帮助 InsertObject(Index: Integer; const S: string; AObject: TObject)
基本意思是向某个物件的某个位置的列表中插入一串字符, 但不知起什么作用?
因我看到如下代码:
procedure PushIntStates;
var
i, j:integer;
begin
if gMainMenu <> nil then begin
for i:=0 to gMainMenu.Items.Count -1 do begin
PushState(gMainMenu.Items[i].Enabled);
for j:=0 to gMainMenu.Items[i].Count -1 do begin
PushState(gMainMenu.Items[i].Items[j].Enabled);
end;
end;
end;
procedure PushState(bAble:Boolean);
begin
if bAble then
lstStates.Insert(0, 1)
else
lstStates.Insert(0, 0);
end;
procedure TStringList.Insert(Index: Integer; const S: string);
begin
InsertObject(Index, S, nil);
end;
第三个参数为无类型指针,
如果你不需要添加对象的话可以使用INSERT函数,
这样就只能单纯的在指定位置中插入字符串
如果你使用INSERTOBJECT函数就是使用了插入了字符串又在这个字符串中连接了你设定的对象,明白??
TOBJECT任何类型
InsertObject(Index: Integer; const S: string; AObject: TObject)
中S和AObject的关系,举个例子很好说明。
拿一个按钮Button1来说,“Button1”是按钮的名字,相当于S,而AObject相当于按钮本身。
—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————