Board index » delphi » Form not displaying new Properties

Form not displaying new Properties

Hi,

  I've inherited a Delphi program and i cannot make the new properties that
i set to any component to show up on any form, (not even if i add a new form)
unless it's done locally in an event (ie: button click). Surely there's a
way that i can set properties in PROCEDUREs outside an event and still have
it show up changed on the form.

  For example: From a ButtonClick event, i call a procedure to change
captions of some buttons but they never appear changed on the screen.
Any help would be much appreciated. Thanks,

Fred
--
remove JUNK at the end of my email address to REPLY!
:-) <-- For the humour impaired.
My only X lives in Tex. -> http://www.compassnet.com/grump/
Have a cow boy! -> http://www.galacticcowboys.com/
http://fox.nstn.ca/~fred_l/index.htm

 

Re:Form not displaying new Properties


Quote
Frederick A. Lajoie wrote in message <37077499.50D50...@fox.nstn.ca>...
>Hi,

>  I've inherited a Delphi program and i cannot make the new properties that
>i set to any component to show up on any form, (not even if i add a new
form)
>unless it's done locally in an event (ie: button click). Surely there's a
>way that i can set properties in PROCEDUREs outside an event and still have
>it show up changed on the form.

>  For example: From a ButtonClick event, i call a procedure to change
>captions of some buttons but they never appear changed on the screen.
>Any help would be much appreciated. Thanks,

Changing button captions the way you describe should, and does for me, work.
There are a number of possibilities why you can't seem to get it working
    1. The button captions are not actually being set.
    2. The button captions being set are not the ones displayed.
    3. After setting the captions the program is going into a CPU intensive
task that doesn't give the program a chance to repaint the form.

A simplified code snippet might clarify the problem.

Re:Form not displaying new Properties


Quote
Bruce Roberts wrote:

> Frederick A. Lajoie wrote in message <37077499.50D50...@fox.nstn.ca>...
> >Hi,

> >  I've inherited a Delphi program and i cannot make the new properties that
> >i set to any component to show up on any form, (not even if i add a new
> form)
> >unless it's done locally in an event (ie: button click). Surely there's a
> >way that i can set properties in PROCEDUREs outside an event and still have
> >it show up changed on the form.

> >  For example: From a ButtonClick event, i call a procedure to change
> >captions of some buttons but they never appear changed on the screen.
> >Any help would be much appreciated. Thanks,

> Changing button captions the way you describe should, and does for me, work.
> There are a number of possibilities why you can't seem to get it working
>     1. The button captions are not actually being set.
>     2. The button captions being set are not the ones displayed.
>     3. After setting the captions the program is going into a CPU intensive
> task that doesn't give the program a chance to repaint the form.

> A simplified code snippet might clarify the problem.

  I forgot to mention that it's Delphi 1. I'm going to the office a
little later, i can post a sample but i don't think it'll clear things up.
The possibilities 1 & 2 were the first ones brought up by co-workers but i
showed them the code to prove it wasn't that. The worst thing is, i've added
a watch and the variables *do* change to the values i set them, but they
still don't change on the form unless i set them in an event.

  I did remember later (after my original post) that the program may
have been compiled in Delphi 3 once, and then brough back to the Delphi 1
environment. Is it possible that there are 'info' files that need to be
cleaned out? I'm really stumped with this one.

Fred
--
remove JUNK at the end of my email address to REPLY!
:-) <-- For the humour impaired.
My only X lives in Tex. -> http://www.compassnet.com/grump/
Have a cow boy! -> http://www.galacticcowboys.com/
http://fox.nstn.ca/~fred_l/index.htm

Re:Form not displaying new Properties


Quote
Bruce Roberts wrote:
> Frederick A. Lajoie wrote in message <37077499.50D50...@fox.nstn.ca>...
> >Hi,

> >  I've inherited a Delphi program and i cannot make the new properties that
> >i set to any component to show up on any form, (not even if i add a new
> form)
> >unless it's done locally in an event (ie: button click). Surely there's a
> >way that i can set properties in PROCEDUREs outside an event and still have
> >it show up changed on the form.

