我很难弄清楚这个功能出了什么问题。我不确定我是否应该再使用 -1,而且无论我如何尝试安排代码,即使它不应该返回,它似乎也返回 nil。有新鲜眼睛的人可以看看吗?另外,我不确定我的结果 := nil 是否在正确的位置。
function TFrmMain.FindQueryFrm(Server, Nickname: String): TFrmMessage;
var
I,M: Integer;
begin
/// No -1 in the I loop - why? Because the first childform will not always be
/// of type TFrmMessage, which is what we're looking for.
///
/// Is this approach wrong?
for I := 0 to MDIChildCount do
begin
if Screen.Forms[I] is TFrmMessage then
begin
/// Same concept with -1 here (M Loop)... I need to check all forms
/// stored by QueryManager to see if their .MyServer and .QueryWith's match
///
/// Is the M Loop wrong?
for M := 0 to QueryManager.Count do
begin
if UpperCase((QueryManager[M] as TFrmMessage).MyServer) = UpperCase(Server) then
begin
if UpperCase((QueryManager[M] as TFrmMessage).QueryWith) = UpperCase(NickName) then
begin // BINGO!
Result := (QueryManager[M] as TFrmMessage);
exit;
end;
end; // HOST COMPARE
end; // M Loop
end; // Is TFrmMessage
end; // I Loop
Result := nil; // None Found
end;