Topic: Make a non-Visible field Visible

Hi all,
I'm venturing into an area where I'm a total novice - scripting.  I have been able to understand the scripts that you folks have provided (many Thanks), but I'm not yet able to create them on my own.
-
Having said that maybe you can help me to learn.  Here's what I would like to do.
I have a field called RentOwn. And another called hPurchaseDate.
I would like to have PurchaseDate be Invisible unless RentOwn = Own
-
Here's what I tried and it doesn't work.  I just read that the condition of an If statement needs to be Boolean so I can see why it's probably not working.
-
procedure frmHousing_cboRentOwn_OnExit (Sender: TObject);
begin
      if frmHousing_cboRentOwn = "Own" then
        frmHousing_hPurchaseDate := Visible
end;
-
Maybe you could steer me in the right direction.
-
Thanks, Frank

2 (edited by ehwagner 2020-10-06 19:26:58)

Re: Make a non-Visible field Visible

Frank,
Typically an object on a form has three parts to it. The form name that the object belongs to, the object (field name), and the property of the object. So it usually looks like this: formname.fieldname.property. An example is Form1.Edit1.Text

Therefore your If statement should be:

if frmHousing.cboRentOwn.Text = "Own" then
        frmHousing.hPurchaseDate.Visible := True else frmHousing.hPurchaseDate.Visible := False; 

Re: Make a non-Visible field Visible

Thanks for your help.
So far it's not working for me and here's what I have:
-
procedure frmHousing_cboRentOwn_OnExit (Sender: TObject);
begin
    if frmHousing.cboRentOwn.Text = "Own" then
       frmHousing.hPurchaseDate.Visible := True else frmHousing.hPurchaseDate.Visible := False;
end;
-
I get an error saying that it wants Then right before the = sign
I'm not sure why it is getting this error?
-
Also now that I think more about it, I really would like hPurchaseDate to not be visible when the form is first opened ...unless cboRentOwn = Own.
This assumes that it is a record that has already been created and cboRentOwn = Rent.
-
The other situation is if I'm adding a new record then hPurchaseDate should not be visible until I enter Own into the cboRentOwn field. Then hPurchaseDate should be visible so I can put data into it.
-
I could just leave all the fields visible but I'm thinking it would be nicer if hPurchaseDate only became visible when I say I Own the property.
-
Thanks for looking into this for me, Frank

Re: Make a non-Visible field Visible

seems ok. try

frmHousing.hPurchaseDate.Visible := (frmHousing.cboRentOwn.Text = "Own");
brian

5 (edited by derek 2020-10-07 00:08:20)

Re: Make a non-Visible field Visible

Hi Frank, Hi EHW,
I think the error message you get is because it wants single quotes rather than double quotes.
The other thing I'd do is probably have your code triggered by frmhousing_cborentown_onchange (ie on change rather than on exit) so it actions immediately.  But we all have our own peculiar ways of doing things - neither's right nor wrong.
Please see the attached as an example of what you want to achieve.
One thing to note in the example (again it's option but I do it because it's easier!) - the hpurchasedate edit field presumably has a label and you'd want both edit field and label to be invisible if the status is 'RENT'. 
You can either code for both of these in your script OR you can place hupurchasedate AND the label onto a panel and then you only have to code for the panel in your script.  This is because all objects that are placed on a panel are subordinate to that panel and take on the panel's properties (in other words, make the panel invisible and you make hpurchasedate and its label invisible at the same time). 
It's a real time saver when you have a large number of fields - if they can be grouped together on a panel, you only need to make one change in your script.
Just shout if something's unclear.
Derek.

Post's attachments

Attachment icon frankvisible.zip 338.01 kb, 211 downloads since 2020-10-07 

Re: Make a non-Visible field Visible

Derek,
You are right - it was the double quotes.  I changed them to single quotes and it's now working.
-
Yes, I do have a label for the field, and I also have more fields like Purchase Price, Sales Date and Sales Price which I want to behave the same way. I figured if I could hide one field then I would apply the same code to the other fields and labels.
-
I also applied this 'fix' to the OnShow event so when I'm adding a new record it will NOT show the Purchase stuff unless I add an 'Own' field. So far that's working OK.
-
I do like your idea about putting my OWN fields on a panel.  However, I have what I perceive as a problem with panels.
Currently I'm using a couple of panels on some forms, however I have to put them at the bottom of the form in order for TABBING to work.
-
I like for users to be able to TAB through the form as opposed to having to use the mouse to select the fields.
-
Here's an example of what I'm seeing when using a panel:
Field 1 = Tab order 1
Field 2 = Tab order 2
Panel field 1 = Tab order 0
Panel field 2 = Tab order 1
Field 3 = Tab order 3
-
The Tabbing will go from Field 1 to Field 2 then skip over Panel field 1 and go to Field 3. Then after Field 3 it will finally go back up to Panel field 1.
-
Panels seem to have their own order for the fields?  When I try to make Panel field 1 to be Tab order 3, it doesn't work.
-
On my current form I don't want to put the Sales panel on the bottom, so I don't know how to put it in the middle of the form and still follow the Tabbing sequence.
-
Maybe you have some ideas?
Thanks, Frank

