Plocationrecord是我自己定义的一个结构体
type
Plocationrecord=^_locarecord; // 将行号和id 存放一起
_locarecord=record
lowrow:integer;
highrow:integer;
firendid:integer; //放id
End;
procedure TForm1.Button2Click(Sender: TObject);
var location:Plocationrecord;
begin
new(location);
location.lowrow:=1;
location.highrow:=11;
location.firendid:=111;
if locationList.IndexOf(location)=-1 then//这里的location值不都是一样吗?为什么跟着显示的不一样呢?
locationList.Add(location);
ShowMessage(IntToStr(locationList.Count));
end;
我的问题就是IndexOf如何检测结构体呢?因为每次单击button,它的Count就加1
type
Plocationrecord=^_locarecord; // 将行号和id 存放一起
_locarecord=record
lowrow:integer;
highrow:integer;
firendid:integer; //放id
End;
procedure TForm1.Button2Click(Sender: TObject);
var location:Plocationrecord;
begin
new(location);
location.lowrow:=1;
location.highrow:=11;
location.firendid:=111;
if locationList.IndexOf(location)=-1 then//这里的location值不都是一样吗?为什么跟着显示的不一样呢?
locationList.Add(location);
ShowMessage(IntToStr(locationList.Count));
end;
我的问题就是IndexOf如何检测结构体呢?因为每次单击button,它的Count就加1
那我想判断某一个结构体是否已经加入?
是不是只有每个变量都循环判断一次?这样做太麻烦了吧
新分配了一个location 地址肯定和以前不一样
locationList.IndexOf(location)=-1 永远都是-1
function TList.IndexOf(Item: Pointer): Integer;
begin
Result := 0;
while (Result < FCount) and (FList^[Result] <> Item) do
Inc(Result);
if Result = FCount then
Result := -1;
end;
贴上源码,原来FList^[Result] 根据地址来比较的