Jump to content

Setting Object Default Value Programmatically


Recommended Posts

Is it possible (using Scripting, I assume) to modify the default value of an object programmatically? I have an object whose default value is loaded at runtime to represent some system settings and I've created a UI to modify those settings. Currently I manually take the settings and copy them into the object and right-click -> Set as Default Value, than save it. Was wondering if there was a way to do this programmatically?

Link to post

You can set the default value of a control using scripting.  But I don't think this is what you want.  Very few scripting functions work in the run-time engine.  Scripting is generally a thing that makes LabVIEW code, or edits LabVIEW code.  These are not the types of things you do in a run-time engine.  In a built EXE for C++ you wouldn't generate new source code that is compiled and then used in that EXE.  It would be something like self modifying code, and probably should be avoided.

 

But what you can do is use a function like the OpenG Write Panel to INI, and Read Panel From INI.  This will take the control values for every control on your front panel, and save them to a human readable INI file.  Then on startup of your program you can use the Read Panel From INI and it will set the control values to what they were last saved to.  Where you save the INI is up to you, but you may get into some permissions issues if you try writing and reading to files under Program Files, which is why most programs are gravitating to using the Application Data folder, or ProgramData for all users.

 

These two wonderful OpenG functions can be found in the Variant Configuration package.

  • Like 1
Link to post

Hooovahh,

 

Thanks for the reply. Unfortunately my settings object has in it's class data other objects. I tried collapsing the objects to XML however one of these objects can grow rather large and I get the 1803 error when expanding it from XML.

Link to post

My preference would be to have a "Set to Default" method of the class that initialises the object with reasonable defaults that you call on teh startup of your application. Then your settings UI can call methods on the object to tweak teh settings as the user desires.

 

As a general rule I dislike the "Default Value" properties of controls because they can be very hard to control and enforce over the development lifetime of an application.

Edited by ak_nz
  • Like 1
Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.