Geting Info from a String

Hi there,

I wondered if anyone know a good method to extract serteain information from a string.

Take the following two strings for example:
[italic]
1) Unit1.pas(57) Warning: Variable 'k' might not have been initialized

2) Unit1.pas(31) Hint: Variable 'CharID' is declared but never used in 'TForm1.Button1Click'
[/italic]

As you can see its a compiler info from DCC32.EXE. I want to first know if the string is an "Warning" or a "Hint" (or Error etc). Then I want to extract the Messega ("Variable 'k' might not have been initialized" in string 1). Finally I want to know witch file ("Unit1.pas) and where in the file (line "57") the error warning from.

I would like to put the information in an array of records.


Regards,
Arash

Comments

  • : Hi there,
    :
    : I wondered if anyone know a good method to extract serteain information from a string.
    :
    : Take the following two strings for example:
    : [italic]
    : 1) Unit1.pas(57) Warning: Variable 'k' might not have been initialized
    :
    : 2) Unit1.pas(31) Hint: Variable 'CharID' is declared but never used in 'TForm1.Button1Click'
    : [/italic]
    :
    : As you can see its a compiler info from DCC32.EXE. I want to first know if the string is an "Warning" or a "Hint" (or Error etc). Then I want to extract the Messega ("Variable 'k' might not have been initialized" in string 1). Finally I want to know witch file ("Unit1.pas) and where in the file (line "57") the error warning from.
    :
    : I would like to put the information in an array of records.
    :
    :
    : Regards,
    : Arash
    :
    This call for a smart use of the Copy(), Delete() and Pos() routines.
    Here is a small code, which splits 1 line into several strings, one for each of your info.
    [code]
    UnitName := Copy(ErrorLine, 1, Pos('(', ErrorLine)-1); // Get the first part
    Delete(ErrorLine, 1, Pos('(', ErrorLine)); // Remove the part taken
    LineNumber := Copy(ErrorLine, 1, Pos(')', ErrorLine)-1);
    Delete(ErrorLine, 1, Pos(')', ErrorLine));
    ErrorType := Copy(ErrorLine, 1, Pos(':', ErrorLine)-1);
    Delete(ErrorLine, 1, Pos(':', ErrorLine));
    Message := ErrorLine;
    [/code]
    You can remove leading and trailing blanks using the Trim() routines. All the variable are strings, which means you need to see to the conversion to the types you need.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion