%GenerateVirtuals - Add Embed for Routines After: RETURN ReturnValue

I am getting tired of coding around the generated virtual RETURN statement. It is not a frequent thing but has come up enough to be annoying.

For instance, the WindowManager.TakeCompleted method generates with:
RETURN ReturnValue
…and in the embeditor there is not an embed line after this statement and the next generated method.

I added an #EMBED (ie ‘New Class Method Routine Code Section’) to:
#GROUP(%CheckAddMethodPrototype) in ABOop.tpw
This does include an embed line for routines after the return statement. However, I have yet to get the embed parameters correct such that a simple Routine point shows in the embed tree for each method.

Might a template guru have the solution?

You can try this template code.
Open ABOOP.TPW and go to the %GenerateVirtuals #GROUP

Add the lines between the #!UpperPark comments.
One caveat, the #RESUME command for the #SUSPEND in effect for the method generation is inside of %CheckAddMethodPrototype. I don’t see any real way to add this embed statement inside of there. We just don’t have the information needed.
This means if you put code inside of the method routine embed point but do not put any code in the method data or code embed points, the routine will generate but the method will not.
This shouldn’t be a problem because if you declare a routine, you should add code to call it in the method.

#GROUP(%GenerateVirtuals, %WhichClassItem, %EmbedTreeText, %VirtualGroup, %GlobalObject = %False),AUTO
  #CALL(%SetClassItem, %WhichClassItem)
  #EQUATE(%BaseClass, %BaseClassToUse())
  #IF(%BaseClass)
    #EQUATE(%Indent, %OutputIndent)
    #CALL(%FixClassName, %BaseClass)
    #FOR(%pClassMethod)
      #FOR(%pClassMethodPrototype), WHERE(~%pClassMethodPrivate AND ~%pClassMethodFinal AND (UPPER(%pClassMethod) = 'DESTRUCT' OR UPPER(%pClassMethod) = 'CONSTRUCT' OR %pClassMethodExtends OR %pClassMethodVirtual))
        #CALL(%SetupMethodCheck)
        #INDENT(-%Indent)
#INVOKE(%VirtualGroup, %GetTreeTextToClass(%EmbedTreeText, %BaseClass) & %GetObjectEmbedPrototype(), %GetDataText(), %GetCodeText())
        #INDENT(%Indent)
        #CALL(%CheckAddMethodPrototype,%ClassLines)
#!UpperPark - rsm - 2024-02-16 - added embed point for routines after virtual method generation
#EMBED(%ClassMethodRoutineSection,'Class Method Routine Section'),%ActiveTemplateInstance,%pClassMethod,%pClassMethodPrototype,LABEL,TREE(%GetTreeTextToClass(%EmbedTreeText, %BaseClass) & %GetObjectEmbedPrototype()&'|ROUTINES{{PRIORITY(10000)}'),WHERE(NOT %GlobalObject)
#!End UpperPark
      #ENDFOR
    #ENDFOR

Let us know how it goes.

1 Like

Placing the embed there gives this generation error:
File Closed with #SUSPEND pending

Worked here. What type of class did you embed code into?
Can you give the exact error message?

Looking good now. I copied your embed line exactly, but had not yet gone back to do a full refresh of the ABC classes. That should not make a difference with minor template changes so perhaps I missed something. Nevertheless, the routine embed point now shows for all ABC Object classes (includes 3rd party). This should be a change in the shipping templates.

ABC Object virtual methods now show in the embed tree as:
AbcMethodName PROCEDURE,VIRTUAL
DATA
CODE
ROUTINES

1 Like

Im somewhat curious as to why you prefer thiscembed point. The regulat Procedure Routines point is in scope for (all the) methods, so generally i put my routines all yogether there.

If you are calling a block of code multiple times from inside the same method, then i can see some value, but generally i just collect my routines together in procedureroutines.

That said, if you want the code to be added to the shipping templates then post a PTSS. Thats the official way to get stuff added, and ive had good success submitting changes, and getting them applied that way.

Good questions. It probably comes back to coding preferences.

I prefer to keep things in scope as much as possible. For Procedure Routines one must use object names as opposed to SELF. Now out of habit but attributed to some long ago words from a certain Cajun, this is just about always my first clue. Routines in a method also maintain code proximity which I find helpful in the embed tree & embedditor. While I sometimes use routines for multiple calls, I more often use them to keep a main block of code simple and ‘embed document’ what the routine code accomplishes. Over my career, I haven’t any doubt this has proven useful when re-visiting code years later.

It has been a long time since I last looked at the PTSS list. Usually I do so after a new SV release. With the always present SV struggles to focus & keep up, I haven’t any doubt that your success rate far exceeds those from the rest of us. Nevertheless, I will submit Rick’s solution. Maybe it will become SVs claim that the ABC templates have finally been updated.