Can anyone explain why Application.Terminate does not work from within a
loop ? (Delphi 1) I have noticed this problem several times before in
different situations.
For instance, the following code fragment was taken from the FormCreate
handler of a MainForm. The intention is to gather up a number of individual
memos named Memo1, Memo2, etc. and to assemble them into an array.
tcmp is a TComponent, s is a string.
for j := 1 to maxMemo do
begin
s := 'Memo'+IntToStr(j) ; tcmp := Self.FindComponent(s) ;
if tcmp = nil then
begin
MessageDlg('Component "'+s+'" can not be found.', mtError,[mbOK],0) ;
break ;
end ;
MemoRay[j] := (tcmp as TMemo) ;
end ;
if tcmp = nil then Application.Terminate ;
The above code halts as intented if an expected Memo is missing, but if
"break" is replaced by "Application.Terminate", then the application fails
to halt at that point, and the program ends on an error in the
"MemoRay[j] :=" line.
Note - the purpose of assembling these (basically identical) memos into an
array is to allow the first "n" (not all) to be selected at run time, and
their top, left, width, and height be assigned so that they lie side by side
and just fill the window. The excess are made invisible. Your ideas for
better ways to handle this situation are welcome.
--- PPoint 2.00
---------------
* Origin: Kingston, Canada (1:249/109.11)
|