> >  For example: From a ButtonClick event, i call a procedure to change
> >captions of some buttons but they never appear changed on the screen.
> >Any help would be much appreciated. Thanks,

> Changing button captions the way you describe should, and does for me, work.
> There are a number of possibilities why you can't seem to get it working
>     1. The button captions are not actually being set.
>     2. The button captions being set are not the ones displayed.
>     3. After setting the captions the program is going into a CPU intensive
> task that doesn't give the program a chance to repaint the form.

> A simplified code snippet might clarify the problem.

procedure ChangeCaption;
begin
  editjobsform.bmpro.Caption       := 'test';
  editjobsform.bhelpdesk.Caption  := 'test';
  editjobsform.bother.Caption       := 'test';
  editjobsform.button1.Caption      := 'test';
end;

procedure TEditJobsForm.Button1Click(Sender: TObject);
begin
  ChangeCaption;
end;

  The above does compile and belong all to the same form.
If i were to take the 4 lines from ChangeCaption and put
them in the Button1Click event, then it will display the
changes on the components of the form. But it won't
display the changes when in ChangeCaption. (Delphi 1)
It's particular to that program i inherited. If i start a new
project, i don't have that problem.

Fred

Re:Form not displaying new Properties


Quote

>procedure ChangeCaption;
>begin
>  editjobsform.bmpro.Caption       := 'test';
>  editjobsform.bhelpdesk.Caption  := 'test';
>  editjobsform.bother.Caption       := 'test';
>  editjobsform.button1.Caption      := 'test';
>end;

procedure ChangeCaption (Whose : tEditJobsForm);

begin
with Whose do
    begin
    bmPro.Caption := 'test';
    bHelpDesk.Caption := 'test';
    bOther.Caption := 'test';
    button1.Caption := 'test';
    end;
end;

Quote

>procedure TEditJobsForm.Button1Click(Sender: TObject);
>begin
>  ChangeCaption;
>end;

procedure tEditJobsForm.Buton1Click (Sender : tObject);

begin
ChangeCaption (Self);
end;

Quote
>  The above does compile and belong all to the same form.
>If i were to take the 4 lines from ChangeCaption and put
>them in the Button1Click event, then it will display the
>changes on the components of the form. But it won't
>display the changes when in ChangeCaption. (Delphi 1)
>It's particular to that program i inherited. If i start a new
>project, i don't have that problem.

Try the changes I suggest above. From what you have shown, I would suspect
that EditJobsForm is not the form instance that is displayed.

Re:Form not displaying new Properties


Quote
Bruce Roberts wrote:

> >procedure ChangeCaption;
> >begin
> >  editjobsform.bmpro.Caption       := 'test';
> >  editjobsform.bhelpdesk.Caption  := 'test';
> >  editjobsform.bother.Caption       := 'test';
> >  editjobsform.button1.Caption      := 'test';
> >end;

> procedure ChangeCaption (Whose : tEditJobsForm);

> begin
> with Whose do
>     begin
>     bmPro.Caption := 'test';
>     bHelpDesk.Caption := 'test';
>     bOther.Caption := 'test';
>     button1.Caption := 'test';
>     end;
> end;

> >procedure TEditJobsForm.Button1Click(Sender: TObject);
> >begin
> >  ChangeCaption;
> >end;

> procedure tEditJobsForm.Buton1Click (Sender : tObject);

> begin
> ChangeCaption (Self);
> end;

  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?

Quote
> >  The above does compile and belong all to the same form.
> >If i were to take the 4 lines from ChangeCaption and put
> >them in the Button1Click event, then it will display the
> >changes on the components of the form. But it won't
> >display the changes when in ChangeCaption. (Delphi 1)
> >It's particular to that program i inherited. If i start a new
> >project, i don't have that problem.

