loading text from a txt file to a listview

hi all can you please help me I am trying to make my program load/add names from a txt file to a listview I have the code to add names to text but I dont no how to make it load and add!

save code:

[code]
procedure TForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
i:integer;
S:TStringList;
begin
S := TStringList.Create;
for i := 0 to ListView1.Items.Count-1 do
S.Add('"'+ ListView1.Items[i].Caption +'",'+ ListView1.Items[i].SubItems.CommaText);
S.LoadFromFile('names.txt');
S.Free;
end;
[/code]

thats the code I use to save to text file but how do I load?
can anyone help me???

thanks for taking the time!
Slewis

Comments

  • : hi all can you please help me I am trying to make my program load/add names from a txt file to a listview I have the code to add names to text but I dont no how to make it load and add!
    :
    : save code:
    :
    : [code]
    : procedure TForm.FormClose(Sender: TObject; var Action: TCloseAction);
    : var
    : i:integer;
    : S:TStringList;
    : begin
    : S := TStringList.Create;
    : for i := 0 to ListView1.Items.Count-1 do
    : S.Add('"'+ ListView1.Items[i].Caption +'",'+ ListView1.Items[i].SubItems.CommaText);
    : S.LoadFromFile('names.txt');
    : S.Free;
    : end;
    : [/code]
    :
    : thats the code I use to save to text file but how do I load?
    : can anyone help me???
    :
    : thanks for taking the time!
    : Slewis
    :
    Nope. LoadFromFile does just that. You need to use SaveToFile......
  • : : hi all can you please help me I am trying to make my program load/add names from a txt file to a listview I have the code to add names to text but I dont no how to make it load and add!
    : :
    : : save code:
    : :
    : : [code]
    : : procedure TForm.FormClose(Sender: TObject; var Action: TCloseAction);
    : : var
    : : i:integer;
    : : S:TStringList;
    : : begin
    : : S := TStringList.Create;
    : : for i := 0 to ListView1.Items.Count-1 do
    : : S.Add('"'+ ListView1.Items[i].Caption +'",'+ ListView1.Items[i].SubItems.CommaText);
    : : S.LoadFromFile('names.txt');
    : : S.Free;
    : : end;
    : : [/code]
    : :
    : : thats the code I use to save to text file but how do I load?
    : : can anyone help me???
    : :
    : : thanks for taking the time!
    : : Slewis
    : :
    : Nope. LoadFromFile does just that. You need to use SaveToFile......
    :

    O I know I put in worng code lol so how do I get it to load from text file and add to listview??

    Slewis

  • : : : hi all can you please help me I am trying to make my program load/add names from a txt file to a listview I have the code to add names to text but I dont no how to make it load and add!
    : : :
    : : : save code:
    : : :
    : : : [code]
    : : : procedure TForm.FormClose(Sender: TObject; var Action: TCloseAction);
    : : : var
    : : : i:integer;
    : : : S:TStringList;
    : : : begin
    : : : S := TStringList.Create;
    : : : for i := 0 to ListView1.Items.Count-1 do
    : : : S.Add('"'+ ListView1.Items[i].Caption +'",'+ ListView1.Items[i].SubItems.CommaText);
    : : : S.LoadFromFile('names.txt');
    : : : S.Free;
    : : : end;
    : : : [/code]
    : : :
    : : : thats the code I use to save to text file but how do I load?
    : : : can anyone help me???
    : : :
    : : : thanks for taking the time!
    : : : Slewis
    : : :
    : : Nope. LoadFromFile does just that. You need to use SaveToFile......
    : :
    :
    : O I know I put in worng code lol so how do I get it to load from text file and add to listview??
    :
    : Slewis
    :
    :
    Do something like:
    [code]
    S:=TStringList.Create;
    S.LoadFromFile('NameOfTextFile');
    //Don't call Free or you better look quickly
    [/code]
    To save to a file, use the code above and replace LoadFromFile with SaveToFile. Should work.
  • yes I know how to save it I need to load it to the listview so everytime I reopen my program it will load name.txt and it will show them in the listview!
    Slewis

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