Solved

C++ Builder enable button

Posted on 2003-11-13
10
867 Views
Last Modified: 2009-12-16
Hello This is a simple question

I created an MDI project, C++ Builder creates a main form child form etc. However on the main form there is a toolbar. The save button on this bar is always disabled. I can't figure out where and how these tool bar buttons are enabled and disabled. For example when I open a new document, a child window is created, when i select some text in this form the cut, copy and paste buttons become enbled.

Unfortunately the save button never becomes enabled. Anyone know where these buttons are being enabled/disabled, I can't see it in the main form code or the child form code.

Regards
0
Comment
Question by:auk_ie
  • 5
  • 4
10 Comments
 
LVL 13

Expert Comment

by:SteH
Comment Utility
In a MDI app I would assume that there is something like a document class which should have a property or method called something like modified. Change this and saving should be enabled. The idea behind: A document opened not changed doesn't need to be saved and so the button is disabled. Only when it is altered it needs saving and the button is enabled. Since I don't have BCB available here I can't give you more details.

0
 
LVL 12

Expert Comment

by:andrewjb
Comment Utility
You need to write a handler for the action.

On the main form, there's an ActionList. Double-click this, and click on the 'FileSave1' item. Then look in object inspector, and it's got an OnExecute event. You need to put something in here.

( A simple ; will do to start with - so long as the handler exists, the button is enabled and the handler is called. The default project doesn't implement saving or loading for you, though. )
0
 

Author Comment

by:auk_ie
Comment Utility
Hello andrewjb

The only onexecute event handlers I can see in main.cpp are

FileNew1Execute
FileOpen1Execute
HelpAbout1Execute
FileExit1Execute

I don't know where the other handlers are for the other default functionality added

for eg, In the object inspector I see the buttons have certain actions

for eg

FileOpen1
EditCopy1
FileSave1 (This is added to the save button I want to enable)
WindowCascade1...........etc.....etc

But how can I modify the functionality of any of these actions. I see them defined in the main header file as

        TAction *FileNew1;
        TAction *FileSave1;
        TAction *FileExit1;
        TAction *FileOpen1;
        TAction *FileSaveAs1;

But I have no idea as how to modify these actions. And I don't see where the actions are being implemented from.

Kind Regards
0
 
LVL 12

Expert Comment

by:andrewjb
Comment Utility
Find the ActionList on themain form.
Double-click it. This opens to show you the actions.
Find FileSave1
Dbl-click this;
That defines you an OnExecute event handler. It will initially be empty. For now, just put a ; between the { and } so the function doen's disappera.
Compile.
The save button will be enalbed, though at the moment it doesn't do anything.

0
 

Author Comment

by:auk_ie
Comment Utility
Thanks andrew, That about answers my question, I figured this out last night, but doing it this way you loose the default functionality C++Builder added to my save button, ie FileSave1. I have to reimplement that. I only wanted to modify this function. If I had to go around and re-implement from scratch all the different actions c++builder added, that would be a pain.

I really don't understand when C++ bulider declares

TAction *FileSave1; //in the main header

and then adds FileSave1 to the action property of the save button. How does that work? Where's the implementation for the save button functionality (in essesnce so I can modify it instead of writing a new function from scratch).
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:andrewjb
Comment Utility
There _is_ no implementation of the save mechanism. You have to do it yourself.... It just don't save anything. Nowhere, not ever.

The TAction you see is the one in the actionlist on the form, and you're going to have to tell it _how_ to save. How can it save when it doesn't know what data you'll be editing?

Andrew.
0
 

Author Comment

by:auk_ie
Comment Utility
But what about the cut button, That has an action called EditCut1

again this is declared in the header as TEditCut *EditCut1;

but I can't see any implemenation for it. So I can't modify.

There is a whole list of these type of buttons and I for some reason can't see where they are implemented, the paste, copy and tile window functions are other examples.

0
 

Author Comment

by:auk_ie
Comment Utility
I just want to know where is this functionality coming from
0
 
LVL 12

Accepted Solution

by:
andrewjb earned 250 total points
Comment Utility
I think cut / copy etc just pass the CTRL-X etc to the memo which implements it.

'New' and 'Open' are implemented in code.

Others aren't implemented at all - go into the action manager, find the action, and dbl-click to define your own procedure.
0
 

Author Comment

by:auk_ie
Comment Utility
So basically the default functionality can't be modified, what a pain! Thanks anyway.

Andrew will you look at another question for me please,

The URL is

http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20798366.html
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now