#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Smile Load Text From File in Delphi


    hello,,
    i m a beginner in delphi,,
    now i m so confused about load text from file,,
    before, i made a program in delphi which save text in a file
    Ex : delphi 123456
    i want when i click load button, delphi in Edit1 and 123456 in Edit2
    plz help me
    NB : sorry for my bad language
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    It is hard to know from your post how complex your situation or how large the text files
    might become.

    If the text files will fit comfortably in memory and you only want to break the file into
    strings based upon carriage returns (as implied by readln) then you could just load the
    file into a stringList.

    Simplistically
    Code:
    procedure TForm1.LoadFile;
    var
      myStrings: TStringList;
    begin
       myStrings := TStringList.Create;
       try
         myStrings.LoadFromFile('drive\path\filename.txt');
         // Do what you want here
         // e.g. Edit1.Text := myStrings[0];
       finally
         myStrings.Free;
       end;
    end;
    Ofcourse, you may want the TStringList to be more permanent and be available for
    interaction with the user. In such a case you might want it to be created in FormCreate.
    The example I gave is just to illustrate loading the file and accessing the first line.

    Clive

IMN logo majestic logo threadwatch logo seochat tools logo