第一:如果是FORM的话,你可以从Screen中找看有没有它(Screen.Forms);如果是TControl或TComponent的派生类,应该也可以从Application和Screen.Forms顺滕摸瓜找到;
第二:非常不确切,我似乎从哪本书上看到Delphi有对象管理机制,可能能从这方面入手进行全能的控制;
第三:如果你非要管理,你可以进行自己一套管理机制,如在Form中增加一个List,其中每一项是变量的地址或你的glList,在赋值时往List中加这些东东,然后在FormDestroy中按照List去掉每一个。如:
for i:=List.Count-1 downto 0 do
begin
if IsVarPtr(List[i]) then
PTForm(List[i])^ := nil
else
TList(List[i]).Remove(Self);
end;
甚至还可以这样:
每个List中的项都存的是事件处理器:
for i:=List.Count-1 downto 0 do
TNotifyEvent(List[i])(Self);
首先,应该避免你所描述情况的发生才是上策,在写程序时,若这个指针所指向的对象已经释放掉了,同时应该将该指针置空。
若已经发生了,是不是可以
function IsValid(APointer :Pointer): Boolean;
begin
Result := True;
try
引用一下
except
Result := False;
end;
end;
不用再提前
我是这样做的:
if (Assigned(MyFormInstance)=false) or (MyFormInstance.ComponentCount=0) then
MyFormInstance:=TMyFormInstance.create(application);
MyFormInstance.show;