TDeveloper = class
private
fName: string;
fOnNameChanged: TDisplayMethod;
procedure SetName(const Value: string);
constructor create;
published
property Name: string read fName write SetName;
property OnNameChanged: TDisplayMethod read fOnNameChanged write
fOnNameChanged;
end;
constructor TDeveloper.create;
begin
fName := 'warleyalex';
end;
procedure TDeveloper.SetName(const Value: string);
begin
if fName <> Value then
if Assigned(fOnNameChanged) then
fOnNameChanged('old name: ' + fName);
fOnNameChanged('new name: ' + Value);
fName := Value;
end;
procedure TForm1.W3Button10Click(Sender: TObject);
var
d: TDeveloper;
{ Nested Routines }
function DoSomething(S: string) : Variant;
var
X, Y: Integer;
procedure NestedProc(var S: string);
begin
X := 1; Y := 2;
S := S + (X * Y).ToString;
end;
begin
NestedProc(S);
Result := S;
end;
procedure MyValueMSG(const s: string);
begin
ShowMessage(s);
end;
begin
d := TDeveloper.Create;
d.OnNameChanged := procedure (const s: string)
begin
ShowMessage(s);
end;
d.Name := DoSomething('warleyalex');
d.OnNameChanged := MyValueMSG;
d.Name := DoSomething('sevenlakes');
end;
|