Jump to content
Sign in to follow this  
Chris1701

Change a forms OnShow Event?

Recommended Posts

I'm using Delphi 12.2. Patch 2 and I'm trying to accomplish something that I've never had to do and I'm having a problem figuring it out.

 

I have a dialog that is created and then called and freed by a particular form; this dialog is written with a default OnShow event. Now I've discovered that I want to reuse that dialog in another place however the OnShow event is not correct for that 2nd usage and before I use .ShowModal I want to either blank the OnShow event or reassign it to a different event that has the correct code for the 2nd usage and so far the things I've tried have failed:

First thing, I know for something like a TButton you can set the OnClick event to Nil i.e. Button.OnClick := Nil; but MyDialogForm.OnShow := Nil; after the form is created "MyDialogForm := TMyDialogForm.Create(Application);" shows an error of E2025 Not enough actual parameters; likewise if I create an alternate OnShow procedure "procedure TMyDialogForm.OnShowNoProc(Sender: TObject);" and then after the dialog is created but before it's called I try MyDialogForm.OnShow := MyDialogForm.OnShow := MyDialogForm.OnShowNoProc;; I end up with the same error message Not enough actual parameters.

 

What what am I doing wrong here, how can I either set the forms OnShow to Nil (do nothing) or reassign the OnShow event to an alternate procedure?

Share this post


Link to post
11 minutes ago, Chris1701 said:

What what am I doing wrong here

Hard to tell with no code to go by. Regardless, one thing you could do is add a property to the form (e.g. a Boolean) to indicate what it should do when OnShow is called, use an if statement to determine which code is executed, and set the property before ShowModal is called

Share this post


Link to post
16 minutes ago, Dave Nottage said:

Hard to tell with no code to go by. Regardless, one thing you could do is add a property to the form (e.g. a Boolean) to indicate what it should do when OnShow is called, use an if statement to determine which code is executed, and set the property before ShowModal is called

Ok that's an alternate way to do it but still doesn't explain why can't I set the dialogs OnShow property to nil to do nothing or set it to an alternate compatible procedure to do something different?

Share this post


Link to post
17 minutes ago, Attila Kovacs said:

you have overriden the OnShow property with your OnShow procedure. Rename it.

I have tons of programs with forms that have an OnShow procedure that the forms OnShow event calls and I've never had an issue; and even if that is true that doesn't explain  why can't I set the dialogs forms OnShow property to nil to do nothing or set it to an alternate compatible procedure to do something different?

Share this post


Link to post
Just now, Chris1701 said:

and even if that is true that doesn't explain  why can't I set the dialogs forms OnShow property to nil to do nothing

You are calling your OnShow method, it's not the property, the property is invisible because you have overriden it.

Learn the basics of OOP.

Share this post


Link to post

It's really hard to understand what you are doing from your description. Please show us the code of a minimal example instead (and please use the code tag).

// Like this

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×