File IO routines

www.kxcad.net Home > Electronic Index > Altium(Protel) Index


Your Ad Here

Delphi Script has the following IO routines (which is covered in detail in the Delphi Script reference):

Delphi Script gives you the ability to write information out to a text file, since DelphiScript is an untyped language, you can only deal with strings. Thus Read/ReadLn routines are equivalent. They read a line up to but not including the next line. A Writeln(String) routine is equivalent to a Write(S) and a Write(LineFeed + CarriageReturn) routine.

To be able to write out a text file, you need to employ AssignFile, ReWrite, Writeln and CloseFile procedures. To read in a text file, you need to employ the AssignFile, Reset, Readln and CloseFile procedures. This example writes to a text file and adds an end-of-line marker.

Use of Try / Finally / End block is recommended to make scripts secure in DXP in the event of an IO failure.

Example

Var

    InputFile  : TextFile;

    OutputFile : TextFile;

    I          : Integer;

    Line       : String;

Begin   

    AssignFile(OutputFile,eConvertedFile.Text);

    Rewrite(OutputFile);

    

    AssignFile(InputFIle,eOriginalFIle.Text);

    Reset(InputFile);

    Try

        While not EOF(InputFile) do

        Begin

            Readln(InputFile,Line);

            For I := 1 to Length(Line) Do

                Line[I] := UpperCase(Line[I]);

          

            Writeln(Outputfile, Line);

        End;

        

    Finally

        CloseFile(InputFile);

        CloseFile(OutputFile);

    End;

End;

See also

Delphi Script functions

Delphi Script Keywords Reference

Delphi Script Extensions Reference

Your Ad Here