Example: |
The following tiny program shows how to set up and use an OnChange event. When the matrix is changed it issues the OnChange event which is assigned to the event handler MyMatOnChangeEvent. This event handler simply shows a mesagebox. The event handling can be removed again by assigning a nil value to the OnChange event:
program MatrixEvents;
procedure MyMatOnChangeEvent (Sender: TObject); // event handler
begin
MessageDlg ('Bingo! Matrix has changed', mtInformation, [mbOK]);
end;
var
MyMat : TMatrix;
begin // main program
MyMat := TMatrix.Create (nil);
MyMat.Resize (10,5);
MyMat.Fill (0,0,0,0,100);
MyMat.OnChange := @MyMatOnChangeEvent; // assign event handler
Pause;
MyMat.Elem [1,1] := 99; // this triggers the OnChange event
Pause;
MyMat.OnChange := nil; // remove event handling
MyMat.Elem [1,1] := 55; // this does not trigger the OnChange event any more
Pause;
MyMat.Free;
end.
|