Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2023-02

How to make TBitButton set the ModalResult properly and close the form?

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I am porting a Windows application from Delphi2007 to Lazarus/Fpc and have run into problems with the dialog forms used in the app. They are all provided with two TBitButton buttons, one for OK and the other for Cancel.

But unlike how it works on Delphi when I use any of these when running the ported app nothing at all happens! Luckily I have kept the close button on the form border so it can be closed that way.
But then I cannot get any confirmation back to the main application...

So in order to fix this on the first form I have had to implement the OnClick event and code the following into them:

ModalResult := mrOk
(or mrCancel) as needed.

This causes the wanted behaviour.

But this was not how the Delphi TBitButton operated, why has it changed? And is there some way I can restore this functionality without having to add OnClick event handlers to all of these buttons?
Some special $MODE setting perhaps?

The Delphi converter I used in Lazarus to port the application put {$MODE Delphi}
into most units..

I have a queue of utilities I need to port so it would be good not having to deal with all of these dialogs...

Bo Berglund Developer in Sweden

Reply by email

gabor
to Bo Berglund

W dniu 2023-02-11 o?21:15, Bo Berglund via lazarus pisze:

Show quoted text 31 lines
I am porting a Windows application from Delphi2007 to Lazarus/Fpc and have run into problems with the dialog forms used in the app. They are all provided with two TBitButton buttons, one for OK and the other for Cancel. But unlike how it works on Delphi when I use any of these when running the ported app nothing at all happens! Luckily I have kept the close button on the form border so it can be closed that way. But then I cannot get any confirmation back to the main application... So in order to fix this on the first form I have had to implement the OnClick event and code the following into them: ModalResult := mrOk (or mrCancel) as needed. This causes the wanted behaviour. But this was not how the Delphi TBitButton operated, why has it changed? And is there some way I can restore this functionality without having to add OnClick event handlers to all of these buttons? Some special $MODE setting perhaps? The Delphi converter I used in Lazarus to port the application put {$MODE Delphi} into most units.. I have a queue of utilities I need to port so it would be good not having to deal with all of these dialogs...

Have you set the TBitButton.ModalResult property or TBitButton.Kind property appropriately?

Micha?.

Reply by email

Bart
to gabor
PM gabor wrote
Have you set the TBitButton.ModalResult property or TBitButton.Kind property appropriately?

This would normally also set ModalResult to mrOk (Kind := bkOK) or mrCancle (Kind := bkCancel).
Setting the modalresult to those values should be enough (no OnClick needed) to close the modal form.
It definitively does so for me.

Bart

Reply by email

Salvatore Coppola
to Bart

Did you call the form with Form2.ShowModal?

Ottieni BlueMail per Android

Il giorno 11 Feb 2023, 23:26, alle ore 23:26, Bart via lazarus ha scritto:

Show quoted text 19 lines
On Sat, Feb 11, 2023 at 9:26 PM gabor via lazarus wrote: > Have you set the TBitButton.ModalResult property or TBitButton.Kind > property appropriately? This would normally also set ModalResult to mrOk (Kind := bkOK) or mrCancle (Kind := bkCancel). Setting the modalresult to those values should be enough (no OnClick needed) to close the modal form. It definitively does so for me. -- Bart -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20230212/0a1ce8b8/attachment-0001.htm>

Reply by email

Bo Berglund
to Bo Berglund: I am porting a Windows application from Delphi2007 to Lazarus/Fpc and have run into…
Bo Berglund wrote 16 lines
So in order to fix this on the first form I have had to implement the OnClick event and code the following into them: ModalResult := mrOk (or mrCancel) as needed. This causes the wanted behaviour. But this was not how the Delphi TBitButton operated, why has it changed? And is there some way I can restore this functionality without having to add OnClick event handlers to all of these buttons? Some special $MODE setting perhaps? The Delphi converter I used in Lazarus to port the application put {$MODE Delphi} into most units..

It might be the converter that does this...
It made a new lfm file from the dfm that Delphi had made and maybe it did not transfer the button kind properly so that the modalresult was not set as it would be when the kind was selected...

Anyway by going over the forms and changing ModalResult to the proper value depending on the Kind property value made it work as expected. No OnClick event handler needed.

Now working properly.

Bo Berglund Developer in Sweden

Reply by email