How to make controls on a form non-editable?

HI all,

how to make controls on a form non-editable , when performing Push-action for a button.

I set a Push-action property for a button on a form , when i perform push-action , it opens a form.when form opens , some controls shd have to be turned into non-editable …

Plz help me in this case…

Regards

venu

So these fields should be put into non-editable mode only when the form is called by this specific command button and not when called from somewhere else ?

ya , exactly …

In the form you need to define a new function which switches Editable ON/OFF in the form where you want to have the controls editable or not.

  • Define a new function with a bool “NewEditable” parameter
  • Add a “CurrForm.Control.EDITABLE := NewEditable;” line to that function for each control you want to switch editable mode on or off
  • Call this function from the command button before you call the RUN/RUNMODAL of the form

That’s a pretty smart solution, but be aware that that would also mean that all of those controls would not be editable by default. You would have to add the call from all places that this form is used, and possibly replace simple RunObject button actions with a few lines of code.

Hi Daniel,

Is this also the case if the controls are editable-property is set to Yes to begin with.
As long as the new function is not called, then all controls will be editable.
So basically you only have to modify existing calls of the form, if you want this limited editability instead.

Hi Guys,

Why not just invert Thomas solution i.e.

  • Define a new function with a bool “NewDisabled” parameter
  • Add a “CurrForm.Control.EDITABLE := NOT NewDisabled;”

Then opening the form without calling the function will have the controls enabled

In case it does not matter if or not or which way round to define the parameter:

In the OnInitForm trigger just call “EnableFields(TRUE)” will “initially” enable all fields and only call the “EnableFields(FALSE)” from the command button will disable the fields if required.

Yes indeed, it is the same as when the editable property is set to yes in the property. BUT, if you set EDITABLE to an uninstantiated boolean variable in OnInitForm or OnOpenForm (or through a function call in one of the triggers), then it will be set to that variable’s default value, which for a boolean is FALSE. Without actually setting that value to TRUE, controls will not be editable.

The purpose of my comment is just to make people aware that you have to be aware of this. Be aware of the variable’s default value, and make sure you are setting the EDITABLE property of the controls properly for when the form opens without having called the custom function.

… and that’s way I suggested inverting it.

Exactly Dave, you got it [Y]

Of course nothing wrong with using the other way around, as long as you are aware that the default will not be editable.

Hi thomas,

I have 2 fields Status whch has editable property =NO And Task whch has editable property set to yes ,

Now when i open this form frm a command button , Status shd be turned to editable & Task shd be non-editable.

For tht in that form i have created a function vth 2 bool parametrs called edit1,edit2.

And i wrote code like Currfrom.task.editable=edit1;

Currfrom.task.editable=edit2;

And in the command button On-Push trigger i Wrote

Form variable.function(TRUE,FALSE);

form.run()

BUT ITS NOT Working…

I would use the following function:

SetStatusEditable(NewStatusEditable:bool)

CurrForm.Status.ENABLED := NewEditable;
CurrForm.Task.ENABLED := NOT NewEditable;

and set both fields Editable=true in the properties.

In the OnOpenForm trigger you call

SetStatusEditable(FALSE);

Hi Daniel,

I see that. And of course you’re right.

I didn’t understand your comment though, because Thomas never mentioned any function-calls in the OnInitForm- nor in the OnOpenForm-triggers before you made that comment.
And i thought that if my form is editable by default, why would i have to make a function-call to make it editable.

When you do not call the function, the system will assume that the fields are editable/non-editable as defined in the properties. These settings are NOT part of the zup-file and therefore not restored when reopening the form.

So only if you want to change the default settings from the property, you would call that function - and this is what has been asked in this thread.

The call in the OnInitForm trigger is actually useless and just to make people feel safer.

removed rant, it’s uncool to lose your cool

Sorry thomas, i cant change d editable propertys of those fields .

And if i write tht code in on-open form trigeer , the code wll be executed whenever i open tht form , I dont want this actually …

Instead the code shd be executed for a certain Button -action only…