Solved

About component building

Posted on 2002-04-28
5
159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 186
creating threads in delphi 1 161
Installshield for Embarcadero EX 10.1 Berlin 4 72
IP without any Dots 1 52
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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