J'ai un peu de mal à comprendre ce qui ne va pas avec cette fonction. Je ne suis pas sûr si je devrais utiliser -1 ou plus, et peu importe comment j'essaie d'arranger le code, il semble revenir à zéro, même si ce n'est pas le cas. Quelqu'un avec des yeux frais pourrait jeter un coup d'oeil? Aussi, je ne suis pas sûr que mon résultat: = nul est à la bonne place.Devrais-je soustraire 1 de la limite supérieure de mes boucles «for»?
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;
"Les indices de tableau doivent-ils commencer à 0 ou 1? Mon compromis de 0,5 a été rejeté sans, je pense, une considération appropriée. "- Stan Kelly-Bootle –