🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.winforms.controls.using
13 messages
13 total messages Started by Brigitte Spatz Tue, 05 Sep 2006 10:30
one form influencing another
#240
Author: Brigitte Spatz
Date: Tue, 05 Sep 2006 10:30
11 lines
1477 bytes
When a certain event happens on one of my forms (non-MDI), I want  
something else to happen on the main form (which is an MDI parent and I  
want all children to close). How do I do this? (I know how to close all  
MDI children from the MDI parent but I don't know how to do this from  
another form. Simply calling the MDI parent's Close_All procedure gives an  
error message along the lines of "only allowed for class methods" but I  
can't make Close_All a class method as it needs to refer to itself.)

TIA.

Brigitte
Re: one form influencing another
#241
Author: Wayne Niddery [TeamB]
Date: Tue, 05 Sep 2006 14:20
43 lines
2511 bytes
Brigitte Spatz wrote:
> When a certain event happens on one of my forms (non-MDI), I want
> something else to happen on the main form (which is an MDI parent and
> I want all children to close). How do I do this? (I know how to close
> all MDI children from the MDI parent but I don't know how to do this
> from another form. Simply calling the MDI parent's Close_All
> procedure gives an error message along the lines of "only allowed for
> class methods" but I can't make Close_All a class method as it needs
> to refer to itself.)

Post a message to the main form. In the main form, define a custom message 
and matching method:

const
    wm_MyCustomMessage = wm_user + 2006;
    // any # is good here as long as it's not used elsewhere in your app

type
    TForm1 = class(TForm)
    {...}
    protected
        procedure MyCustomMessage(var msg: TMessage); message 
wm_MyCustomMessage;

{...}

procedure TForm1.MyCustomMessage(var msg: TMessage);
begin
    // close MDI kids here
end;

Now in your other form, you need to have the main form unit in the Uses 
clause, then you can just do:

    PostMessage(Application.Mainform.Handle, wm_MyCustomMessage, 0, 0);

If you need to have the MDI kids closed before the other form can proceed 
further, then use SendMessage instead of PostMessage.

-- 
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"Reality is that which, when you stop believing in it, doesn't go
away." - Philip K. Dick 
Re: one form influencing another
#243
Author: Brigitte Spatz
Date: Thu, 07 Sep 2006 09:53
14 lines
1367 bytes
On Tue, 05 Sep 2006 16:20:43 +0200, Wayne Niddery [TeamB]  
<wniddery@chaffaci.on.ca> wrote:

> const
>     wm_MyCustomMessage = wm_user + 2006;
>     // any # is good here as long as it's not used elsewhere in your app

And what is wm_user? It's flagged up as undefined identifier :-(

TIA.

Brigitte
Re: one form influencing another
#244
Author: Brigitte Spatz
Date: Thu, 07 Sep 2006 09:56
11 lines
1295 bytes
On Tue, 05 Sep 2006 16:20:43 +0200, Wayne Niddery [TeamB]  
<wniddery@chaffaci.on.ca> wrote:

> procedure MyCustomMessage(var msg: TMessage); message
> wm_MyCustomMessage;

TMessage is also unknown. What uses clause do I need, please?

TIA.

Brigitte
Re: one form influencing another
#246
Author: Brigitte Spatz
Date: Thu, 07 Sep 2006 11:04
10 lines
1280 bytes
On Tue, 05 Sep 2006 16:20:43 +0200, Wayne Niddery [TeamB]  
<wniddery@chaffaci.on.ca> wrote:

> PostMessage(Application.Mainform.Handle, wm_MyCustomMessage, 0, 0);

...and PostMessage is also unknown. Which uses clause, please?

TIA.

Brigitte
Re: one form influencing another
#245
Author: Brigitte Spatz
Date: Thu, 07 Sep 2006 11:05
12 lines
1495 bytes
On Thu, 07 Sep 2006 11:56:25 +0200, Brigitte Spatz  
<brigitte.NOSPAMspatz@svenmahn.de> wrote:

> On Tue, 05 Sep 2006 16:20:43 +0200, Wayne Niddery [TeamB]  
> <wniddery@chaffaci.on.ca> wrote:
>
>> procedure MyCustomMessage(var msg: TMessage); message
>> wm_MyCustomMessage;
>
> TMessage is also unknown. What uses clause do I need, please?

It's System.Windows.Message.
Re: one form influencing another
#247
Author: Wayne Niddery [TeamB]
Date: Thu, 07 Sep 2006 16:19
18 lines
1649 bytes
Brigitte Spatz wrote:
> On Tue, 05 Sep 2006 16:20:43 +0200, Wayne Niddery [TeamB]
> <wniddery@chaffaci.on.ca> wrote:
>
>> const
>>     wm_MyCustomMessage = wm_user + 2006;
>>     // any # is good here as long as it's not used elsewhere in your
>> app
>
> And what is wm_user? It's flagged up as undefined identifier :-(


Add Windows to your Uses clause (for all 4 reported problems I see 
currently).

-- 
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"In a tornado, even turkeys can fly." - unknown 
Re: one form influencing another
#248
Author: Brigitte Spatz
Date: Thu, 07 Sep 2006 17:09
26 lines
1840 bytes
On Thu, 07 Sep 2006 18:19:36 +0200, Wayne Niddery [TeamB]  
<wniddery@chaffaci.on.ca> wrote:

> Brigitte Spatz wrote:
>> On Tue, 05 Sep 2006 16:20:43 +0200, Wayne Niddery [TeamB]
>> <wniddery@chaffaci.on.ca> wrote:
>>
>>> const
>>>     wm_MyCustomMessage = wm_user + 2006;
>>>     // any # is good here as long as it's not used elsewhere in your
>>> app
>>
>> And what is wm_user? It's flagged up as undefined identifier :-(
>
>
> Add Windows to your Uses clause (for all 4 reported problems I see
> currently).
>

I've tried adding Windows but then I get something really weird: the  
"Show" in Messagebox.Show isn't recongised any more... BTW, I'm using  
D2005, maybe things are better in 2006...
Re: one form influencing another
#249
Author: Wayne Niddery [TeamB]
Date: Fri, 08 Sep 2006 15:05
18 lines
2001 bytes
Brigitte Spatz wrote:
>
> I've tried adding Windows but then I get something really weird: the
> "Show" in Messagebox.Show isn't recongised any more... BTW, I'm using
> D2005, maybe things are better in 2006...

My apologies, I didn't realize which group I was in - you're developing a 
.Net app, so you *do not* want to add Windows to your uses clause, and my 
custom message suggestion isn't really appropriate.

Going back to your original post, you indicate an error message when you try 
to call Close_All, How are you trying to call this? If it is a public method 
of your main form then you should be able to call it.

-- 
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"At the apex of every great tragedy of mankind there stands the figure
of an incorruptible altruist." - Ayn Rand 
Re: one form influencing another
#1
Author: Brigitte Spatz
Date: Mon, 11 Sep 2006 08:58
17 lines
2228 bytes
Wayne Niddery [TeamB] wrote:
> Brigitte Spatz wrote:
>> I've tried adding Windows but then I get something really weird: the
>> "Show" in Messagebox.Show isn't recongised any more... BTW, I'm using
>> D2005, maybe things are better in 2006...
> 
> My apologies, I didn't realize which group I was in - you're developing a 
> .Net app, so you *do not* want to add Windows to your uses clause, and my 
> custom message suggestion isn't really appropriate.
> 
> Going back to your original post, you indicate an error message when you try 
> to call Close_All, How are you trying to call this? If it is a public method 
> of your main form then you should be able to call it.
> 
I tried mgds.Ground.Close_All; where mgds is the unit, Ground is the 
class (Ground = class(System.Windows.Forms.Form)) and Close_All is a 
public method.
Re: one form influencing another
#2
Author: Wayne Niddery [TeamB]
Date: Mon, 11 Sep 2006 15:17
16 lines
1880 bytes
Brigitte Spatz wrote:
>
> I tried mgds.Ground.Close_All; where mgds is the unit, Ground is the
> class (Ground = class(System.Windows.Forms.Form)) and Close_All is a
> public method.

Ok, that's a problem - Ground is the *class type* not an instance of that 
type. You need to have access to the instance. If Ground is the type of your 
main form (and I'm assuming you are using VCL.Net) then try this:

    Ground(Application.MainForm).Close_All;

-- 
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"Nurture your mind with great thoughts. To believe in the heroic makes
heroes." - Benjamin Disraeli 
Re: one form influencing another
#3
Author: Brigitte Spatz
Date: Tue, 12 Sep 2006 14:42
6 lines
1551 bytes
Wayne Niddery [TeamB] wrote:

> main form (and I'm assuming you are using VCL.Net) then try this:

No, I'm using FCL (at least that's what I think Winforms refers to). 
Cor, wasn't life easy when there was just one Delphi - LOL.
Re: one form influencing another
#4
Author: Wayne Niddery [TeamB]
Date: Tue, 12 Sep 2006 17:51
27 lines
2537 bytes
Brigitte Spatz wrote:
>
> No, I'm using FCL (at least that's what I think Winforms refers to).
> Cor, wasn't life easy when there was just one Delphi - LOL.

Ok. Then I assume that there is some action (e.g. a button or menu item) 
that is creating and displaying the second form. Therefore it is possible 
for you to pass a reference to the main form to this second form, and then 
the second form is free to call any public method or access public 
properties of the main form.

E.g. If the main form class is named TWinFom1 and the form you want to call 
Close_All from is TWinForm2, then:

- Add WinForm1 to the uses clause of WinForm2.
- Add a public field in TWinForm2 of type TWinForm1 (let's call it Form1: 
TWinForm1;)
- in the TWinForm1 procedure that creates and displays TWinForm2, after 
creating it, set its Form1 field to Self (Self will refer to the TWinForm1 
instance that is running).
- Now anywhere in TWinForm2, you should be able to call Form1.Close_All.

-- 
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"Some see private enterprise as a predatory target to be shot, others
as a cow to be milked, but few are those who see it as a sturdy horse
pulling the wagon." - Winston Churchill 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads