この関数の何が問題なのかを理解するのに少し苦労しています。-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;