Sometimes madExcept shows bugs which are there, but hidden without madExcept. Don't know if that is the case for you. Of course it could also be a bug in madExcept.
How does your code in unit "uPrincipal" around line 119 look like? If the function is not too long, maybe you could post the full function code here?
madshi wrote:Sometimes madExcept shows bugs which are there, but hidden without madExcept. Don't know if that is the case for you. Of course it could also be a bug in madExcept.
How does your code in unit "uPrincipal" around line 119 look like? If the function is not too long, maybe you could post the full function code here?
My function is realy simple.
She load a BPL in runtime, create a registred class and then Execute the function associated.
procedure TFormPrincipalRunner.ExecutarAgendamento(Agendamento: TAgendamento);
var
vObj: TObject;
AForm: TCustomForm;
AClass: TPersistentClass;
begin
if not Assigned(Agendamento) then
Exit;
LoadPackage(Agendamento.ModuloExecucao);
AClass := GetClass(Agendamento.ClasseExecucao);
if AClass <> nil then
begin
try
AForm := TComponentClass(AClass).Create(nil) as TCustomForm;
try
if AForm.GetInterface(IRunnerModuleBase, vObj) then
begin
dmPrincipal.MomentoExecucao := meExecutandoModulo;
(AForm as IRunnerModuleBase).Executar;
end;
finally
FreeAndNil(AForm);
AddLogModulos('ExecutarAgendamento finaliza corretamente...');
end;
except
on Erro: Exception do
begin
AddLogModulos(Erro.Message);
end;
end;
end;
end;
I think your code is buggy. Calling "AForm.GetInterface(IRunnerModuleBase, vObj)" probably increases the reference count of AForm from 0 to 1. Then when "vObj" goes out of scope, Delphi automatically decreases reference count from 1 to 0 again and as a result the automatic interface cleanup solution frees the form. But you have already freed it yourself! I think if "AForm.GetInterface" succeeds you must not free AForm manually, anymore, to avoid having the form freed twice. You can check it out yourself: Remove that "FreeAndNil(AForm)". And then set a breakpoint in "AForm.Destroy" and check whether it's called. I think it will be called by the interface logic.
madshi wrote:I think your code is buggy. Calling "AForm.GetInterface(IRunnerModuleBase, vObj)" probably increases the reference count of AForm from 0 to 1. Then when "vObj" goes out of scope, Delphi automatically decreases reference count from 1 to 0 again and as a result the automatic interface cleanup solution frees the form. But you have already freed it yourself! I think if "AForm.GetInterface" succeeds you must not free AForm manually, anymore, to avoid having the form freed twice. You can check it out yourself: Remove that "FreeAndNil(AForm)". And then set a breakpoint in "AForm.Destroy" and check whether it's called. I think it will be called by the interface logic.
Hi,
I comment FreeAndNil code and my class Destroy don't called.
I discover an error in EXECUTAR method. But, is strange madException don't show the real class/function raise exception.