type TFormClass = class of TForm;procedure pShowForm(aForm:TForm;TaForm:TFormClass;IsModal:boolean);
begin
if IsModal then
begin
if not Assigned(aForm) then
begin
aForm := TaForm.Create(Application);
try
aForm.ShowModal;
finally
aForm.Free;
aForm := nil;
end;
end
else aForm.ShowModal;
end
else
begin
if not Assigned(aForm) then
begin
aForm := TaForm.Create(Application);
aForm.Show;
end
else aForm.Show;
end;
end;pShowForm(Form2,TForm2,false);
問題在這裡,為甚麼我調試的時候aForm為nil,而不是預期的Form2?
應該怎麼解決?
begin
if IsModal then
begin
if not Assigned(aForm) then
begin
aForm := TaForm.Create(Application);
try
aForm.ShowModal;
finally
aForm.Free;
aForm := nil;
end;
end
else aForm.ShowModal;
end
else
begin
if not Assigned(aForm) then
begin
aForm := TaForm.Create(Application);
aForm.Show;
end
else aForm.Show;
end;
end;pShowForm(Form2,TForm2,false);
問題在這裡,為甚麼我調試的時候aForm為nil,而不是預期的Form2?
應該怎麼解決?
begin
if IsModal then
begin
if not Assigned(aForm) then
begin
aForm := TaForm.Create(Application);
try
aForm.ShowModal;
finally
aForm.Free;
end;
end
else aForm.ShowModal;
end;
if isModal=false then
begin
if not Assigned(aForm) then
begin
aForm := TaForm.Create(Application);
aForm.Show;
end
else aForm.Show;
end;
end;