Quote
> Thanks Bruce, that worked. But i still would like to know why
>i have to do that. If i start a new project and do exactly the same,
>it works without having to send SELF as a parameter to
>ChangeCaption. AAMOF, i need send no parameters at all.
>Could it be just some flukey(bug?) thing with Delphi 1?
Its definitely not a bug. What I suspect is happening is that the form being
displayed is not the one that is auto created. When one defines a form in
Delphi it creates a class definition tFormName. Delphi also defines a
variable FormName in the same unit. Unless Delphi is instructed otherwise,
when the program starts up FormName is instantiated. However, a program does
not have to only use the instance FormName, it can do something like
myForm := tFormName.Create (Application);
myForm.Show;
In which case a second instance of tFormName is created. The code you posted
would always change the captions in the FormName instance, regardless of the
actual instance displayed. The changes I suggested change this behaviour so
that the captions that are changed are those that belong to the instance
that executes the code.
Quote
> If it's not the form instance, why does it display the changes when
>i make the changes to the captions in the event itself? (Button1Click)
When you include the lines in the event, all the references to the object's
local names implicitly include a Self reference, e.g.
Button1.Caption := 'text';
is actually compiled as
Self.Button1.Caption := 'text';
BTW, you can get around passing the Self parameter to ChangeCaption if you
make the procedure a method of the form, e.g.
tMyForm = class (tForm)
...
private
...
procedure ChangeCaption;
...
end;
procedure tMyForm.ChangeCaption;
begin
Button1.Caption := 'text';
...
end;