Solved

About component building

Posted on 2002-04-28
5
156 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

21 Experts available now in Live!

Get 1:1 Help Now