Solved

About component building

Posted on 2002-04-28
5
155 Views
Last Modified: 2010-04-04
I need help on this:
  To build a component with a button on it, when the button is clicked, a dialog style form will be displaying,
on this form:
           1. certain buttons like OK, Add.
           2. when button OK on the form is clicked, the form is closed, an event e.g. OnCancel in the component will be connected to the OK button's OnClick event.
           3. the component will get certain result calculated at the form when OK button is clicked, an event AfterCalc in the component is fired.
 
  my problems: how can I have a component like this with its properties and event handlers that relate to a form that is only create when requied  
0
Comment
Question by:JasBei
5 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6976509
Simply set the ModalResult properties of the buttons on the modal form.
Connecting an OnCancel event is not needed and not (easily) possible.
Move your modal form in Project : Options : Forms to the rigt list.
In the OnClick of the main form button do something like this:
var
  ModRes: Integer;
begin
  ModForm := TModForm.Create(Self);
  ModRes := ModFrom.ShowModal;
  if ModRes = mrOK then
  ...
  ModForm.Free;
0
 

Author Comment

by:JasBei
ID: 6979129
I would like to clarify my problem:
      I tried to use a mordal form just as you have pointed out, but if on the mordal form there is a button I would like to use it to fire an event in my component, and this button is not going to shut the mordal form after all this happening, so I couldn't use ModResult here.
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6979473
You can always call methods of the main form in response to the button click on the modal form.
0
 
LVL 4

Accepted Solution

by:
nestorua earned 100 total points
ID: 6981723
HI,
If I am not mistaken you don't know how to create a component which has a button as a part of it and this "part" has its own event OnClick?
If so do the following (see an example):
TMyPanel=class(TPanel)
private
FButton: TButton;
FOnButtonClick: TNotifyEvent;
...
protected
 procedure MyButtonClick(Sender: TObject)
published
 property OnButtonClick: TNotifyEvent read FOnButtonClick
                                      write FOnButtonClick;
end;
...

constructor TMyPanel.Create(AOwner: TComponent);
begin
  inherited;

   FButton:=TButton.Create(Self);  
   with FButton do
    begin
     Left:=...
     Top:=...
     Parent:=Self;
     OnClick:=MyButtonClick;    
  ...
    end;
end;
procedure TMyPanel.MyButtonClick(Sender: TObject)
begin
  If Assigned(FOnButtonClick)
   then FOnButtonClick(Self);
end;

Sincerely,
Nestorua.
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9004269
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from nestorua

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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