Jump to content

Form Owner must be UniApplication


Wilton Ergon

Recommended Posts

in some cases, this error is generated when creating a frame inside a pagecontrol,
I've never been able to get this error locally in development, but it always appears in my error log that I capture in the application, I can't understand why this happens in a completely random way.

I'm using this event to catch the error, and a function created by farshad to catch the error and save it to a table.

 

procedure TUniServerModule.UniGUIServerModuleException( Sender: TUniGUIMainModule; AException: Exception; var Handled: Boolean);
var
  s, Msg: String;
  p1, p2, p3: Integer;
begin
  try
    if Assigned(Sender) then
     begin
      try
        (sender as TUniMainModule).LogException(AException);
      except
        s:= 'debug';
      end;
      Handled:= True;
    end
   else
    begin
      if AException <> nil then
      begin
        Msg:= AException.Message;
        p1 := Pos('Invalid URI:', Msg);
        p2 := Pos('EIdOSSLAcceptError :', Msg);
        p3 := Pos('Session not found:', Msg); // EUniSessionException : Invalid session or session Timeout. (Session not found:
        if (p1+p2+p3) > 0 then
        begin
          Handled:= True;
        end
       else
        begin
          Logger.AddLog('ERROR_GEP_WEB',
                        'EXCEPTION - ' +
                        'UnAssigned MainModule "'+Msg+'"');
          Handled:= True;
        end;
      end
     else
      begin
           Handled:= True;
      end;
    end;
  except
  end;
end;

in mainmodule...

procedure Tunimainmodule.LogException(E: Exception);
var
  Cmp: TComponent;
  s1, s2, Msg: String;
begin
  S1:='';
  S2:='';
  try
    if E <> nil then
    begin
      Msg:= E.Message;
      if copy(msg,1,1)<>'*' then
        Begin
          Cmp:= TUniGUIApplication(UniApplication).UniSession.CurrentComponent;
          if Assigned(Cmp) then
           begin
            if Cmp is TUniControl then
                 s2:= TUniControl(Cmp).OwnerForm.Name
            else if Cmp is TUniComponent then
                 s2:= TUniComponent(Cmp).OwnerForm.Name
            else s2:= '';

          //this function save in database error!
            SaveLogError(Msg,                      s2+' - '+cmp.Name+' - ' +Cmp.ClassName,                        CaptionGuiaAtualPrincipal);
           end
         else
           begin
                SaveLogError(Msg,
                            'ERRO NAO IDENTIFICADO',CaptionGuiaAtualPrincipal);
           end;
        End;

  except
  end;
end;

my function create new form...

 

procedure TFrmPrincipal.CriaFormulario(NomeForm,Titulo:string;BotaoFechar:Boolean);

Var  Ts  : TUniTabSheet;
     FrC : TUniFrameClass;
     Fr  : TUniFrame;
     i   : Integer;
     fname,TsName:String;
Begin
  Try
    For I := 0 to pgControlMain.PageCount-1 do
      Begin
        if pgControlMain.Pages[I].Caption=Titulo then
          Begin
            pgControlMain.ActivePageIndex :=I;
            Exit;
          End;
      End;

   if pgControlMain.PageCount>5 then
      FecharAba(1);

    TsName:='tab_'+SomenteLetras_e_Numeros(GetGuid);
    fname :=NomeForm+SomenteLetras_e_Numeros(GetGuid);


    Ts             := TUniTabSheet.Create(self);
    Ts.PageControl := pgControlMain;
    Ts.Name        := TsName;
    Ts.Closable    := BotaoFechar;

    Ts.Caption     := Titulo;
    Ts.OnClose     := tabStartClose;
    pgControlMain.ActivePage   :=Ts;
    FrC             := TUniFrameClass(FindClass(NomeForm));

    Fr                := FrC.Create(self); //here before I used TS as form owner
    Fr.Name      := fname;
    Fr.Align       := alClient;
    Fr.Parent     := Ts;


  finally
    BEGIN
     HideMask;
     UniSession.Synchronize;
    END;
  end;
end;

 

procedure TFrmPrincipal.tabStartClose(Sender: TObject; var AllowClose: Boolean);
var   zForm: TuniFrame;
begin

//destroy frame 
  try
      zForm        := tunitabsheet(sender).controls[0] as TuniFrame;
      freeandnil(zform);
  except
  end;

end;

 

 

 

 

 

Link to comment
Share on other sites

there is no way to create such a test case, as already explained, the function is called thousands of times a day, and randomly in some cases, this message is displayed, in totally different forms, when ending the session and trying the form again already and opened without problems, if I knew what causes this error to occur, I could try to find something else in the system that could generate the error.

  • Upvote 1
Link to comment
Share on other sites

  • 3 months later...
On 29/11/2021 at 14:06, Wilton Ergon said:

não há como criar tal caso de teste, como já explicado, a função é chamada milhares de vezes ao dia, e aleatoriamente em alguns casos, essa mensagem é exibida, de formas totalmente diferentes, ao encerrar a sessão e tentar o formulário novamente já e aberto sem problemas, se eu soubesse o que causa esse erro, poderia tentar encontrar outra coisa no sistema que pudesse gerar o erro.

I have the same problem

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...