How to read CurrForm.Field.EDITABLE inital values?

I’m currently working on a small functionality to make it possible to manage what fields are editable and what fields are not editable based on data in another table.

Extract from the code:

iss_FormSetup.GetField(‘MyFIELD’,“Record Type”);
IF CurrForm.“MyFIELD”.EDITABLE AND (NOT FormFieldSetup.IsEditable) THEN
CurrForm.“MyFIELD”.EDITABLE(FALSE);

The code piece is called from the form OnAfterGetRecord and again if the value in “Record Type” is changed. It works fine when the form is opened, as “MyField” is visible. But if the “Record Type” tells me that the field should be Not Editable, then when I change back the “Record Type” value, to a value which should be Editable, then it’s still not “Editable”. A quick look at the code of cause tells you why: It’s checking the CurrForm.MyField.EDITABLE value, which has just been FALSE.

If I removed this code, then it would work, but since we here talk about some generic I’m using in many tables, then it’s not so good, I would have to change this a lot of different places.

So what I’m looking for is really a way to look up the Initial value of the Editable property of the field? Is this possible?

I think the best way is to create globals that you initialize in the OnOpenForm and then test in the OnAfterGetRecord.

Thanks, why didn’t I think about this myself? [;)] Maybe because my programming is getting a bit rusty - actually coding is not what I do the most these days. Mostly I just take on a few development tasks for the fun of it, and to make sure I don’t forget it…

But do you have a suggestion how to work with forms in a more generic fashion? In example with tables it’s very easy to list the fields in the table, but it’s not quite that easy to get a list of active controls in a form. Or is there?

A long time ago there was version 2.01. For that version (and it also works for more recent versions) I created an advanced security system with roles that are added to other roles, field security, record security, logging.

To (partly) automatically do field security for a form, I had to export it as text. I had a function to import it into some tables to know which fields exist on the form and that could be secured. I also had a function to export the code to be put in the OnOpenForm-trigger (a function-call for each field). In the function I returned a value that decided that the field was visible+editable or visible+not editable or not visible.

So in short, you should create a table in which you put the form ID and the names of the fields. Another table in which you define the role (or the user) + the form ID + the name of the field + a field to define the security on it.

In the OnOpenForm, you call a function with the userID, the form ID, the name of the field (FIELDNAME(“The Field”) or ‘Some Name’ if the field is NOT a field of the sourcetable) and the return-value says what security you need to put on it.

hi if x=’’ i need to keep my particular fields in a record to be non editable can any body help me on this

You need to use CurrForm.“YourFields”.EDITABLE(FALSE);



field 1



Field 2



Field 3



Field 4



Field 5



Field 6



Field 7



Non editable



Non editable



Non editable



Non editable



Editable



Editable



TRUE



Editable



Editable



Editable



Editable



Editable



Editable



FALSE



Non editable



Non editable



Non editable



Non editable



Editable



Editable



TRUE

If my “Field 7” is TRUE the Field 1 to Field 4 should be Non Editable else all field should be editable.

Ok.

Then your code would be something like this:

IF Field7 THEN BEGIN
CurrForm.Field1.EDITABLE := FALSE;
CurrForm.Field2.EDITABLE := FALSE;
CurrForm.Field3.EDITABLE := FALSE;
CurrForm.Field4.EDITABLE := FALSE;
END;

or

CurrForm.Field1.EDITABLE(Not Field7);
CurrForm.Field2.EDITABLE(Not Field7);
CurrForm.Field3.EDITABLE(Not Field7);
CurrForm.Field4.EDITABLE(Not Field7);

thanks ernst

can put this code in OnOpenForm

No if you put it on the OnOpenForm trigger, then it will be the same for all records depending on the first record.

You should put it on OnAfterGetRecord trigger. Then it’s checked each time you get a record.

if i put the code in OnaftergetRecord trigger fields in all field r getting non editable .

but while trying in OnAfterGetCurrRecord its working as i required

thanks ernst.

But When i do that then all the records in the customer master getting non editable

My requirement is

When i mark the field as approved in the Customer master i need to make certain fields in the Customer master as in active

Regards

Narayan

Place the below code at OnActvate() of customer master form

if Approved then begin
CurrForm.“No.”.EDITABLE(true)
CurrForm.UPDATE’

end;

Thanks

Jerome Marshal.J