Recent

Author Topic: Affect many buttons to class with events ?  (Read 4879 times)

jojo86

  • Jr. Member
  • **
  • Posts: 52
Re: Affect many buttons to class with events ?
« Reply #15 on: February 12, 2019, 04:34:36 pm »
Quote
Yes... I can’t explain why, but I’m sure that you’re going to tell me that’s the problem...
It's not a problem, but makes no sense to pass all those components as parameter. Why don't you use them directly by adding the form's unit to the uses clause? Like this:
Code: Pascal  [Select][+][-]
  1. uses unit1;//forms unit
  2.  
  3. procedure SetImgZoom;
  4. begin
  5.   MyZoom:= TZoomCls.Create;
  6.   Form1.TrackBar.OnChange := @MyZoom.TrackBarChange;
  7.   Form1.DtSource.OnDataChange:=@MyZoom.DtSourceChange;
  8.   MyZoom.TrackBarChange(Form1.TrackBar);
  9.   AfficherImage;
  10. end;
  11.  
Hi,
Sorry for my late reply.
I don't want to do that because my class can be used by 3 differents forms. So I don't want to specifie each form, I want to pass all my form to my class to control my form objects from my class...

So, I still have some problems with that... My code posted on January 31 doesn't works...


lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Affect many buttons to class with events ?
« Reply #16 on: February 12, 2019, 08:44:40 pm »
According to your description, there may be many interactions between objects in the other units and yor class which we can't see. Can you attach the full project so that we can see what exactly are you doing and how?

Anyway, freeing your class shouldn't affect any external object unless you're freeing them:
  • through the internal reference) in your class destructor; -or-
  • by changing their owners and freeing/destroying the new owner
Note also that after you free/destroy your class the pointers to the event handlers of the external objects now point to nowhere! You should revert the assignations you did in SetImgZoom() in your destructor.
« Last Edit: February 12, 2019, 08:51:09 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Affect many buttons to class with events ?
« Reply #17 on: February 12, 2019, 11:09:26 pm »
This looks almost like a job for ACTIONS.

The only true wisdom is knowing you know nothing

jojo86

  • Jr. Member
  • **
  • Posts: 52
Re: Affect many buttons to class with events ?
« Reply #18 on: February 13, 2019, 10:55:37 am »
You should revert the assignations you did in SetImgZoom() in your destructor.

Hi, thanks,
But how can I revert the assignations?
I Tried :
Code: Pascal  [Select][+][-]
  1. procedure SetImgZoom(TrackBar: TTrackBar; ChkPlRep: TCheckBox;
  2.   DataSrc: TDataSource; Qry: TSQLQuery);
  3. begin
  4.   MyZoom:= TZoomCls.Create;
  5.   MyZoom.Form:=TrackBar.Owner;
  6.   MyZoom.TrackBar:= TrackBar;
  7.   MyZoom.DtSource:=DataSrc;
  8.   MyZoom.ChkBox:= ChkPlRep;
  9.   MyZoom.Query:=Qry;
  10.   MyZoom.Img:=(MyZoom.Form.FindComponent('Img1') as TImage);
  11.   MyZoom.PContenantImg:=(MyZoom.Form.FindComponent('PContenantImg') as TPanel);
  12.   TrackBar.OnChange := @MyZoom.TrackBarChange;
  13.   MyZoom.DtSource.OnDataChange:=@MyZoom.DtSourceChange;
  14.   MyZoom.TrackBarChange(TrackBar);
  15.   AfficherImage;
  16. end;                                        
  17.  
  18.  
  19. destructor TZoomCls.Destroy;
  20. begin
  21.   MyZoom.Form:=nil;
  22.   TrackBar.OnChange := nil;
  23.   MyZoom.TrackBar:= nil;
  24.   MyZoom.DtSource.OnDataChange:=nil;
  25.   MyZoom.DtSource:=nil;
  26.   MyZoom.ChkBox:= nil;
  27.   MyZoom.Query:=nil;
  28.   MyZoom.Img:=nil;
  29.   MyZoom.PContenantImg:=nil;
  30.  
  31.   inherited;
  32.   //Destroy;
  33. end;                                        
  34.  

But after that, Assigned(MyZoom) return allways true so, I presume that something stay linked to my class but I don't know what...
How can I remove all link created with SetImgZoom ?

« Last Edit: February 13, 2019, 11:01:26 am by jojo86 »

 

TinyPortal © 2005-2018