> Try the changes I suggest above. From what you have shown, I would suspect
> that EditJobsForm is not the form instance that is displayed.

  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)

Thanks for you help Bruce. Much appreciated.

Fred
NDS

Re:Form not displaying new Properties


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;

Re:Form not displaying new Properties


Quote
"Frederick A. Lajoie" wrote:
> Hi,

>   I've inherited a Delphi program and i cannot make the new properties that
> i set to any component to show up on any form, (not even if i add a new form)
> unless it's done locally in an event (ie: button click). Surely there's a
> way that i can set properties in PROCEDUREs outside an event and still have
> it show up changed on the form.

>   For example: From a ButtonClick event, i call a procedure to change
> captions of some buttons but they never appear changed on the screen.
> Any help would be much appreciated. Thanks,

  Did you put in an 'Application.ProcessMessages' to make certain that the
screen/forms/etc... are updated??

--
If there is a no_junk in my address, please REMOVE it before replying!
All junk mail senders will be prosecuted to the fullest extent of the law!!
http://www.ntsource.com/~andyross

Re:Form not displaying new Properties


Quote
Bruce Roberts wrote:
> >  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;

  Bingo. In the .DPR file i have this:

    Application.CreateForm(TEditJobsForm, EditJobsForm);

  But in the Button1Click event i have also this:

    EditJobs:=TEditJobsForm.create(self);
    EditJobsform.show;

  I got rid of the CREATE(SELF) line, and now everything works
fine. I don't even need to send SELF as a parameter to my local
procedures.

  As i mentionned earlier, i've inherited this program. Can you tell me
why even use the "EditJobs:=TEditJobsForm.create(self)" when the
form is already created in the .DPR file?

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';

   Ok, i understand that now.

  Thanks again Bruce. This Delphi newbie appreciates the help.

Fred
NDS

Re:Form not displaying new Properties


Quote
Frederick A. Lajoie wrote:
> Bruce Roberts wrote:

> > >  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;

>   Bingo. In the .DPR file i have this:

>     Application.CreateForm(TEditJobsForm, EditJobsForm);

>   But in the Button1Click event i have also this:

>     EditJobs:=TEditJobsForm.create(self);
>     EditJobsform.show;

>   I got rid of the CREATE(SELF) line, and now everything works
> fine. I don't even need to send SELF as a parameter to my local
> procedures.

>   As i mentionned earlier, i've inherited this program. Can you tell me
> why even use the "EditJobs:=TEditJobsForm.create(self)" when the
> form is already created in the .DPR file?

  Oops...ignore this. I goofed up. To make a long story short, the
original program does not create any of the forms twice. While
adding a form of mine, being new to Delphi i've tried to do as
the original program was doing, but i did it wrong. But maybe
you can tell me what is the difference between doing it one way
and the other? Thanks,

Fred
NDS

Re:Form not displaying new Properties


On Tue, 06 Apr 1999 11:48:12 -0300, "Frederick A. Lajoie"

Quote
<n...@istar.ca> wrote:
>>   As i mentionned earlier, i've inherited this program. Can you tell me
>> why even use the "EditJobs:=TEditJobsForm.create(self)" when the
>> form is already created in the .DPR file?

>  Oops...ignore this. I goofed up. To make a long story short, the
>original program does not create any of the forms twice. While
>adding a form of mine, being new to Delphi i've tried to do as
>the original program was doing, but i did it wrong. But maybe
>you can tell me what is the difference between doing it one way
>and the other? Thanks,

If you autocreate a form, that form will take up memory as soon as the
program starts executing. All the code placed in .FormCreate, on timer
events and other periodic events on those forms will start executing.
If you open database tables for those forms, opening up a program can
take a lot of time.

To minimize memory and only use memory for what you're actually
displaying, remove the forms from the autocreate list and use the code
you had to dynamically create the forms when you need them

--
Lasse V?gs?ther Karlsen
Cintra Software Engineering AS
la...@cintra.no

All views in this posting is my own and does not reflect those of the company I work for.

Other Threads