Dynamically set field's properties

Hi, all, I have a question about how to set field’s properties dynamically. For example, I know the field No. and name, and form no… Normally, we can use hard code to set properties. Like this CurrForm.Name.Editable = false But is there a solution which I don’t need to hard code? Thanks in advance.

Sorry, there is no way to dynamically set properties without writing code. The editable property only accepts values Yes or No. Some other properties (like the caption property) accept variables, but you’d have to write code to fill the variables. Maybe I don’t understand your question, but to me dynamic means writing code. How would you dynamically set a property without writing code?

Sorry,I didn’t describe my question clearly. My question is if I know the form no., the field no., how can I set this field’s property at the form? For example, I can use CurrForm.Name.Editable=False. If I need to set 20 fields’ property, I have to write 20 lines of code. What I am imaging is I can declare the field object since I know its field no… Therefore, I don’t need to write 20 lines of code. Maybe I can use a loop to run it. Or I can use CurrForm.FieldNo.Editable. Is there possible solution?

No, there is no way to address fields dynamically in Navision, you’ll have to go the 20 lines of code way. What you refer to is only possible for records and fields (recordref and fieldref). Saludos Nils

There is no easy way? hmm… not good news. But I found many ppl asked this issue before. Nobody gets a solution?

If you need to set the editable property for 20 fields, isn’t it easier to just set the Form’s editable property? Or maybe using 2 Forms?

This kind of code can get very messy. If you go ahead with this on one form you could try using 2 frames to group the fields together and place the frames over one another. On one frame you could have all the fields non-editable and on the other set them all as editable. You can then switch between editable fields or not by showing or hiding the frames. This kinda code only works if the fields in questions are grouped together.

Thanks you all for your reply. :slight_smile: Actually, the 20 fields is just a example. What I am thinking is to use some configuration tables to define the field’s properties. Therefore, I don’t need to write code at each form. It is a very flexible way for customers to set certain fields’ properties based on their company rules. When opening a form, I check the configuration table to dynamically set those properties.

hi ww s, Any how u need to take values from configuration table and assign to properties (still u need to hard code). regards, Sarukai

Actually, what you can do is add a function to the form in which you can set the editable property depending on the value of a certain (number of) field(s), and you can call this function from the forms OnAfterGetRecord and OnActivateForm or something. You will still have to write 20 lines of code for all your fields, but at least the code is in one place.

ww_s has the right idea – C/SIDE forms should expose their controls as a control array. Suppose we could write something like this: CurrForm.Controls[i].EDITABLE := FALSE; or better yet CurrForm.Controls[“Balance”].VISIBLE := FALSE; Then we could create something like a forms configuration table where we could store UserID, Form#, Control# and/or ControlName, PropertyID and PropertyValue. Think of the possibilities :slight_smile:

Navision is an ERP system, not a development environment. If Navision manages to include even more development oriented features, it will become a Visual Basic competitor… [:D]

Looking forward to that day !