读取某一行的内容用哪个函数?

解决方案 »

  1.   

    你的问题不是很清楚、是读取文本文件的某一行吗?Readln?
      

  2.   

    能否吧问题说的清楚一些,比如读什么控件里面的什么内容。如:
    读Edit中的内容可以写成:
    String str;
    str:=Edit.Text;
    读Label控件的内容可以写成:
    str:=Label.Caption;
    读ListBox的内容可以写成:
    str:=ListBox.Item[i];   //i为第几行,从0开始以此类推。
    不好意思说一下,以后不要这么肉麻,我受不了,嘿嘿
      

  3.   

    TO:cherrylin (伊雪妹妹) 你好好可爱噢。呵呵
      

  4.   

    关键是看你是读什么的
    string str;
    读TStringList方法
    TStringList List;
    str := List.Strings[i];//第i+1行
    读TListBox控件:
    str := ListBox1.Item[i];//第i+1行
    读TStrings内容:
    str := Memo1.Lines.Strings[i];//第i+1行       读TMemo控件
    str := RichEdit1.Items.Strings [i];//第i+1行       读TRichEdit控件
    str := ComboBox1.Items.Strings [i];//第i+1行       读TComboBox控件
    读TTreeNode内容:
    str := TreeView1.Items.Item[0].Text;// 读控件TTreeView
      

  5.   

    这是对你们的尊称,可是有几位大哥不喜欢啊!那小妹以后就不这么叫了,免得有几位大哥哥晕倒!到时我的罪就大了,嘿嘿:)   我要读指定的文本文件的某一行内容!我知道用ReadLn,但不知道该怎么用!能给一结源码码?(比如说我现在要读c:\test.txt文件的第二行内容!)
       
       谢谢各位兄长了!这不肉麻吧!呵呵!!
      

  6.   

    unit V4_1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        btnCreate: TButton;
        btnAppend: TButton;
        btnOpenRead: TButton;
        Memo1: TMemo;
        procedure btnCreateClick(Sender: TObject);
        procedure btnAppendClick(Sender: TObject);
        procedure btnOpenReadClick(Sender: TObject);  private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;implementation{$R *.dfm}--创建文本文件
    procedure TForm1.btnCreateClick(Sender: TObject);
    var
      MyTextFile: TextFile;
      s: string;
      i: integer;
    begin
      //关联文件
      AssignFile(MyTextFile, 'MyTextFile.txt');
      //覆盖或创建新文件
      Rewrite(MyTextFile);
      //向文本文件里写字符串
      try
        for i := 1 to 5 do
        begin
          s := 'This is line #';
          Writeln(MyTextFile, s, i);
        end;
      finally
        CloseFile(MyTextFile);
      end;
    end;--添加内容
    procedure TForm1.btnAppendClick(Sender: TObject);
    var
      MyTextFile: TextFile;
      s: string;
      i: integer;
    begin
      //关联文件
      AssignFile(MyTextFile, 'MyTextFile.txt');
      //判断文件是否存在
      if FileExists('MyTextFile.txt') then
      //以添加的方式打开文本
        Append(MyTextFile)
      else
        raise Exception.Create('MyTextFile.txt不存在');
      //向文本添加字符串
      try
        for i := 6 to 10 do
        begin
          s := 'This is line #';
          Writeln(MyTextFile, s, i);
        end;
      finally
        CloseFile(MyTextFile);
      end;
    end;
    --读取内容
    procedure TForm1.btnOpenReadClick(Sender: TObject);
    var
      MyTextFile: TextFile;
      s: string[14];
      i, j: integer;
    begin
      //关联文件
      AssignFile(MyTextFile, 'MyTextFile.txt');
      //判断文件是否存在
      if FileExists('MyTextFile.txt') then
      //以只读方式打开文本
        Reset(MyTextFile)
      else
        raise Exception.Create('MyTextFile.txt不存在');
      //读取文本数据
      try
        while not eof(MyTextFile) do
        begin
          Readln(MyTextFile, s, j);
          Memo1.lines.Add(s + IntToStr(j));
        end;
      finally
        CloseFile(MyTextFile);
      end;
    end;
    end.
      

  7.   

    读取内容应改为procedure TForm1.btnOpenReadClick(Sender: TObject);
    var
      MyTextFile: TextFile;
      s: string[14];
    begin
      //关联文件
      AssignFile(MyTextFile, 'MyTextFile.txt');
      //判断文件是否存在
      if FileExists('MyTextFile.txt') then
      //以只读方式打开文本
        Reset(MyTextFile)
      else
        raise Exception.Create('MyTextFile.txt不存在');
      //读取文本数据
      try
        while not eof(MyTextFile) do
        begin
          Readln(MyTextFile, s);
          Memo1.lines.Add(s);
        end;
      finally
        CloseFile(MyTextFile);
      end;
    end;