• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Visual Form Inheritance question

Hi folks,

I need to create a custom TForm which will include a Toobar, Statusbar and  a listbox.  The form must also have code added to it to adjust sizing of the form (setting the client height/width in the FormShow event) and a few extra things.

I would then like this form to be able to be added to my project by going File|New|Other->TStusForm (or something).

Can someone tell me how I do this please?

Many thanks,

Stuart.
0
SJohnson
Asked:
SJohnson
  • 4
  • 4
  • 3
2 Solutions
 
kretzschmarCommented:
as i have it correct in my head,
just design your formclass and use the option "Add to repository"

meikl ;-)
0
 
geobulCommented:
Hi,

When you finish the design of the form select 'Project-Add to Repository' from the menu, describe the form, press OK. You can now create/inherit new forms from that one using 'File-New-Forms tab'.

Regards, Geo
0
 
geobulCommented:
Hi meikl ;-) I'm drinking my first cup of coffee while writing my first post in Ex-Ex for the day and what a surprise - meikl. Isn't it too early in the morning for you?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kretzschmarCommented:
:-)) its not too early in the morning (currently its 8:05am),
but i have similar done as you (drinking my first cup of coffee) one hour before

meikl ;-)
0
 
SJohnsonAuthor Commented:
OK, scuse the ignorance here, but if I do File|New|Form' and then try to add it to the repository, the option is disabled.  The only way I can seem to do it is by first creating a new project, then adding that to the repository.

However, that doesn't really give me what I'm after (completely).  I also need to be able to hide properties (like if I was creatin a custom control).  I specifically need to hide Height, Width, ClientHeight and ClientWidth.

Cheers.

Stu
0
 
SJohnsonAuthor Commented:
Further:

This works for half of what I want to do, but not quite.

If I create my form, then add it to the repository, it's only there fore as long as the project is running.  As soon as I close, I can not longer create a form based on that class unless I add that project back into the main project again.  I want a form available at all times from the File|New|Other dialog.

I just did a simple test and tried to set the client height/width in the FormCreate event, and it never fired in the designer.  I need to be able to automatically set the ClientHeight/Width when the form is initally created.

Am I asking to much now?

Thanks guys


Stu
0
 
geobulCommented:
Sorry, Stu. My mistake. To add a single form (not the whole project) to the repository right-click on the form and select 'Add to repository' from the pop-up menu.

New forms (copied from repository) appear in the designer as they have been added to the repository. Your FormCreate is there and will be executed in run-time.

Do you want to hide Height, Width, ClientHeight and ClientWidth from ObjectInspector? I'm not sure if that's possible for forms.

Regards, Geo
0
 
SJohnsonAuthor Commented:
Hi Geo,

Thanks.  That works great.

Just one final question.  The reason for doing this is to replace all the standard TForms in our application with a form which contains some standard code we need in every form.  Our original goal was to create the form, then open our project and replace TForm with our custom form class.  However, this doesn't seem to work because the code that's in the custom form isn't automatically added to the project as we're not adding the form to the project, we're manually replacing a form.

Example.  

We've got a form with a OnCreate method.  We add a bit of code to this method.
We modify the DFM to say TForm1 is no longer a TForm, but a TExampleForm.  TExampleForm has an OnCreate method, but the code is not used when the form is used like this.

If we add a new form (using File|New|Other), the form is created, as to is all the extra code.

I guess what I'm trying to say is, I need the code that's in those events available all the time.

Do you think it's possible at all?

Thanks again for your help.

Stu
0
 
geobulCommented:
Hi,

You already have a project with forms derived from TForm, right? And you want to modify these forms as they were initially created using TExampleForm from the repository. The way I can think of is: you may use that TExampleForm as an ancestor of the forms in the project.

- Add TExampleForm to the project and extract it from the auto-create list. This form won't be created but used for deriving the other forms.
- For every form add TExampleForm's unit in the uses clause and replace TForm with TExampleForm:

type
  Form2 = class(TExampleForm)
...

The code of TExampleForm won't be visible in this unit (where TForm2 is declared) but will be executed in run-time. When you're creating new forms in the future and are using the repository there are two options - copy and inherit (there is also Use but it's out of interest now). What I'm trying to say is that Inherit option does exactly the above.

On the other side Copy option does what you're after but this automatically works for new forms only.

So, you may inherit your forms from TExampleForm and don't see its code or inherit your forms from TForm and manually copy TExampleForm code in all your forms.

If meikl can make up something better it would be nice.

meikl, what do you think?

Regards, Geo
0
 
kretzschmarCommented:
>meikl, what do you think?

usual i had nothing to append, you described already the two possibilties i had also in mind

- replace the ancestor (unit must then included into the uses clause)
- inherit from the repository

meikl ;-)
0
 
SJohnsonAuthor Commented:
Mmm. OK.  It hasn't quite done what I wanted to do.  I was hoping the end result would be a lot easier.

Thanks very much Geo and Meikl.

Stu
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now