?
Solved

listview - load list from file..

Posted on 2005-04-14
3
Medium Priority
?
248 Views
Last Modified: 2010-04-05
hi , i want load a proxylist, but i dont understand why it doesnt work..

------------

type
  PMyListItem = ^TMyListItem;
  TMyListItem = record
    Proxy,
    Port : string;
  end;

ProxyList: TListView;

  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  form1: Tform1;
  lstPMyList : Tlist;


   function TForm1.PMyList(Index: Integer): PMyListItem;
  begin
   Result := PMyListItem (lstPMyList[Index]);
  end;

procedure Tform1.Button1Click(Sender: TObject);
var MyListItem: PMyListItem;
             F : TextFile;
       strLine : string;
       IniFile : TIniFile;

  begin

   if OpenDialog.Execute then
    begin
    ClearMyList;
    ProxyList.Items.BeginUpdate;
     AssignFile (F, OpenDialog.FileName);
     Reset (F);
     try
      while not Eof (F) do
       begin
        Readln (F, strLine);
          MyListItem := New (PMyListItem);
          MyListItem.Proxy := Copy (strLine, 1, Pos (':', strLine) - 1);
          MyListItem.Port := Copy (strLine, Pos (':', strLine) + 1, Length(strLine));
          lstPMyList.Add (MyListItem);

                  MyListItem := New (PMyListItem);
          MyListItem.Proxy := Copy (strLine, 1, Pos (':', strLine) - 1);
          MyListItem.Port := Copy (strLine, Pos (':', strLine) + 1, Length(strLine));
          lstPMyList.Add (MyListItem);
          ProxyList.AddItem(strLine);
         end;
     finally
      CloseFile (F);
     end;

    with ProxyList do
     begin
      Items.Count := lstPMyList.Count;
      Items.EndUpdate;
      Repaint;
     end;
   end;
     end;
end.


the source code is cut, and i think is also a little confused, anyone can help me to load a proxy list into a listviewer with the record function? or if somebody know any tutorial for learn how to use the listview in all ways..

-thanks!!
0
Comment
Question by:xapsx
  • 2
3 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 13787325
would you mind if I rewrote this to use an object instead of a record? I think it will be much simpler and still very easy to work with
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 320 total points
ID: 13787342
otherwise, this is waht you want :-
Lines I've added/repalced are marked with (**)

procedure TForm1.Button1Click(Sender: TObject);
    var MyListItem: PMyListItem;
        F : TextFile;
        strLine : string;
        IniFile : TIniFile;
(**)        newitem: TListItem;
    begin
       
        if OpenDialog.Execute then
        begin
            ClearMyList;
            ProxyList.Items.BeginUpdate;
            AssignFile (F, OpenDialog.FileName);
            Reset (F);
            try
                while not Eof (F) do
                begin
                    Readln (F, strLine);
                    MyListItem := New (PMyListItem);
                    MyListItem.Proxy := Copy (strLine, 1, Pos (':', strLine) - 1);
                    MyListItem.Port := Copy (strLine, Pos (':', strLine) + 1, Length(strLine));
                    lstPMyList.Add (MyListItem);
                   
                    MyListItem := New (PMyListItem);
                    MyListItem.Proxy := Copy (strLine, 1, Pos (':', strLine) - 1);
                    MyListItem.Port := Copy (strLine, Pos (':', strLine) + 1, Length(strLine));
                    lstPMyList.Add (MyListItem);
(**)                    newItem := ProxyList.Items.Add;
(**)                    newitem.Caption := MyListItem.Proxy;
(**)                    newitem.Subitems.Add(MyListItem.Port);
(**)//                    newitem.Data := MyListItem; // enable this if you want to keep a reference to the proxy:port record with the listview item

                end;
            finally
                CloseFile (F);
            end;
           
            with ProxyList do
            begin
                Items.Count := lstPMyList.Count;
                Items.EndUpdate;
                Repaint;
            end;
        end;
    end;

0
 

Author Comment

by:xapsx
ID: 13787436
thanks therealloki , THANKS! great help
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question