BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using TAction in different form

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using
View previous topic :: View next topic  
Author Message
Anja
Guest





PostPosted: Tue Nov 25, 2003 8:14 am    Post subject: Using TAction in different form Reply with quote




Hi,

I have two forms:

Form2 with One TActionList with one TAction having a OnExecute event:

procedure TForm2.Action1Execute(Sender: TObject);
begin
showmessage ('The action is performed.')
end;

And a Form1 with one TPopupMenu, with one TMenuItem, which is linked
to the Form2.Action1 (of course Unit2 is in my uses clause).

Why is the action not executed when I click het menu item ?
Am I missing something?

Thanks,
Anja.

Back to top
Ollo
Guest





PostPosted: Tue Nov 25, 2003 3:58 pm    Post subject: Re: Using TAction in different form Reply with quote



Hi Anja,
it's difficult to say anything without more information.

Does your form2 exist when you call the action of form2?

Bye Ollo


"Anja" <Anjasmedts (AT) hotmail (DOT) com> schrieb im Newsbeitrag news:3fc31d58$1 (AT) newsgroups (DOT) borland.com...
Quote:

Hi,

I have two forms:

Form2 with One TActionList with one TAction having a OnExecute event:

procedure TForm2.Action1Execute(Sender: TObject);
begin
showmessage ('The action is performed.')
end;

And a Form1 with one TPopupMenu, with one TMenuItem, which is linked
to the Form2.Action1 (of course Unit2 is in my uses clause).

Why is the action not executed when I click het menu item ?
Am I missing something?

Thanks,
Anja.


Back to top
Peter Below (TeamB)
Guest





PostPosted: Tue Nov 25, 2003 6:46 pm    Post subject: Re: Using TAction in different form Reply with quote



In article <3fc31d58$1 (AT) newsgroups (DOT) borland.com>, Anja wrote:

Quote:
Form2 with One TActionList with one TAction having a OnExecute event:

procedure TForm2.Action1Execute(Sender: TObject);
begin
showmessage ('The action is performed.')
end;

And a Form1 with one TPopupMenu, with one TMenuItem, which is linked
to the Form2.Action1 (of course Unit2 is in my uses clause).

Why is the action not executed when I click het menu item ?
Am I missing something?

IMO it is a very bad idea to link two forms this way. The action is
probably disabled or the link you set in the designer has been lost.
This will happen when the application loads TForm1 and TForm2 has not
been created yet. Set the link at run-time, but not in the OnCreate
event of form1, that is too early. Use OnActivate or OnShow.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be



Back to top
AnjaSmedts
Guest





PostPosted: Wed Nov 26, 2003 6:58 am    Post subject: Re: Using TAction in different form Reply with quote


"Peter Below (TeamB)" <100113.1101 (AT) compuXXserve (DOT) com> wrote:
Quote:
In article <3fc31d58$1 (AT) newsgroups (DOT) borland.com>, Anja wrote:

Form2 with One TActionList with one TAction having a OnExecute event:

procedure TForm2.Action1Execute(Sender: TObject);
begin
showmessage ('The action is performed.')
end;

And a Form1 with one TPopupMenu, with one TMenuItem, which is linked
to the Form2.Action1 (of course Unit2 is in my uses clause).

Why is the action not executed when I click het menu item ?
Am I missing something?

IMO it is a very bad idea to link two forms this way. The action is
probably disabled or the link you set in the designer has been lost.
This will happen when the application loads TForm1 and TForm2 has not
been created yet. Set the link at run-time, but not in the OnCreate
event of form1, that is too early. Use OnActivate or OnShow.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


Hi Peter,


I've tested your idea to link the action at run-time (just in a Onclick event of a button) and then it works. Great!

But seems to me a strange behaviour, as I can 'link' two forms by using eg. a TTable from one form as DataSet property of a TDatasource in another form, without any problem.

My idea was: let all the actions which have an influence on TForm2 reside on that form, even if they are invoked by a TMenuItem on TForm1. Would you propose another way of working?

But in the meanwhile, I can continue with your solution.
Could you please take a look on my Primary Key problem, posted in the vcl.components.writing NG?

Anja.

Back to top
Peter Below (TeamB)
Guest





PostPosted: Wed Nov 26, 2003 7:12 pm    Post subject: Re: Using TAction in different form Reply with quote

In article <3fc45d24$1 (AT) newsgroups (DOT) borland.com>, AnjaSmedts wrote:
Quote:
But seems to me a strange behaviour, as I can 'link' two forms by using
eg. a TTable from one form as DataSet property of a TDatasource in
another form, without any problem.

Oh, there are reports about similar problems with such setups quite regulary
on these groups. The typical setup using datamodules works because the DMs
are created before the main form is. Even then you can run into problems if
you close the DM in the IDE, then change something on a form that has links to
the DM and save the form.
Quote:

My idea was: let all the actions which have an influence on TForm2 reside
on that form, even if they are invoked by a TMenuItem on TForm1. Would
you propose another way of working?

Yes, i never let code in unit A mess around with the innards of an object
in unit B. Basically i consider all the stuff the IDE puts in the default
section of a form class to be private to the form (even though it is
published in scope). So the menu item in your case would have a handler on
form1 and that handler would call a public method in form2 that would then
call the form2 actions Execute method (or better call a method that does the
actual work and is also called form the actions OnExecute event).

Doing things this way may look like more work but it isolates your forms
much better from each other, and that pays of big over time. You can now
change form2, rename the action, whatever, without breaking code in form1.



--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.