Topic: Hide a button

Hello All,

I have a new program and when it opens, the user sees an empty grid and a button to Add Owner.

The Add Owner button takes them to a form to add Owner information.  Once the Owner enters their data I would like to prevent them from entering another Owner.

I'm thinking that when the program opens, if the grid is not empty then maybe I could just hide the Add Owner button?

Then if the user later on deletes the owner, then the Add Owner button would become visible again.  So my Owner table would always have only one owner.

Thanks for your thoughts.
Frank

Re: Hide a button

If (Form1.TableGrid1.rowcount = 1) then form1.AddButton.visible ;= false else form1.addbutton.visible ;= true;

3 (edited by derek 2021-07-17 22:26:39)

Re: Hide a button

Hi Frank,
Long time no hear - trust all is well at your end.
I'm not sure if I understand your question totally but there seems to be a bit of a  'catch-22'. 
If you hide the 'add owner' button once an owner has been added, how does the user subsequently access the record to delete the owner (or do you also have a 'delete owner' button)?  In that case, I presume you'd want to toggle the visibility of both the 'add owner' and 'delete owner' buttons depending on whether an owner has been set up or not.
If your concern is that multiple 'owners' might get created, one option might be something like the attached (I like to keep life simple - LOL!) - doing it this way, no more than one record can ever be created..
(The extra bit of script is just a 'nice to have' so when you hover over the 'owner' button, it shows who it's currently set to).
Derek.

Post's attachments

Attachment icon papafrank owner.zip 340.21 kb, 189 downloads since 2021-07-17 

Re: Hide a button

blackpearl8534
Thanks for your suggestion.  It does what I want (almost).  Here's what happens:
- I open my START form.
- I click on my ADD OWNER button.
- It opens my OWNER form and I enter my information
- When I close the OWNER form it takes me back to my START form.
- However the ADD OWNER button is still visible.
- If I close my START form (this closes my program) and then re-open the program, the ADD OWNER button is not visible, as it should be.
- However I don't want to have to re-start the program.  I'm thinking that maybe I should refresh the START form when I go back to it.  I've been experimenting with some of the EVENTS and it helps, but not perfectly yet.  I'll keep working on it as I learn new things by just trial and error..  If you have any more thoughts please let me know. THANKS
.
DEREK
Yes, it's been a while.  I'm doing well, just getting older, YUCK.
.
I finished my project with the outstanding help from yourself and others on the forum.  Now I'm onto a new project and of course new challenges.
.
I checked out your example and I don't see how it limits the program to only one OWNER.  I must be missing something? 
Thanks, Frank

5 (edited by papafrankc 2021-07-18 16:08:17)

Re: Hide a button

blackpearl8534, derek

I believe I have found a solution that works for me.  On my START form grid,  I used the OnChange EVENT as follows:
.
procedure frmStart_GridOwner_OnChange (Sender: TObject);
begin
   If (frmStart.GridOwner.rowcount = 1) then
    frmStart.btnAddOwner.Enabled := false else
    frmStart.btnAddOwner.Enabled := true;
end;

.
Now when I add an Owner and come back to the START form, the ADD OWNER button is disabled (grayed out).  As you can see I used the code from blackpearl8534.  Note: I believe I can use either btnOwner.Enabled or btnOwner.Visible.  I'll take a look & see which one I think works best.  FYI - to Derek's earlier question, I do have 2 buttons - an ADD OWNER and a DELETE OWNER button.
.
So far this procedure seems to be working OK for me.  If you see anything that might be a problem please let me know.
.
Many thanks for pointing me in the right direction.
Frank