Changing Command name is a snap for 4D, but

… for programmers it’s a nightmare. :face_vomiting:
Daily, with my eight databases, seven components, some in v17, some in v18, copy and paste from one to others… I got bad thoughts about 4D!

$evt:= Form event code // v18
$evt:= Form event // v17

Please ! Never do it again, put a new name to the new commands!!!
$evt:= Form event ob or Form event detail, or what ever you want.

And I have a tool, in v18, Oviyar, which can generate code for databases: put in a button popup menu, obviously with event manager… How can I know the target ? I can’t.
So I need to had an intermediate popup to ask for the destination “v17 or v18? Your bread, sliced or not sliced ?”.

I know your intentions were good, but the result is a trap I fall in each time, each time, daily. A nightmare.
Please avoid… please.

For my own, I had to forget copy paste, you can’t work with that with N versions. It’s worse when you have to go back and forth between french and english langages.

It would be so simple instead: add a “Copy with tokens” menu in the method menu…

3 Likes

Is there a reason your tool does not generate code with tokens?

The concept of avoiding hard-coding command names in code generator logic has been around at least v15 R4 and in a more basic form since v2003 (Quick Report code generator and method macros), or even before, since 4D has has English and French commands names for a long time.

Yes Keisuke,
there is a reason.
I have a database “Oviyam” in 4D v18 which manage buttons generation, but also the code to place in your target database, for popup buttons (States resources for buttons, menu Icons, and small icons).
I generate the code from “Command name” command. But the context is Oviyam, not the target, and how can I know the target ? The resulting text code is then pasted ready to be copied in the destination.

Command name(388) // Gives "Form event Code" as my tool is in v18

But my target needs " Form event" only. So each time I generate code, I have to specify the target. By a menu. And same, I need to create the command name without the “Command Name” command, as I can’t specify a “version target” in this command :frowning:

Exemple of code generation for a state toggle popup menu.

The resulting code contains “Form Event Code”, ok for a v18 target database, but not ok with a v17 target database.

And what about making copy and paste?
From v17 to v18, the entire method is copied with token, this is cool. But if you need a part, then the issue is there.
From v18 to v17, nop, you can’t (I understand why), so you need to copy and paste the text itself, with the issue.

If I say that is to express the everyday’s trouble I get…

But you don’t need to know the target version, you just need to copy and paste any_command_name:C388 and it will transform to the correct token in the target version. That is the whole point of tokens, that the names are relative but the IDs are absolute.

1 Like

Set “:C388” in method text without command name is possible too.
it auto translated to “Form event code:C388”
or to “Form event:C388” (belongs to version).
But this is same behavior you had wenn you insert token inclusive command name “cmdnameOld:Cxxx” auto translate to “cmdnameNew:Cxxx” (…after line is closed with cr).
But to have in method-editor context menu a additional copy-with-tokens can be a good feature request.

METHOD SET CODE (“testMethod”;":C388")
results auto in “Form event” or “Form event code” (belongs to version)

Bildschirmfoto 2020-05-04 um 14.19.27

Keisuke!
Ahhhhhhh ! But yes ! For sure. I’ll try, I had forgotten that way.
Many thanks, issue solved for Oviyam. But not for Copy and paste…

Ok, it works well, just adding “:Cxxx” to commands. Thanks for the idea Keisuke.

Just copy and paste to solve, why 4D do not use tokens in the same way in copy paste for method’s texts ?

Forgot to say, tokens in the pasteboard are not all, a converter for “control flow” (if, case of, etc.) is necessary too for french - english.

It’s a good thing 4D changes commands/constant names, but I don’t understand why they don’t consider the useless work they invent just because that ridiculously small feature is missing. Using export/import as .c4d is far less practical than copy/paste.

Don’t be surprised if french people still code in french.

Run your own, some pieces:

METHOD GET CODE("myMethodName";$code_t;Code with tokens)
SET TEXT TO PASTEBOARD($code_t)
C_COLLECTION($0;$keyword_c)
$keyword_c:=New collection

If (Command name(1)="Sum")  //en
	$keyword_c.push(New object("start";"If";"end";"End if";"else";"Else"))
	$keyword_c.push(New object("start";"Case of";"end";"End case";"else";"Else";"branch";":"))
	$keyword_c.push(New object("start";"For";"end";"End for"))
	$keyword_c.push(New object("start";"While";"end";"End while"))
	$keyword_c.push(New object("start";"Repeat";"end";"Until"))
	$keyword_c.push(New object("start";"Begin SQL";"end";"End SQL"))
	$keyword_c.push(New object("start";"For each";"end";"End for each"))
Else   //fr
	$keyword_c.push(New object("start";"Si";"end";"Fin de si";"else";"Sinon"))
	$keyword_c.push(New object("start";"Au cas ou";"end";"Fin de cas";"else";"Sinon";"branch";":"))
	$keyword_c.push(New object("start";"Boucle";"end";"Fin de boucle"))
	$keyword_c.push(New object("start";"Tant que";"end";"Fin tant que"))
	$keyword_c.push(New object("start";"Repeter";"end";"Jusque"))
	$keyword_c.push(New object("start";"Debut SQL";"end";"Fin SQL"))
	$keyword_c.push(New object("start";"Pour chaque";"end";"Fin de chaque"))
End if 
$0:=$keyword_c

Arnaud,
I didn’t know about option “Code with tokens”, will have a look in it.
But what is the purpose of your second method ???!?

In fact, if I read properly the documentation, the paste always use tokens if they are present in pasteboard.
So true, would be great to have an option to copy with token somewhere… with a shortcut…
Yes, you can write your own with a macro (to get the selection), that is what I’ll do now, but 4D can offer it directly in the interface!

It would help to know how you are currently trying to “get a selection”, but it sounds like you are using METHOD GET CODE to tokenise and Substring + GET HIGHLIGHT or ST Get plain text to get a code snippet.

Instead , maybe you should get a code snippet first and iterate each line with Parse formula.

QS_Toolbox !

But what is the purpose of your second method ???!?

Read above:

Forgot to say, tokens in the pasteboard are not all, a converter for “control flow” (if, case of, etc.) is necessary too for french - english.

In other word, 4D is able to convert “Somme:1” in “Sum”, [myOldTableName:1] in “[myNewTableName]” etc. But the control flow instructions have no tokens, you must convert them yourself for french/english purpose.

Yes for sure,
in my case, all my databases are used in the same language for development. You guessed the one :slight_smile:

side bar:

In the context of 4DCODE tags, the control flows are always English. I missed this behaviour at first and added similar logic to switch the control flow keywords in my 4D tags document. In that instance, it was not necessary, but in general, I always remind myself that I should anticipate different language settings when I release my code to the public.

Code may include literal values, date or numeric, so it should be prudent to also query for GET SYSTEM FORMAT, add decimal separator to Num, ask for "&xml" with String, if applicable.

1 Like