Message dialog lazarus / 31-LCL ---------------------------------------------------------------------- dseligo · 2018-12-18 10:28 I have a strange problem with showing dialogs. I have small unit for entering password on my application start. After this form is released first dialog is not shown (it only flashes briefly). Edit: I just tried with Free instead of Release and it works fine. Could it have something with the fact that I create this form before main form? Lazarus is: Lazarus 1.8.2 r57369 FPC 3.0.4 x86_64-win64-win32/win64 OS is Windows 8.1, 64bit. Application is compiled as 32 bit. This is code where this occurs: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure csmPassword(var _sZaporka:String);begin  With TfmSigurnosnaProvjera.Create(nil) do  try    If ShowModal=mrOK then _sZaporka:=edZaporka.Text                      else _sZaporka:='';  finally    showmessage('1');    Release;    showmessage('2'); // this one flashes    showmessage('3');  end;end;  What could cause this behaviour? This is source from form: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i object fmSigurnosnaProvjera: TfmSigurnosnaProvjera  Left = 327  Height = 128  Top = 198  Width = 289  ActiveControl = edIme  BorderIcons = [biSystemMenu, biMinimize]  BorderStyle = bsDialog  Caption = 'Sigurnosna provjera'  ClientHeight = 128  ClientWidth = 289  Color = clBtnFace  Font.Color = clWindowText  Font.Height = -10  Font.Name = 'MS Sans Serif'  KeyPreview = True  OnClose = FormClose  OnShow = FormShow  Position = poScreenCenter  LCLVersion = '1.8.2.0'  object lIme: TLabel    Left = 63    Height = 13    Top = 20    Width = 17    Caption = '&Ime'    FocusControl = edIme    ParentColor = False  end  object lZaporka: TLabel    Left = 63    Height = 13    Top = 46    Width = 40    Caption = '&Zaporka'    ParentColor = False  end  object lZaporka2: TLabel    Left = 23    Height = 13    Top = 76    Width = 80    Alignment = taRightJustify    Caption = '&Kontrola zaporke'    ParentColor = False  end  object edIme: TEdit    Left = 122    Height = 21    Top = 20    Width = 98    MaxLength = 16    OnKeyPress = edImeKeyPress    TabOrder = 0  end  object edZaporka: TEdit    Left = 122    Height = 21    Top = 46    Width = 98    EchoMode = emPassword    MaxLength = 16    OnKeyPress = edZaporkaKeyPress    PasswordChar = '*'    TabOrder = 1  end  object btnOK: TBitBtn    Left = 56    Height = 25    Top = 88    Width = 75    Caption = '&U redu'    Glyph.Data = {      76010000424D7601000000000000760000002800000020000000100000000100      04000000000000010000120B0000120B00001000000000000000000000000000      800000800000008080008000000080008000808000007F7F7F00BFBFBF000000      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00555555555555      555555555555555555555555555555555555555555FF5555555555555A055555      55555555577FF55555555555AAA05555555555557777F55555555555AAA05555      555555557777FF555555555AAAAA05555555555777777F55555555AAAAAA0555      5555557777777FF5555557AA05AAA05555555777757777F555557A05555AA055      55557775555777FF55555555555AAA05555555555557777F555555555555AA05      555555555555777FF555555555555AA05555555555555777FF5555555555557A      05555555555555777FF5555555555557A05555555555555777FF555555555555      5AA0555555555555577755555555555555555555555555555555    }    NumGlyphs = 2    OnClick = btnOKClick    TabOrder = 2  end  object btnOdustani: TBitBtn    Left = 152    Height = 25    Top = 88    Width = 75    Cancel = True    Caption = '&Odustani'    Glyph.Data = {      76010000424D7601000000000000760000002800000020000000100000000100      04000000000000010000130B0000130B00001000000000000000000000000000      800000800000008080008000000080008000808000007F7F7F00BFBFBF000000      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333      3333333333FFFFF3333333333999993333333333F77777FFF333333999999999      3333333777333777FF3333993333339993333377FF3333377FF3399993333339      993337777FF3333377F3393999333333993337F777FF333337FF993399933333      399377F3777FF333377F993339993333399377F33777FF33377F993333999333      399377F333777FF3377F993333399933399377F3333777FF377F993333339993      399377FF3333777FF7733993333339993933373FF3333777F7F3399933333399      99333773FF3333777733339993333339933333773FFFFFF77333333999999999      3333333777333777333333333999993333333333377777333333    }    ModalResult = 2    NumGlyphs = 2    TabOrder = 3  end  object edZaporka2: TEdit    Left = 122    Height = 21    Top = 73    Width = 98    EchoMode = emPassword    MaxLength = 16    OnKeyPress = edZaporka2KeyPress    PasswordChar = '*'    TabOrder = 4  endend ---------------------------------------------------------------------- ASerge · 2018-12-18 18:22 1. Remove password dialog from auto-create forms in project options. 2. A simple test revealed no problems, regardless of using Free or Release. Perhaps in the OnClose or OnShow events you breaking something. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i class function TGetPasswordDlg.Execute(out Password: string): Boolean;var  Instance: TGetPasswordDlg;begin  Instance := Self.Create(Application); // or .Create(nil)  try    Result := (Instance.ShowModal = mrOK);    if Result then      Password := Trim(Instance.edtPassword.Text)    else      Password := '';  finally    Instance.Release; // or .Free  end;end; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMainForm.Button1Click(Sender: TObject);var  Password: string;begin  if TGetPasswordDlg.Execute(Password) then    Caption := Password // Test only!  else    Caption := 'SKIP PASSWORD';end; ---------------------------------------------------------------------- dseligo · 2018-12-19 10:23 Quote from: ASerge on December 18, 2018, 07:22:44 pm2. A simple test revealed no problems, regardless of using Free or Release. Perhaps in the OnClose or OnShow events you breaking something. OK, I created new project, added one more form, excluded second form from autocreate and add following code to project source: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Form2:=TForm2.Create(nil);  With Form2 do try    ShowModal;  finally  Release;    //Free;    ShowMessage('0');    ShowMessage('1');  end;  If I use "Free" instead of "Release" first showmessage is shown. I guess it has something to do with Application.CreateForm(TForm1, Form1), but I would appreciate explanation. I included complete test project in attachment. ---------------------------------------------------------------------- Josh · 2018-12-19 11:07 Hi Not tested Try adding application.processmessages; After you have released the form. To force the message cue to release the form and its controls. ---------------------------------------------------------------------- dseligo · 2018-12-21 01:33 Thanks, if I add Application.ProcessMessages then it's OK.  So is it better to use Release; Application.ProcessMessages; combination or Free; with manually created forms? ---------------------------------------------------------------------- lucamar · 2018-12-21 02:22 Quote from: dseligo on December 21, 2018, 02:33:52 amSo is it better to use Release; Application.ProcessMessages; combination or Free; with manually created forms? Free is almost always the best way to destroy an object. In this particular case Release basically just "marks" the form as disposable, making ProcessMessages almost obligatory to allow the application to destroy the form, if it's the Owner.