IDE Scripts Do Not Seem To Change Declarations For Methods

If I use the following code, it will work.

DoCommand("NewProperty")
ChangeDeclaration("UserName", "Bob Roberts",
"String", 2, "")

But it seems to not work with methods so if I replace ‘Property’ with ‘Method’ in this code then it will not work.

Thanks

Try as an example:

DoCommand("NewMethod") ChangeDeclaration("IsPointValid", "x As Integer, y As Integer", "Boolean", 2, "")
It will create this method body:

[code]Private Function IsPointValid(x As Integer, y As Integer) As Boolean

End Function[/code]

[quote=196170:@Eli Ott]Try as an example:

DoCommand("NewMethod") ChangeDeclaration("IsPointValid", "x As Integer, y As Integer", "Boolean", 2, "")
It will create this method body:

[code]Private Function IsPointValid(x As Integer, y As Integer) As Boolean

End Function[/code][/quote]
Didn’t seem to work. Thanks

Can’t change constants either. <https://xojo.com/issue/33310>

Oliver,

Did you ever find a solution to this? If not, did you file a feedback report? I’m running into the same issue…

I have to admit I’m very curious about what it is you guys are trying to achieve with IDE scripting.
Seems like you’re writing code to write code ?

IDE scripting is, for 99% of the uses, a simple way to automate things you might do manually - mostly to be able to build a project (which is mostly how it started out)
It doesn’t provide full access to the entire project & all its elements nor was it designed to.

[quote=200437:@Norman Palardy]I have to admit I’m very curious about what it is you guys are trying to achieve with IDE scripting.
Seems like you’re writing code to write code ?

IDE scripting is, for 99% of the uses, a simple way to automate things you might do manually - mostly to be able to build a project (which is mostly how it started out)
It doesn’t provide full access to the entire project & all its elements nor was it designed to.[/quote]

Well, on one part you’re right; on the other… according to the PDF on it:

“Generally this is used to rename a property or method after it has
been added to a project item.”

So, it should work. About your statement though… I am using it to ‘write’ code. As with most of the topics using ideScript on here when searching for issues I’m having, they (as well as I) am using flags in my string (ie. “[!]this is my string[!]”) and attempting to create an ideScript which will pull all those out and replace them with obfuscated data. I’m actually going a step further and replacing them with an encrypted hex value, and using something like:

dim a as text a = convertData("[!]this is my string[!]")

in the convertData method, I check if debugBuild is true. If it is, I just use replaceAll “[!]” to “”. If it’s not, I pass it through a decryption method (because by then, the string between the flags should be encrypted in hex format). It’s this process of pulling out the strings within the flags, using an external application I made to pass the string values to, and replacing it with stdOut of that, that I am attempting.

IDE script has no decent way to walk over all the items in your project, and all the constants, methods, etc etc in each item so you can reliably process EVERY item in your project which is what it sounds like you need.
Thats one issue.

Not sure if you’re using constants for these or not but with constants you have no way to manipulate each localized value - only the default.

Personally I’d
a) use a constant (hexed or not)
b) always call convertdata and have its internals know debugbuild or not and do the right thing
c) change the value of the constants only to the hexed / unhexed versions as needed

That way you minimize the amount of code that changes between a debug run and actual build

Changing data should be ok as the code doesn’t change.
Changing compilable code after debugging the code is often a recipe for differences in a release vs debug builds that are truly a pain in the butt to track down. Been there done that have the scars from having this occur in building the IDE itself.

That said there IS, somewhere, an FR for making IDE script able to walk over the project and its contents so doing scripted changes to projects could be simpler with an external tool like you’re trying to do

But thats about the best I can suggest at this point

Alternatively you could write ONE module with all these constants in it and process if you use VCP format
Or use the code gen classes I wrote ages ago & use them to generate a new module.
Then simply replace a “debug build” module with the other “release module”

[quote=200452:@Norman Palardy]Alternatively you could write ONE module with all these constants in it and process if you use VCP format
Or use the code gen classes I wrote ages ago & use them to generate a new module.
Then simply replace a “debug build” module with the other “release module”[/quote]

That’s actually what I have been doing. I’m just attempting to tackle this using ideScript to ‘see if it’s possible’. I know it’s not feasible or designed for this… but damnit, I’m determined. :stuck_out_tongue:

