Fórum Como saber quais objetos tem parent igual ao objeto atual. #355612
18/03/2008
0
Estou usando assim....
procedure TFrmPrincipal.PageControlPrincipalClose(Sender: TObject;
var AllowClose: Boolean);
var
i, j: integer;
StateCDS: boolean;
begin
StateCDS := False;
with PageControlPrincipal do
begin
for i := 0 to Screen.FormCount - 1 do
with Screen.Forms[i] do
begin
if Parent <> nil then
if Parent = ActivePage then
for j := 0 to ComponentCount - 1 do
if (Components[j] is TClientDataSet) then
if (Components[j] as TClientDataSet).Active then
if (Components[j] as TClientDataSet).ChangeCount > 0 then
StateCDS := True;
end;
if StateCDS then
begin
if
Application.MessageBox(´Atenção! Existem Alterações pendentes que serão descartadas...´
+ #13 + 13 + ´Você tem mesmo certeza ?´,
´Cancelamento de Operações de dados...´, MB_YESNO + MB_ICONWARNING +
MB_DEFBUTTON1) = IDNO then
AllowClose := False
else
begin
ActivePage.Destroy;
SelectNextPage(false);
PageControlPrincipalChange(nil);
end;
end
else
begin
ActivePage.Destroy;
SelectNextPage(false);
PageControlPrincipalChange(nil);
end;
end;
end;
Apesar de funcional , queria substituir o ´for´ por alguma atitude mais rápida e orientada, mas getparent e etcs.. não estão funcionando.
Agradeço antecipadamente.
Emerson Azevedo
Curtir tópico
+ 0Posts
19/03/2008
Emerson Azevedo
Gostei + 0
20/03/2008
Emerson Nascimento
procedure TFrmPrincipal.PageControlPrincipalClose(Sender: TObject;
var AllowClose: Boolean);
var
i, j: integer;
StateCDS: boolean;
begin
StateCDS := False;
with PageControlPrincipal do
begin
// faz a verredura nos forms abertos
for i := 0 to Screen.FormCount - 1 do
with Screen.Forms[i] do
begin
if (Parent <> nil) and (Parent = ActivePage) then
// caso o form seja ´filho´ da página ativa no pagecontrol,
// faz a verredura nos componentes do form
for j := 0 to ComponentCount - 1 do
if (Components[j] is TClientDataSet) then
if (Components[j] as TClientDataSet).Active and
((Components[j] as TClientDataSet).ChangeCount > 0) then
begin
StateCDS := True;
break; // se já encontrou um dataset aberto,
// não é mais necessário varrer os COMPONENTES
end;
// se já encontrou um dataset aberto,
// não é mais necessário varrer os FORMS
if StateCDS then
break;
end;
AllowClose := not StateCDS or (StateCDS and
(Application.MessageBox(´Atenção! Existem Alterações pendentes que serão descartadas...´
+ 13 + 13 + ´Você tem mesmo certeza ?´,
´Cancelamento de Operações de dados...´, MB_YESNO + MB_ICONWARNING +
MB_DEFBUTTON1) = IDNO));
// a flag AllowClose=True fecha a página automaticamente.
// de qualquer forma, se você mesmo quiser controlar
// o fechamento, habilite o código abaixo
{ if AllowClose then
begin
ActivePage.Destroy;
SelectNextPage(false);
PageControlPrincipalChange(nil);
end;}
end;
end;Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)