Recent

Author Topic: Unusual behavior with RadioButtons  (Read 1017 times)

CarmichaelJohn

  • New Member
  • *
  • Posts: 46
Unusual behavior with RadioButtons
« on: September 17, 2020, 07:37:34 pm »
Hello,
I am learning some pretty basic operations in Lazarus so that I can port over several of my Delphi programs and modify them.  I started with a blank program called “main form” and placed two radio buttons on it.  Each of these radio buttons calls a separate form.  All three forms have a simple menu with a “close” entry which is tied to a procedure that closes the form (with “close;”.  Each radio button is tied to a procedure that uses the “formname.showmodal;”.  It all works as expected until I activate the close on either of the called forms.  The form then blinks out of and back into existence on my monitor. 
When I do the same operation except calling the called forms from TmainMenu entries, the problem does not occur.
What can I do to make the form close and return focus to main form?
Thank you in advance, John

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
Re: Unusual behavior with RadioButtons
« Reply #1 on: September 17, 2020, 09:52:45 pm »
Please attach the project (zipped sources), otherwise it's hard to tell what's wrong.

Bart

CarmichaelJohn

  • New Member
  • *
  • Posts: 46
Re: Unusual behavior with RadioButtons
« Reply #2 on: September 17, 2020, 11:04:04 pm »
Bart,
Sorry, I do not know how to zip the source, I can unzip downloads, but that is the extent of the luck I have had with winzip, so here is my code in text format.  Thank you in advance for looking at it.
John

unit FormMainSubroutineCallingTWOSep162020;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, StdCtrls,
  FormSubCallModule2Sep162020, FormSuCallModule3Sep162020;

type

  { TFromMainSubroutineCall2Sep162020 }

  TFromMainSubroutineCall2Sep162020 = class(TForm)
    MainMenu1: TMainMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    MenuItem3: TMenuItem;
    MenuItem4: TMenuItem;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    RadioButton6: TRadioButton;
    procedure MenuItem2Click(Sender: TObject);
    procedure MenuItem3Click(Sender: TObject);
    procedure MenuItem4Click(Sender: TObject);
    procedure RadioButton1Change(Sender: TObject);
    procedure RadioButton2Change(Sender: TObject);
  private

  public

  end;

var
  FromMainSubroutineCall2Sep162020: TFromMainSubroutineCall2Sep162020;

implementation

{$R *.lfm}

{ TFromMainSubroutineCall2Sep162020 }

procedure TFromMainSubroutineCall2Sep162020.MenuItem2Click(Sender: TObject);
begin
    //
    close;
    //
end;

procedure TFromMainSubroutineCall2Sep162020.MenuItem3Click(Sender: TObject);
begin
    //
    FormSubCallModuleONESep162020.showModal;
    //
end;

procedure TFromMainSubroutineCall2Sep162020.MenuItem4Click(Sender: TObject);
begin
   //
   FormSubCallModuleTWOSep162020.ShowModal;
   //
end;

procedure TFromMainSubroutineCall2Sep162020.RadioButton1Change(Sender: TObject);
begin
    //
    FormSubCallModuleONESep162020.showModal;
    //
end;

procedure TFromMainSubroutineCall2Sep162020.RadioButton2Change(Sender: TObject);
begin
   //
   FormSubCallModuleTWOSep162020.ShowModal;
   //
end;

end.     

//**************************************************************************************************

unit FormSubCallModule2Sep162020;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus;

type

  { TFormSubCallModuleONESep162020 }

  TFormSubCallModuleONESep162020 = class(TForm)
    MainMenu1: TMainMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    procedure MenuItem2Click(Sender: TObject);
  private

  public

  end;

var
  FormSubCallModuleONESep162020: TFormSubCallModuleONESep162020;

implementation

{$R *.lfm}

{ TFormSubCallModuleONESep162020 }

procedure TFormSubCallModuleONESep162020.MenuItem2Click(Sender: TObject);
begin
    //
    close;
    //
end;

end.
       
//**********************************************************************************************

unit FormSuCallModule3Sep162020;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus;

type

  { TFormSubCallModuleTWOSep162020 }

  TFormSubCallModuleTWOSep162020 = class(TForm)
    MainMenu1: TMainMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    procedure MenuItem2Click(Sender: TObject);
  private

  public

  end;

var
  FormSubCallModuleTWOSep162020: TFormSubCallModuleTWOSep162020;

implementation

{$R *.lfm}

{ TFormSubCallModuleTWOSep162020 }

procedure TFormSubCallModuleTWOSep162020.MenuItem2Click(Sender: TObject);
begin
    //
    close;
    //
end;

end.
         

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Unusual behavior with RadioButtons
« Reply #3 on: September 17, 2020, 11:19:29 pm »
@CarmichaelJohn,

Consider putting the code you posted between the tags [ code=pascal ] (at the beginning) and [ /code ] (at the end without spaces after the "[" or before the "]" which are there to only to ensure the tags are visible (instead of only their effect being visible.)
 
ETA:

Also, consider using 7zip (instead of winzip), it's open source, free download and very easy to use.
« Last Edit: September 17, 2020, 11:21:37 pm by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 6129
Re: Unusual behavior with RadioButtons
« Reply #4 on: September 17, 2020, 11:35:44 pm »
@CarmichaelJohn,

Consider putting the code you posted between the tags [ code=pascal ] (at the beginning) and [ /code ] (at the end without spaces after the "[" or before the "]" which are there to only to ensure the tags are visible (instead of only their effect being visible.)
 
ETA:

Also, consider using 7zip (instead of winzip), it's open source, free download and very easy to use.

Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. unit FormMainSubroutineCallingTWOSep162020;
  4.  
  5. {$mode objfpc}{$H+}
  6.  
  7. interface
  8.  
  9. uses
  10.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, StdCtrls,
  11.   FormSubCallModule2Sep162020, FormSuCallModule3Sep162020;
  12.  
  13. type
  14.  
  15.   { TFromMainSubroutineCall2Sep162020 }
  16.  
  17.   TFromMainSubroutineCall2Sep162020 = class(TForm)
  18.     MainMenu1: TMainMenu;
  19.     MenuItem1: TMenuItem;
  20.     MenuItem2: TMenuItem;
  21.     MenuItem3: TMenuItem;
  22.     MenuItem4: TMenuItem;
  23.     RadioButton1: TRadioButton;
  24.     RadioButton2: TRadioButton;
  25.     RadioButton3: TRadioButton;
  26.     RadioButton4: TRadioButton;
  27.     RadioButton5: TRadioButton;
  28.     RadioButton6: TRadioButton;
  29.     procedure MenuItem2Click(Sender: TObject);
  30.     procedure MenuItem3Click(Sender: TObject);
  31.     procedure MenuItem4Click(Sender: TObject);
  32.     procedure RadioButton1Change(Sender: TObject);
  33.     procedure RadioButton2Change(Sender: TObject);
  34.   private
  35.  
  36.   public
  37.  
  38.   end;
  39.  
  40. var
  41.   FromMainSubroutineCall2Sep162020: TFromMainSubroutineCall2Sep162020;
  42.  
  43. implementation
  44.  
  45. {$R *.lfm}
  46.  
  47. { TFromMainSubroutineCall2Sep162020 }
  48.  
  49. procedure TFromMainSubroutineCall2Sep162020.MenuItem2Click(Sender: TObject);
  50. begin
  51.     //
  52.     close;
  53.     //
  54. end;
  55.  
  56. procedure TFromMainSubroutineCall2Sep162020.MenuItem3Click(Sender: TObject);
  57. begin
  58.     //
  59.     FormSubCallModuleONESep162020.showModal;
  60.     //
  61. end;
  62.  
  63. procedure TFromMainSubroutineCall2Sep162020.MenuItem4Click(Sender: TObject);
  64. begin
  65.    //
  66.    FormSubCallModuleTWOSep162020.ShowModal;
  67.    //
  68. end;
  69.  
  70. procedure TFromMainSubroutineCall2Sep162020.RadioButton1Change(Sender: TObject);
  71. begin
  72.     //
  73.     FormSubCallModuleONESep162020.showModal;
  74.     //
  75. end;
  76.  
  77. procedure TFromMainSubroutineCall2Sep162020.RadioButton2Change(Sender: TObject);
  78. begin
  79.    //
  80.    FormSubCallModuleTWOSep162020.ShowModal;
  81.    //
  82. end;
  83.  
  84. end.      
  85.  
  86. //**************************************************************************************************
  87.  
  88. unit FormSubCallModule2Sep162020;
  89.  
  90. {$mode objfpc}{$H+}
  91.  
  92. interface
  93.  
  94. uses
  95.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus;
  96.  
  97. type
  98.  
  99.   { TFormSubCallModuleONESep162020 }
  100.  
  101.   TFormSubCallModuleONESep162020 = class(TForm)
  102.     MainMenu1: TMainMenu;
  103.     MenuItem1: TMenuItem;
  104.     MenuItem2: TMenuItem;
  105.     procedure MenuItem2Click(Sender: TObject);
  106.   private
  107.  
  108.   public
  109.  
  110.   end;
  111.  
  112. var
  113.   FormSubCallModuleONESep162020: TFormSubCallModuleONESep162020;
  114.  
  115. implementation
  116.  
  117. {$R *.lfm}
  118.  
  119. { TFormSubCallModuleONESep162020 }
  120.  
  121. procedure TFormSubCallModuleONESep162020.MenuItem2Click(Sender: TObject);
  122. begin
  123.     //
  124.     close;
  125.     //
  126. end;
  127.  
  128. end.
  129.        
  130. //**********************************************************************************************
  131.  
  132. unit FormSuCallModule3Sep162020;
  133.  
  134. {$mode objfpc}{$H+}
  135.  
  136. interface
  137.  
  138. uses
  139.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus;
  140.  
  141. type
  142.  
  143.   { TFormSubCallModuleTWOSep162020 }
  144.  
  145.   TFormSubCallModuleTWOSep162020 = class(TForm)
  146.     MainMenu1: TMainMenu;
  147.     MenuItem1: TMenuItem;
  148.     MenuItem2: TMenuItem;
  149.     procedure MenuItem2Click(Sender: TObject);
  150.   private
  151.  
  152.   public
  153.  
  154.   end;
  155.  
  156. var
  157.   FormSubCallModuleTWOSep162020: TFormSubCallModuleTWOSep162020;
  158.  
  159. implementation
  160.  
  161. {$R *.lfm}
  162.  
  163. { TFormSubCallModuleTWOSep162020 }
  164.  
  165. procedure TFormSubCallModuleTWOSep162020.MenuItem2Click(Sender: TObject);
  166. begin
  167.     //
  168.     close;
  169.     //
  170. end;
  171.  
  172. end.
  173.          
  174.  
I wonder if he is seeing a similar issue like I am when using the ALT key for the first time when a form gets activated, it does a complete redraw, Very ugly view I might add.
« Last Edit: September 17, 2020, 11:38:15 pm by jamie »
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11912
Re: Unusual behavior with RadioButtons
« Reply #5 on: September 17, 2020, 11:41:15 pm »
I do not know how to zip the source
You could also use "Project" > "Publish Project" which has a "Compress" option in Laz 2.x -- it writes a zip of your project to a specific directory; then you can upload the zip to the forum under "Attachments and other options".

CarmichaelJohn

  • New Member
  • *
  • Posts: 46
Re: Unusual behavior with RadioButtons
« Reply #6 on: September 18, 2020, 01:39:09 am »
Hello,
I recoded the entire project under a new name and in a new folder.  Now the behavior is different, but also not what it should be.  When either of the radio buttons are clicked on, the appropriate called module is displayed, then when that module is closed, it closes.  Then when the second module's radio button is clicked, the FIRST module reappears.  If I reverse the order and start with the second module the same thing happens.  Thank you for showing me how to zip the files using publish project.  Here are the zipped files.
Thank you again for your help and also for your patience with me.
John

martijnn

  • New Member
  • *
  • Posts: 16
Re: Unusual behavior with RadioButtons
« Reply #7 on: September 18, 2020, 09:05:59 am »
You're using the OnChange event for the radio buttons.

Code: Pascal  [Select][+][-]
  1. procedure RadioButton1Change(Sender: TObject);
  2. procedure RadioButton2Change(Sender: TObject);
  3.  

When one of them is clicked the event is fired for the one getting unchecked too. Possibly the behavior you experience can be solved by using the OnClick event.

CarmichaelJohn

  • New Member
  • *
  • Posts: 46
Re: Unusual behavior with RadioButtons
« Reply #8 on: September 18, 2020, 09:30:39 am »
Martijnn,

Yes, that worked!  I used the on-change event because when I clicked on the Radio Button to get a procedure set in the program that was the procedure it gave me.  When I used an on-click event it worked as it should have.
Thank you so much,
John

 

TinyPortal © 2005-2018