How to add parameters to shape which internally use 'append after command'

Now the questions seems to be quite trivial and solution so obvious ... Any way, solution which I use now solve my problem on the following way:

  • for append after command={\pgfextra{\tikzsavelastnodename\tikzsavednodename}},##1 I define as new style named saveLNN (as acronym for save-Last-Node-Name)
  • to my definition of tcpBOX add this saveLNN

Complete code is:

\documentclass[tikz,border=5mm]{standalone}

\makeatletter
\def\tikzsavelastnodename#1{\let#1=\tikz@last@fig@name}
\makeatother

   \tikzset{TCP/.style = {%
saveLNN/.style = {append after command={%
        \pgfextra{\tikzsavelastnodename\tikzsavednodename}},##1},
add text/.style args = {##1:##2}{%
        append after command={node[ATnode,anchor=##1]
        at (\tikzsavednodename.##1) {##2}}
                                },
ATnode/.style = {inner sep=0.5mm,
                 font=\tiny\bfseries\sffamily},
tcpBOX/.style 2 args = {shape=rectangle,
     draw=##1, % border color
     fill=##2, % fill collor
     thick, inner sep= 2mm, outer sep=0mm, minimum height=11mm,
     saveLNN},
                            }
            }% end of tikzset

which gives:

enter image description here

I'm still open for better solution(s).


Just for inner labels: Let choose the correct anchor for label text and the correct position on node's border and you'll get inner labels.

\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}[
    lblfont/.style={font=\tiny\bfseries\sffamily, inner sep=1pt},
    ]

\node[draw=red, fill=gray, minimum height=1cm,
      label={[anchor=north, lblfont]label.n},  % north is default anchor
      label={[anchor=north east, lblfont]north east:label.ne},
      label={[anchor=south west, lblfont]south west:label.sw},
] {Some main text};

\end{tikzpicture}
\end{document}

enter image description here