Buenas,
Estoy tratando de hacer una aplicación en la que necesito crear y eliminar frames en tiempo de ejecución.
Código:
procedure TfrViewPatient.frEnter;
begin
studyList:=TObjectList.Create;
end;
procedure TfrViewPatient.frExit;
begin
studyList.Free;
end;
procedure TfrViewPatient.AddStudy(study:TStudy);
var
studyFrame: TfrStudy;
begin
try
studyFrame:=TfrStudy.Create(self);
studyFrame.Parent:= ScrollBox;
studyFrame.Name:='frStudy'+IntToStr(studyList.Count+1);
studyFrame.IO.LoadFromFile('Images\1\1\000006.jpg');
studyFrame.PanelStudy.OnClick:=FrStudyOnClick;
Controller.RegisterListener(MSG_STUDY_CLICK,StudyClick);
studyList.Add(studyFrame);
except
ShowMessage('Error creating study');
Exit;
end;
end;
procedure TfrViewPatient.StudyClick(Sender:TObject);
begin
//todo: enter stViewStudy
states.Enter(stViewStudy); <-- aquí el error
end;
procedure TfrViewPatient.FrStudyOnClick(Sender:TObject);
begin
Controller.Send(TMessage.Create(MSG_STUDY_CLICK,self,false));
end;
//todo: eliminar...
procedure TfrViewPatient.BitBtn1Click(Sender: TObject);
var
study: TStudy;
begin
AddStudy(study);
end;
end.
La parte de Controller.RegisterListener(MSG_STUDY_CLICK,StudyClick); es irrelevante. Utilizo un controlador de eventos para lanzarlos en otros threats. Igualmente, utilizo una máquina de estados para controlar las vistas, de ahí el states.Enter(stViewStudy);, que lo que hace básicamente es llamar al procedimiento frExit, donde hago el free de studyList, y modificar algunos aspectos visuales.
El tema está en que si añado un frame TfrStudy (AddStudy(study)) y lo añado a la lista studyList:TobjectList, al cambiar de frame (eliminando por tanto la lista studyList), me salta un error EOSError System Error code 5. Si
no creo ningún frame y por tanto no elimino, no hay problemas.
Alguna idea ??
Gracias