Hi Support Team,
I’m creating an action providing means to create a manifest file. In that action I use OnValidate in order to prevent user input capable to interfere the manifest file (e.g. german umlauts must not be used or version needs to be in format n.n.n.n).
Please refer to the attached files. The Action Studio Project Manifest.fbap contains a property page, some properties and Scripts (et least OnValidate and OnExecute).
In OnValidate I want to check for the entered version:
if (IsIllegalVersionString(Context.ExpandExpression(Context.Properties.PropertyAsString(‘AssemblyVersion’), true)))
…
This leads to the following error message in case I start the FinalBuilder project (Manifest.fbp7):
FB70ActionCtx.CustomActionValidateContext: Variable : BuildVersion - does not exist!
In case I prevent the execution of OnValidate (insert “return true” as first line) then the same check is done in OnExecute - and here it works.
Before I removed all code not related to this bug I had the magic behaviour that OnValidate was able to be executed ONCE - this error occurred only after the first run. Therefore I think the properties should be available from within the OnValidate, shouldn’t they?
Would you mind to have a look into this issue?
Best regards
Michael
Hi Support Team,
I’ve moved the action from the ‘CreateManifestFile’ ActionList to the Main ActionList.
Now the OnValidate code works (i.e. it can access the property / variable).
This means that there is something wrong in case the action is not in main…
And there is another issue: changed the default value for ‘BuildVersion’ via ‘Project’, ‘Edit Variables’ to 1.2.3.4.
This modification is ignored. You need to restart the IDE - after this OnValidate allows the project to run.
Best regards
Michael
Hi Michael (btw, please change your profile display name to something other than Login!)
Validation works fine on action lists, the problem you were seeing is because you probably didn’t have any actions on the main actionlist… which means the project is not runnable and can’t be validated.
I can reproduce the variable change issue here, very strange, looking into it.
The variable issue is fixed for the next update, the issue is that when the Variables options are set to show the current value in tooltips, the the tree is still showing the current value. I have changed this so that the tree always shows the default value.
Hi Vincent
Thanks for your answer. But I do not agree with you that OnValidate works well.
Step 1
I have changed Manifest1.fbp7 slightly (added some actions to main). You’ll see on 1.png that this project does not show the expected massage (“AssemblyVersion needs to be four dot-separated numbers…”) but the “Script Execution Failed…BuildVersion does not exist” message.
Step 2
In case I add “return true” to the first line of OnValidate (in Manifest.fbap) the code in OnValidate is skipped and the same code is executed in OnExecute without error (here BuildVersion is not absent) -> 2.png.
Step 3
Then I removed the first line (“return true”) which I added in step 2.
Additional I added a variable “WorkAround” to the FinalBuilder Project (see Manifest3.fbp7) and changed the code in ActionList “CreateManifestFile”. Now I use this ProjectVariable instead of the ActionList-Variable (field “Version” in Action “CreateManifest” is now set to %Workaround%). And now the behavior I mentioned in my last post occurs:
- First Run of Project succeeds (3.png) and this is wrong: the two red colored Build Log Lines shows that two versions are malformed
- the next Run (without any change!) produces the correct (expected) message from OnValidate (4.png)
I use 7.0.0.2183 - and hope that you are able to reproduce this behavior thanks to the attached files.
Best regards
Michael
Hmmm, probably I should state clearly what I consider as wrong:
- in step 3 the validation should work also on the first run (probably this is already fixed with your fix of the “variable change issue” mentioned yesterday)
- additional FB should work like in step 3 even if I use the ActionList-Variable (Manifest1.fbp7)
I see that OnValidate and OnExecute seem to have different kinds of Context objects. The comments are equal (//Parameters : Context - Provides access to the properties) but the list of available properties / methods are different. Probably the OnValidate-Context object cannot access ActionList-Variables properly… ?
BR
Michael
(PS: I’ve updated my profile as requested…
OnExecute and OnValidate do have different context objects, as they are designed for different thing. You should not expand variables during validation, it’s pointless since their value may not be set at design time. The simple work around for this issue is to change this line :
if (IsIllegalVersionString(Context.ExpandExpression(Context.Properties.PropertyAsString(‘AssemblyVersion’), true)))
to
if (IsIllegalVersionString(Context.ExpandExpression(Context.Properties.PropertyAsString(‘AssemblyVersion’), false)))
The boolean parameter defines whether an exeption will be thrown if an expression is invalid, since you do not have any exception handling in place, the exception bubbles up to the script engine, which is why you see the error.
Hi Vincent,
thank you for your answer.
Why you do not start my sample project? Or is it working on your side?
I have changed the code and
- Manifest1.fbp7 can be started several times without any information
- Manifest3.fbp7 can be started ONCE, from the SECOND start I get the expected information that the second “Run Action List”-Action has a malformed version string (1.2.3 instead of 1.2.3.4)
Therefore there are still the two problems mentioned in my last posts:
1. Manifest1.fbp7
OnValidate cannot access the variable %BuildVersion% (which is an Action List Parameter in Manifest1.fbp7). Otherwise it would (should) inform me that the version string provided in “Delphi 2010 - ConfigTool” violates the format checked by IsIllegalVersionString.
2. Manifest3.fbp7
With the workaround for the bug mentioned in 1. by means of “Set Variable Workaround to [ %BuildVersion% ]” the OnValidate code can access the version strings (e.g. 1.2.3). But the first run of the project succeeds surprisingly. This is wrong. Only the second start of the project is blocked by OnValidate. The blocking itself is correct, but also the first execution should be blocked.
Please check it out with the attached project.
Best regards
Michael
I have already told you, it is bad practice to expand expressions during validation, you cannot possibly know what the value of a variable will be at validation time, variables change during a build process. I tell you this after 10+ years of writing actions, and over those 10+ years, we have removed all expandexpression calls from the validation methods of actions after many customers reporting validation errors, because their variables do not have default values that will pass validation. There is only so much hand holding you can do when writing actions. The only reason the validation context object still has the ExpandExpression method is to avoid breaking existing third party actions, we do not use it here.
The reason you see differing behavior on the first run vs the second run, is because the first time the validation is run, the variables have no value when expand expression is called( and your IsIllegalVersionString logic is wrong). The second time, the variables have the values from the previous run.
Hi Vincent,
thank you for the clarification. I think I’ve had a wrong understanding of the OnValidate method.
OnValidate works well in case I remove the ExpandExpression and enter the Version strings directly (instead of via variables).
I think I will use OnExecute and stop execution in case the version is malformed.
Best regards
Michael