一个文本文件,逗号分隔例如:12345678,ASDFGHJ123K
1234567890365,AS1DFGHJK
123451267890,AS123DFGHJK
1234567890,ASDF3154554GHJKOpenDialog1.execute 后要先读取第一行到Edit1.Text和Edit2.Text或者还有以后的Edit3等等当中,另外有两个按钮Button1和Button2分别为“上一条”,“下一条”来改变文本框中显示的内容,在一个Label1中显示“当前条数/总条数”,写了很久都不得其要领,请大家给出完整代码谢谢!!!

解决方案 »

  1.   

    给你看段代码吧,我就不详细的给你写了
    没有多大区别,你改一下就可以
    Type
    CarCord=Record
    CarNo:String[12];
    EndDate:String[12];
    CarType:String[6];
    CarM:String[12];
    JobName:String[30];
    Tel:String[14];
    PassTime:String[20];
    ClassNo:string[4];
    end;
    Var
    CarFile:File of CarCord;
    CarData:CarCord;
    FName:String;
    RecSize,CurRec:Longint;procedure T_DataHZ.showrecord;
    begin
    cp.Text:=CarData.CarNo;
    EndDate.Text:=CarData.EndDate;
    CarType.Text:=CarData.CarType;
    Cm.Text:=CarData.CarM;
    dw.Text:=CarData.JobName;
    dh.Text:=CarData.Tel;
    PassTime.Text:=CarData.PassTime;
    ClassNo.Text:=CarData.ClassNo;
    end;
    procedure T_DataHZ.ComboBox1Change(Sender: TObject);
    Var
    Str:String;
    begin
    Str:=ComboBox1.Text;
    if str='01道' then filepath:='CarCord01.dat';
    if str='02道' then filepath:='CarCord02.dat';
    if str='03道' then filepath:='CarCord03.dat';
    if str='04道' then filepath:='CarCord04.dat';
    if str='05道' then filepath:='CarCord05.dat';
    if str='06道' then filepath:='CarCord06.dat';
    if str='07道' then filepath:='CarCord07.dat';
    if str='08道' then filepath:='CarCord08.dat';
    CurRec:=0;
    FName:=filePath;
    AssignFile(CarFile,FName);
    RecSize:=Sizeof(CarData);
    if FileExists(FName) then begin
    Reset(CarFile);
    if not Eof(CarFile) then
    begin
    Read(CarFile,CarData);
    end;
    datahz_ok.Enabled:=true;
    seek(CarFile,0);
    showRecord;
    end else
    Application.MessageBox('在本软件的目录下没有这个文件!','系统提示',mb_ok);
    end;如果想控制指针就用SEEK例如:seek(CarFile,0);
    这是指向第一条的指针。
      

  2.   

    用TStringList吧。
      StrList : TStringList;
    begin
      StrList := TStringList.Create();
      StrList.LoadFromFile('c:\dd.txt');
      Label1.Caption := '总数:'+Inttostr(StrList.Count);
      ShowOneLineData(StrList.Strings[i]);//写一下这个过程来处理分段显示的问题
      .......
    end;
      

  3.   

    接楼上
    procedure Tform1.ShowOneLineData(i:integer);
    var
      tmp:string;
      jpos: integer;
    begin
      tmp := strList.strings[i];
      jpos := pos(',',tmp);
      Edit1.text := Copy(tmp,1,jpos -1);
      Delete(tmp,1,jpos);
      Edit2.text := tmp; 
    end;
      

  4.   

    type
      TPayEvent = procedure(ACount: Integer) of object;
    type
      TPay = Class
        PayList: TStringList;
        ListName: string;
        RecordCount: Integer;
      private
        FActive: Boolean;
        FCount: Integer;
        FOnShowInfo: TPayEvent;
        procedure SetActive(const Value: Boolean);
        procedure SetCount(const Value: Integer);
        procedure SetOnShowInfo(const Value: TPayEvent);
      private  public
        property Active: Boolean read FActive write SetActive;
        Property Count: Integer read FCount write SetCount;
        procedure First;
        procedure Prior;
        procedure Next;
        procedure Last;
        procedure Save;
      published
        property OnShowInfo: TPayEvent read FOnShowInfo write SetOnShowInfo;
      end;
    { TPay }procedure TPay.First;
    begin
      if FActive and (Count >= 1) then
        Count := 1
      else
        Count := Count;
    end;procedure TPay.Last;
    begin
      if FActive and (Count > 0)and(Count < RecordCount) then
        Count := PayList.Count
      else
        Count := Count;
    end;procedure TPay.Next;
    begin
      if FActive and (RecordCount > 0)and(Count < RecordCount) then
        Count := Count + 1
      else
        Count := Count;
    end;procedure TPay.Prior;
    begin
      if FActive and (RecordCount > 0)and(Count > 1) then
        Count := Count - 1
      else
        Count := Count;
    end;procedure TPay.Save;
    begin
      if FActive then
      begin
        PayList.SaveToFile(ListName);
      end;
    end;procedure TPay.SetActive(const Value: Boolean);
    begin
      if (FileExists(ListName))and Value  then
      begin
        PayList := TStringList.Create;
        PayList.LoadFromFile(ListName);
        RecordCount := PayList.Count;
        FActive := Value;
      end
      else
      begin
        if not Value then
          PayList.Free;
        Exit;
      end;  
    end;procedure TPay.SetCount(const Value: Integer);
    begin
      FCount := Value;
      if Assigned(OnShowInfo) then
        FOnShowInfo(FCount);
    end;procedure TFrmBrowNoLine.FormClose(Sender: TObject;
      var Action: TCloseAction);
    begin
      PayList.Free;
      Action := caFree;
    end;procedure TPay.SetOnShowInfo(const Value: TPayEvent);
    begin
      FOnShowInfo := Value;
    end;
      

  5.   

    还有一个方法——用数据库先建立一张两个字段(字符串型)的表,然后用sql语句将文本内容插入到数据库BULK INSERT 'YourTable' from 'YourTxtFile' with(FIELDTERMINATOR = ',',     ROWTERMINATOR = '\n')剩下的应该很简单了