Very well explained Alimonster.
Okay another puzzle...
Exercise no 3:
There may be more than one solution for this problem. And for some people the problem might be very easy to solve.
A crazy programmer (me?!?) has design a component with eventhandler like this:
Code:
TOnChange = procedure(var I: Integer);
TMyObject = class
private
FOnChange: TOnChange;
public
property OnChange: TOnChange read FOnChange write FOnChange;
end;
You want to keep your code object-oriented at all costs and you want to attach a method DoIt with this event so you do something like this:
Code:
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
Obj: TMyObject;
procedure DoIt(var I: Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.DoIt(var I: Integer);
begin
ShowMessage(IntToStr(I));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Obj := TMyObject.Create;
Obj.FOnChange := DoIt;
end;
Remember that you can't change anything that crazy programmer has already done (TOnChange is done by a crazy programmer) and you have to keep things object-oriented.
The code above doesn't even compile. Your job is to fix it.
Siim
Bookmarks