Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

About component building

Posted on 2002-04-28
5
Medium Priority
?
168 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 400 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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

782 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