Counting the no. of Lines function by function

forum.cdk (2000-2005) & forum.td.cdk (2005-2010)
Faris

Counting the no. of Lines function by function

Post by Faris » 20 Aug 2007, 23:27

 Posted by:  Faris 

Hello NG,

Can anyone guide me on how to count the number of lines in a
function/message action

I am looking something like this

Class/Form Function/Action Number of
Lines
clsXyz fnAbc1 100
clsXyz fnAbc2 200
clsXyz fnAbc3 300
clsXyz fnAbc4 400
clsXyz fnAbc5 500
clsAbc fnAbc1 100
clsAbc fnAbc2 200
clsAbc fnAbc3 300
clsAbc fnAbc4 400
clsAbc fnAbc5 500
frmAbc SAM_Create 40
frmAbc AM_Save 20

Thanks in Advance
Faris

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2069
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Counting the no. of Lines function by function

Post by Jeff Luther » 21 Aug 2007, 00:16

 Posted by:  Jeff Luther 

Well, I can get you along your way because I have a CDKTutorial demo on my
info/samples link below. Click on that, then Samples; they are listed in
alpha order. And if you don't know the CDK at all, this will also provide
an intro.

Basically, to count function/msg. lines you need to:
-- be aware not to count lines beginning with "!" the comment char. You
can parse that or use IsComment() to ignore (unless you are counting
comments as well).

-- Call CDK_App.InitFromFile( )
Call CDK_App.InitializeFramework()

-- now the global var. CDK_App is a handle to your app.

-- in the CDKTutorial, collapse the outline, turn on animate and click on
the radio button to EnumFunctions as a sample.

-- and as the demo shows, the code to display names and most details of
the functions pseudo-codes like this:
Set nFunctsTotal = CDK_App.EnumFunctions( sAryFunctNames )

Call CDK_App.GetFunction( sAryFunctNames[nFunct], oFunction )
Call oFunction.GetReturnType( sValue )
Set nParmsTotal = oFunction.EnumParameters( sAryParmNames, sAryParmTypes )
Set nVarsTotal = oFunction.EnumStaticVariables( sAryVarNames, sAryVarTypes )
Set nVarsTotal = oFunction.EnumLocalVariables( sAryVarNames, sAryVarTypes )
Call oFunction.GetActions( oActionBlock )

Each call (generally) stuffs a string array with details about that outline section.

-- the GetAction() details is what I didn't write in the demo but you need is to loop
through the oActionBlock. That's where your lines in the function are.

-- Look at the CDK Functional Class: cdkActionBlock for its functions that are used
to traverse the down the actions section. Msg. Actions works about the same.

I would suggest you write a test case and if you get stuck, submit it here as a text
app. along with a specific quesiont. That usually gives you the best chance to get
some help.

Best Regards,
Jeff @ PC Design
info. & samples: www.JeffLuther.net/gupta/

Faris

Counting the no. of Lines function by function

Post by Faris » 21 Aug 2007, 07:36

 Posted by:  Faris 

Hello Jeff,

Thanks for the quick response,
I did follow your sample to start with and i was kind of stuck in the
EnumChildObjects functions,
After getting the functions in the list, i tried using

nACount = oFunction.EnumChildObjects( CDK_IT_ActionsBlock , oiItems )

but oItems resulted only in the first level of the indented row. anyway, i
then traversed through the lines of code that is returned and thought use
the same function in the loop for oItems also, but that didnt work for me.

means,

nBCount = oItems[n].EnumChildObjects( CDK_IT_If/Else/SelectCase/etc,
oItemsArray ) didnt work.

I also tried using Next(), Prev(), Parent() and Child() functions, but i am
getting lost somewhere.

are there any function like GetNextLine() which gives me the next line in
the function even if the code is indented inside if/else/select/while
clauses ?

Thanks
Faris

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2069
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Counting the no. of Lines function by function

Post by Jeff Luther » 21 Aug 2007, 17:24

 Posted by:  Jeff Luther 

"function like GetNextLine()" - no, that's what you would need to write,
using the Next(), Prev(), Parent() and Child() functions. Given an oActions
instantance that represents the "Actions" section. You get that this way:

cdkActionBlock: oActions

Call oMsgAction.GetActions( oActions )
or...
Call oInternalFunction.GetActions( oActions )

Then, the heart of traversing down the actions section is something like this;
at least this is how I did it (this is the heart of my function's code):

If NOT oActions.First()
Set sSalLine = '[no actions]'
Return FALSE
Set bMoreSALCode = TRUE
Set bSkipDownToNextItem = FALSE
While bMoreSALCode
! need bSkipDownToNextItem first, else .Child() call moves obj. ptr.
If NOT bSkipDownToNextItem AND oActions.Child()
Set sSalLine = oActions.Title() || ' ' || oActions.Text()
Else
If oActions.Next()
Set sSalLine = oActions.Title() || ' ' || oActions.Text()
Set bSkipDownToNextItem = FALSE
Else
If oActions.Parent()
Set bSkipDownToNextItem = TRUE
Else ! DONE !!
Set bMoreSALCode = FALSE

FYI, oActions.Title() for any line will = the '!' char. for a comment if you
want the comment. oActions.IsComment() returns TRUE if a comment. Essentially,
the code tries to go 'in' (a child) when/if it can. If not, then 'down' (next),
if not then back 'out' (parent), until it gets back to top, which is 'done.'

Best Regards,
Jeff @ PC Design
info. & samples: www.JeffLuther.net/gupta/

Faris

Counting the no. of Lines function by function

Post by Faris » 22 Aug 2007, 11:09

 Posted by:  Faris 

Hello Jeff,

Thank you very much, it worked pretty well.

Faris

--
NNTP.hk - (^(oo)^)
http://www.nntp.hk/web/

Return to “td.cdk”

Who is online

Users browsing this forum: [Ccbot] and 0 guests