7 (edited by CDB 2020-10-07 07:25:13)

Re: Make a non-Visible field Visible

Frank,

If you look at each component you have on your form you will see they all have a TAB property.

This is where you set the tab order yourself instead of leaving it to MVD to allocate.

One way around this is to place the components on the form in the order you want them - however, who knows exactly their layout until the end?

The first tab item will be 1 and each tab item will increment. Just change the numbers to the order you want.

Just for extra information, if you don't want an item to react to a tab just untick the TabStop property.

Post's attachments

Attachment icon tab_order.PNG 52.19 kb, 109 downloads since 2020-10-07 

On a clear disk you can seek forever

8 (edited by derek 2020-10-07 19:52:54)

Re: Make a non-Visible field Visible

Hi Frank,
Try it using a groupbox instead of a panel.  A groupbox has a 'tab order' property (see the attached screenshot), unlike a panel, so you can sequence it wherever you want on your form.  Then within the groupbox, each field has it's own sequence (a bit like a 'sub-sequence' number)..
In your example, MVD should now tab into the groupbox in the correct sequence (if it's an 'own') or tab to the next field (if it's a 'rent').
Please see the attached with a few extra fields thrown onto the form just to demo it.
I don't know of a way to get rid of the bevel around a group box (you can get rid of it's caption) but that's probably okay because it's a neat enough way of visually grouping any related fields together (guess that's why they call it a 'groupbox' - LOL!).
This might also solve the problem you mentioned with having to put panels at the bottom of forms to maintain your desired tab sequence.
Derek.

Post's attachments

Attachment icon frankvisible 2.zip 487.94 kb, 217 downloads since 2020-10-07 

Re: Make a non-Visible field Visible

Derek, CDB
Thanks for the suggestions.
-
The GroupBox works great.  It solves the problem of assigning Tab Orders from inside a Panel.
-
Question: when I'm using panels, I sometimes change the Color so they stand out from the other fields.  Is there any way to change the background color of a GroupBox?  I haven't found a way so far?
-
However, I am able to put a Panel behind the GroupBox and set it to a different color.  So that'll put a border around the GroupBox. But it would be nice to be able to set the GroupBox background to a different color.  Sometimes I like to use colors to make certain fields stand out.  But over the years I've also learned to be careful because too many colors can make a form messy.
-
Thanks, Frank

10 (edited by derek 2020-10-08 00:06:08)

Re: Make a non-Visible field Visible

Hi Frank,
I know what you mean about overuse of colours - major migraine!
Try the attachment and let me know if the groupbox changes colour.  If it does, all well and good - if not, then I think it's one of the options that became unavailable after Windows 7 (it works for me using MVD Version 6 + Windows XP as you can see from screenshot2 in the attachment).
Derek.

Post's attachments

Attachment icon frankvisible 3.zip 526.46 kb, 238 downloads since 2020-10-08 

Re: Make a non-Visible field Visible

Derek,
The Yellow color in your example does show up but only for the Caption of the GroupBox1.  Not the GroupBox itself.  I actually did try that command when I was trying to figure out how to change the color of the GroupBox.  And I got the same result. It's not a problem for me though. Sometimes I try colors when I can just because I think it might be nice, then more often than not I delete them because it's too messy looking.
-
I think there are times where colors make sense but only when really necessary.
-
FYI - I've been working on trying to implement your GroupBox code into my project.  And for the last few hours I've been pulling my hair out because I couldn't get it to work. Not that I really have any hair to pull out - but you get the idea.
-
So I finally found the problem.  Your program uses the words 'OWN' and 'RENT'.  But my table uses 'Own' and Rent.
-
I think you did that on purpose just to make me work harder 

Re: Make a non-Visible field Visible

LOL!  No, it wasn't done on purpose.
I pretty much always populate my look-up tables in uppercase - just force of habit, I guess.
Derek.

Re: Make a non-Visible field Visible

Derek,

I had put a smiley face after my last comment but it got cut off.  I also went on to say that it was a good learning experience for me.  I went through the code line by line to see why it wasn't working. So I learned more about scripting and I now appreciate the difference with upper/lower case in a text field.
-
Thanks again for all your help, Frank