Ok, that's a good proposal, but with your code, we have to loop on each components form...I'm afraid there is no other way. What's wrong with the loop?
And I can't store datas to a class module...You have to create a class in MyUnit.
QuoteOk, that's a good proposal, but with your code, we have to loop on each components form...I'm afraid there is no other way. What's wrong with the loop?QuoteAnd I can't store datas to a class module...You have to create a class in MyUnit.
As I mentioned in my previous post, procedure ClickTheButton and MouseUp must be part of a class, like this:
//your custom unit type TMyClass = class private procedure ClickTheButton(Sender: TObject); procedure MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); public constructor Create; destructor Destroy; override; end; var MyClass: TMyClass; procedure TMyClass.ClickTheButton(Sender: TObject); begin end; procedure TMyClass.MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin end; constructor TMyClass.Create; begin //do some initialization if needed, create objects, etc... end; destructor TMyClass.Destroy; begin //free object here inherited Destroy; end; //form's unit procedure SetButtons(const AControl: TControl); var I: Integer; begin if (AControl = nil) then Exit; if AControl is TWinControl then begin if (TWinControl(AControl) is TButton) and ((TWinControl(AControl) as TButton).Tag = 0) then begin (TWinControl(AControl) as TButton).OnClick := @Myclass.ClickTheButton; (TWinControl(AControl) as TButton).OnMouseUp := @MyClass.MouseUp; end; for I := 0 to TWinControl(AControl).ControlCount - 1 do SetButtons(TWinControl(AControl).Controls[I]); end; end; procedure TForm1.FormCreate(Sender: TObject); begin MyClass := TMyClass.Create; SetButtons(Form1); end; procedure TForm1.FormDestroy(Sender: TObject); begin MyClass.Free; end;
But how can I destroy all my custom class with variables?Hmm.. I'm not sure what you mean. In the above example, every object belonging to TMyClass(usually created in the constructor), must be freed inside the same class(usually in the destructor). The insance of TMyClass must be created and freed outside the class. In the above example is created and freed in TForm. You should always call MyClass.Free not MyClass.Destroy.
I tried by adding « myclassvariable.free » inside my destructor code and I added MyClass.Destroy but it doesn’t works...
TrackBar, ChkPlRep, DataSrc and Qry are parts of an external form?
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:
Hi,QuoteYes... 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:
uses unit1;//forms unit procedure SetImgZoom; begin MyZoom:= TZoomCls.Create; Form1.TrackBar.OnChange := @MyZoom.TrackBarChange; Form1.DtSource.OnDataChange:=@MyZoom.DtSourceChange; MyZoom.TrackBarChange(Form1.TrackBar); AfficherImage; end;
You should revert the assignations you did in SetImgZoom() in your destructor.