Recent

Author Topic: Extend Package TCheckGroup - Problem to implement OnItemClick  (Read 5400 times)

frakno

  • Jr. Member
  • **
  • Posts: 93
Hi, I try to made a new extended package:   TjmCheckGroup = class(TCheckGroup)   and implemented some properties and functions and it works fine.

One problem I have though. The control TCheckGroup has an event OnItemClick. How can I implement this OnItemClick like:

Code: [Select]
protected
  procedure ItemClick( Sender : TObject; Index : integer ); override;       does not work, and i dont know how to customize

implementation   
  procedure  TjmCheckGroup.ItemClick( Sender : TObject; Index : integer );
     begin
       // Here I will implement som code in the Package
       if Index .... then ..

       inherited ItemClick( Index );
    end;

The idea is to do some work in the Control generally, and can do some work in each used control individually.

I hope somebody can help me.

Best regards
frakno
Lazarus #1.4.0 FPC #2.6.4 i386-win32-win32/win64
« Last Edit: May 21, 2015, 10:02:43 am by frakno »
Lazarus 4.0 FPC 3.2.2 Windows 10 and 11

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Extend Package TCheckGroup - Problem to implement OnItemClick
« Reply #1 on: May 21, 2015, 10:19:02 am »
OnItemClick is an event, you don't OVERRIDE it, but ASSIGN it. Read the docs.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Extend Package TCheckGroup - Problem to implement OnItemClick
« Reply #2 on: May 21, 2015, 10:33:00 am »
Well it seems that the control has missed the design guidelines for some reason. Neither the click or doclick methods are virtual so you can not override them and extend them as needed. So there is no safe way to extend them in an inherited control. On top of that they have divided their functionality in to click and doclick methods making it unsafe to simple add the virtual keyword on one of the methods. It requires a bit of redesign and a rule to be established that it will be followed by all the lcl. Doxxxxx must alway be virtual and must not contain anything more than the code to call the even if assigned. That would make it delphi compatible as well.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

frakno

  • Jr. Member
  • **
  • Posts: 93
Re: Extend Package TCheckGroup - Problem to implement OnItemClick
« Reply #3 on: May 21, 2015, 11:07:13 am »
Thanks for the replies. I have now been playing around a bit, but I can not implement it, I'm too inexperienced or stupid.

I rekognized that in   TCheckGroup   is 
type
   TCheckGroupClicked = procedure(Sender: TObject; Index: integer) of object;
   and
private
   FOnItemClick: TCheckGroupClicked;
   and
public
   property OnItemClick: TCheckGroupClicked read FOnItemClick write FOnItemClick;


but dont know how to adapt this in my ...
Lazarus 4.0 FPC 3.2.2 Windows 10 and 11

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Extend Package TCheckGroup - Problem to implement OnItemClick
« Reply #4 on: May 21, 2015, 11:40:10 am »
method that triggers OnItemClick is DoClick, so you can override that instead. Well it's actually not virtual, so you'll end up hiding the original method. However, I guess that fits your needs. See the source for inspiration on how the original code works.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Extend Package TCheckGroup - Problem to implement OnItemClick
« Reply #5 on: May 21, 2015, 11:52:55 am »
method that triggers OnItemClick is DoClick, so you can override that instead. Well it's actually not virtual, so you'll end up hiding the original method. However, I guess that fits your needs. See the source for inspiration on how the original code works.
it will not work. Click is called from the ancestor class and since it is not virtual or dynamic it does not know anything about the new method and it will continue calling the old one.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

frakno

  • Jr. Member
  • **
  • Posts: 93
Re: Extend Package TCheckGroup - Problem to implement OnItemClick
« Reply #6 on: May 21, 2015, 12:05:32 pm »
I tried it that way, and yes it does not work. Do someone know a solution.
Lazarus 4.0 FPC 3.2.2 Windows 10 and 11

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Extend Package TCheckGroup - Problem to implement OnItemClick
« Reply #7 on: May 21, 2015, 12:52:23 pm »
I tried it that way, and yes it does not work. Do someone know a solution.
your only option at this point is to copy the code from the TCustomCheckGroup as it is to a new unit, rename it to avoid any conflicts with the lcl class and then add your own code in that new class or rework the code to allow the methods named DoXXXXX to be overridable  and post a patch in the bug tracker to allow you at some point in the future to change the hierarchy from your custom class to the lcl class.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Extend Package TCheckGroup - Problem to implement OnItemClick
« Reply #8 on: May 21, 2015, 01:17:26 pm »
I tried it that way, and yes it does not work. Do someone know a solution.
your only option at this point is to copy the code from the TCustomCheckGroup as it is to a new unit, rename it to avoid any conflicts with the lcl class and then add your own code in that new class or rework the code to allow the methods named DoXXXXX to be overridable  and post a patch in the bug tracker to allow you at some point in the future to change the hierarchy from your custom class to the lcl class.
Or hope that the method will be virtual :P

frakno

  • Jr. Member
  • **
  • Posts: 93
Re: Extend Package TCheckGroup - Problem to implement OnItemClick
« Reply #9 on: May 21, 2015, 01:39:08 pm »
Many thanks, let's see if I have enough time and energy to build it.
Lazarus 4.0 FPC 3.2.2 Windows 10 and 11

frakno

  • Jr. Member
  • **
  • Posts: 93
Re: Extend Package TCheckGroup - Problem to implement OnItemClick
« Reply #10 on: May 21, 2015, 05:52:20 pm »
taazz, you are really great.  O:-)

I did it your way and it works fine.
After you have shown me the way it was not that hard  :)
« Last Edit: May 21, 2015, 06:02:48 pm by frakno »
Lazarus 4.0 FPC 3.2.2 Windows 10 and 11

 

TinyPortal © 2005-2018