Buy steel toed boots
Your toes will appreciate them :stuck_out_tongue:

What I was trying to achieve with IDE scripts is, giving me the ability to select an array property and then have the script automatically add methods similar to getters and setters but for arrays. It would add myVar_Append, myVar_Ubound, myVar_Item, myVar_Remove, etc. If this single bug was fixed I believe it would be easy to automate this.

Oliver, not sure what you are trying to accomplish but you can do something similar using the Extends keyword:
http://documentation.xojo.com/index.php/Extends

Generally, if you find yourself writing (by hand) many similar looking methods or (even) trying to automate the process of code-writing, it sometimes is a hint that there might be a more elegant way to accomplish the goal.

Oliver, you have to select the right project item before call the new property/method
For example you want to add it to Window1:

 if SelectProjectItem("Window1") then
    DoCommand("NewProperty")
    ChangeDeclaration("UserName", "Bob Roberts","String", 2, "")
end if

What’s wrong is that this operation take some time and the navigator needs to be updated. Only then you can call this functionality again (I.E: if you call in strict sequence then only the first will be completed and the second call will be ignored.)

[quote=201390:@Antonio Rinaldi]Oliver, you have to select the right project item before call the new property/method
For example you want to add it to Window1:

 if SelectProjectItem("Window1") then
    DoCommand("NewProperty")
    ChangeDeclaration("UserName", "Bob Roberts","String", 2, "")
end if

What’s wrong is that this operation take some time and the navigator needs to be updated. Only then you can call this functionality again (I.E: if you call in strict sequence then only the first will be completed and the second call will be ignored.)[/quote]
Creating a new property was not the problem. As for the delay, which makes it ignored how do I prevent this?

Thanks

You dont.
IDE script is basically automating things you could do by hand.
You do them “slowly” and the IDE can easily keep up.
A program does them so fast that any minor delays will cause a script issues.

It why I ask what it is people are using it for to get a better handle on what we should do in the future.

After some test it is clear that is not a delay problem but an intrinsic bug for changeDeclaration when you use it for methods.

You can use it for property without problems (any number of properties)
You can use it for methods only if it is the first changeDeclaration for the project.
Any further call for method (after properties or as second call for method or with a new script after the first one has failed) will result a no op.

[quote=201454:@Antonio Rinaldi]After some test it is clear that is not a delay problem but an intrinsic bug for changeDeclaration when you use it for methods.

You can use it for property without problems (any number of properties)
You can use it for methods only if it is the first changeDeclaration for the project.
Any further call for method (after properties or as second call for method or with a new script after the first one has failed) will result a no op.[/quote]

Yup, this is definitely a bug… and as such, a feedback should be created.

[quote=201407:@Norman Palardy]You dont.
IDE script is basically automating things you could do by hand.
You do them “slowly” and the IDE can easily keep up.
A program does them so fast that any minor delays will cause a script issues.

It why I ask what it is people are using it for to get a better handle on what we should do in the future.[/quote]

I understand this… and the more I use it, the more I see the current limitations; however, this feature has SO MUCH potential to be extremely powerful and rewarding with so many possibilities. Perhaps something to look closer into in the future.

Looks like as of Xojo 19.3.1.47524 (19.3.1.3.47524) on macOS 10.14.6 (Mojave) that bug is fixed.
Just developed and tested this, and it works.

[h]Create Class and Method from IDE Script[/h]

Var LF As String = Chr(10)

// --- Create and Select a New Class ---
DoCommand "NewClass"
PropertyValue("Class1.Name") = "MyClass2"

If SelectProjectItem("MyClass2") Then
  DoCommand("NewMethod")
  ChangeDeclaration("IsPointValid", "x As Integer, y As Integer", "Boolean", 2, "")
End If

//--- Method is Now Open for Entry/Edit in the IDE ---

//--- Compose the Method Text ---
Var methodStr As String
methodStr = "" _
+ LF + "//--- Added from IDE Script ---" _
+ LF _
+ LF + "Var z As Boolean" _
+ LF + "z = (x > y)" _
+ LF + "Return z"

//--- Set the Method Text in the IDE ---
Text = methodStr