Recent

Author Topic: Assigning a Procedure not working  (Read 2166 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 475
Assigning a Procedure not working
« on: March 26, 2018, 02:02:04 am »
Platform:  Lazarus 1.8.1, FPC 3.0.5

I'm using a radio group component to both display info and to allow the user to select a choice.  This means that the OnSelectionchange needs to be shut off while I set it to the current value, then, turn it on again for the user to make a selection.  I'm trying to do this by setting the .OnSelectionChanged event to nil in the FormCreate procedure, and then in the FormShow procedure, reassign it.  Like this:

Code: Pascal  [Select][+][-]
  1. procedure TForm2.RadioGroup1SelectionChanged(Sender: TObject);
  2. begin
  3.   ShowMessage('My Selection has Changed');
  4. end;
  5.  
  6. procedure TForm2.FormCreate(Sender: TObject);
  7. begin
  8.   RadioGroup1.OnSelectionChanged := nil;
  9. end;
  10.  
  11. procedure TForm2.FormShow(Sender: TObject);
  12. begin
  13.   RadioGroup1.OnSelectionChanged := RadioGroup1SelectionChanged;
  14. end;  
  15.  

The line RadioGroup1.OnSelectionChanged := RadioGroup1SelectionChanged; in the FormShow will not compile. The error message is:

Compile Project, Target: unable_to_assign_prc.exe: Exit code 1, Errors: 2
unit2.pas(47,37) Error: Wrong number of parameters specified for call to "RadioGroup1SelectionChanged"
unit2.pas(35,18) Error: Found declaration: RadioGroup1SelectionChanged(TObject);

What am I doing wrong.  I'm tired and must be missing the obvious.  Thanks in advance for your help.

I have attached a demo project (missed it on my first post)
« Last Edit: March 26, 2018, 03:31:36 am by RedOctober »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Assigning a Procedure not working
« Reply #1 on: March 26, 2018, 02:22:38 am »
Code: Pascal  [Select][+][-]
  1.   RadioGroup1.OnSelectionChanged := @RadioGroup1SelectionChanged;
  2.  
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 7768
Re: Assigning a Procedure not working
« Reply #2 on: March 26, 2018, 03:10:48 am »
I consider that a bug!

I just checked my old Delphi and it's there too.

Normally when ever you set controls that do as what a USER does, the software set should not
trigger the OnClick event.. Only the user with their mouse should be doing that.

 Maybe we can get that fixed with a property option ..

 In any case,

 In the OnClick Event you can do this..

Code: Pascal  [Select][+][-]
  1. If Visible Then  // This is checking the FORM for visibility.
  2.  begin
  3.   //Do your onclick code here.
  4.  End;
  5.  

You also could do this..

In your Onclick event test for the TAG of the control..

If TAG = 1 then you can allow the contents of that event to take place..

when ever you want to move the INDEX of that control without code execution.... do this..

RadoGroup.Tag := O;

Radgroup.ItemIndex := ?

Tag := 1;
etc//

In the event;
If RadioGroup1.Tag = 1 then
Begin
.....
end;
« Last Edit: March 26, 2018, 03:19:16 am by jamie »
The only true wisdom is knowing you know nothing

RedOctober

  • Sr. Member
  • ****
  • Posts: 475
Re: Assigning a Procedure not working
« Reply #3 on: March 26, 2018, 03:40:38 am »
Thanks.  Blaazen's fix worked.  I forgot about "pointer to address"  "@" symbol.

 

TinyPortal © 2005-2018