Forum > Beginners

Nested FunctionsQuestions

(1/3) > >>

JLWest:
howardpc wrote this code in answer to a questions I posted on August 27, 2021, in the beginner section titled ' Parsing a really Long string 620 char'.

I have changed the function header to ParseFoLength and adding ALEVEL and two integers A and B. I realize the code has to be modified to parse for lengths.

I'm trying to implement the code segment and getting nowhere. It just exits with this call I make.

Var
TSA : TStringArray;
A,B : Integer;

My call: TSA := ParseForLength(StringName, sType, sLevel1, A, B );

How do I call ParseForLength?

Thanks

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- function TForm1.ParseForLength(aText: String; const aPhrase: String; ALEVEL : String; ALENGTH, BLENGTH : Integer): TStringArray;  var   endPos: SizeInt = 0;   start: SizeUInt = 0;    procedure AddToResult;    begin     SetLength(Result, Succ(Length(Result)));     case endPos of       0: Result[High(Result)] := Trim(Copy(aText, start));       otherwise         Result[High(Result)] := Trim(Copy(aText, start, endPos-start));     end;   end;   begin   end;

howardpc:
You need to make clearer what you are trying to achieve.
Please give a typical text to be parsed, with its associated phrase and lengths, and what you then expect the output string array to contain.

Bart:

--- Quote from: JLWest on September 26, 2021, 08:45:27 am ---howardpc wrote this code in answer to a questions I posted on August 27, 2021, in the beginner section titled ' Parsing a really Long string 620 char'.

--- End quote ---

He refers to this topic.

Bart

Bart:
I suppose the function still needs to do what it did in the original post.
So:

* What is the meaning of the new parameter Level?
* What is the meaning of the new parameters ALENGHT and BLENGTH?
You are aware that the current function does absolutely nothing, it does not even set a function result?

Bart

JLWest:
@Bart and howaardpc

Bart I don't know how nested functions work or how to call them. Was trying to just get something working so I could figure it out.

OK -  the data entering is a string and could look like the the following:

function CompareStr(const S1 : string; const S2 : string) : Integer; overload;    function CompareStr(const S1 : string; const S2 : string; LocaleOptions:                                             TLocaleOptions) : Integer; overload;

or

Notes: AnsiContainsString checks whether AText contains ASubText, and returns True if this is the case, or returns False otherwise. The search is performed case-sensitive.

function CompareStr(const S1 : string; const S2 : string) : Integer; overload;

function CompareStr(const S1 : string; const S2 : string;

Notes: AnsiStartsStr checks AText to see whether it starts with ASubText , and
returns True if it does, False if not. The check is performed case-sensitive.
Basically, it checks whether the position of ASubText equals 1.

Again 69 character wide first line indented 2 spaces and remaining lines indented the width of  '  Notes: ' or 9 characters. the word 'Notes:' could change but will always be the first word i.e 'XXX:'

The ALEVEL parm indicates what to break or parse on (function, procedure or ';'. ALENGTH is the indention of the first line and BLENGTH is the indention of the rest of the text in the string.