Topic: Button click

Hello all,

I know this is and old question, that has already been asked a lot, but I'm not sure this can not be done, so I ask the questions differently.


I have a customised message form, warning the user that he is going to delete data from the database.

On the form are 2 buttons, one for cancel, and one for confirm.

Of course, I can set two on_click procedures to cancel and confirm the action, but in that case, this form is not reusable.

What I would like to achieve is, from the form that opened the warning message, detect which button is clicked and act accordingly in the same procedure that started the message.

Here is the code :

procedure categories_Button11_OnClick (Sender: string; var Cancel: boolean);
var
    minor_cat_id : Integer;
    m_cat_usage : Integer;
begin
    minor_cat_id := categories.TableGrid3.dbItemID;
    m_cat_usage := SQLExecute('SELECT COUNT(id) FROM asset WHERE id_minor_cat="'+IntToStr(minor_cat_id)+'"');
        if m_cat_usage > 0 then
            begin
                //ShowMessage(minor_cat_id);
                cmessage.Show;
                cmessage.Caption := 'Warning : Minor Category Assigned';
                cmessage.LbCMessage.Caption := 'The Minor Category you tried to delete is assigned to '+IntToStr(m_cat_usage)+' assets(s)'+#13#10#13#10+
                                               'If you click Confirm, all asset assigned with this category will be'#13#10+
                                               'assigned instead, the default value (None Assigned), and this minor'+#13#10+
                                               'category will be deleted'+#13#10#13#10+
                                               'Do you confirm this choice ?';
            end
        else if m_cat_usage = 0 then
            begin
                SQLExecute('DELETE FROM minor_cat WHERE minor_cat.id="'+IntToStr(minor_cat_id)+'"');
                categories.TableGrid3.dbUpdate;
            end;
end;

in the

if m_cat_usage > 0 then

after the warning message, I would like to add something like :

if button1.Click = true then
     begin

    .....................

     end

but of course the Click = True does not exist.

Do you see another way ? Or do I have to create as many warning message forms as I have situations requiring them ?


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Button click

I made an example for you:

Post's attachments

Attachment icon Custom Message box.zip 3.76 kb, 727 downloads since 2016-01-19 

Dmitry.

Re: Button click

Hello Dmitry,


I had to work a little to adapt your example, but this works fine !!


I love :
- being able to reuse a single warning window instead of creating multiple
- detection of the button that was clicked
- the Caption and Message variable that I set differently to suit my needs.


Great job and thanks a million !!


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor