• Delphi程序流程三(2)(while)PS:最简单的任务管理器( 组件LISTVIEW的用法 增加LISTVIEW的读取 删除)


    unit Unit1;
    
    interface
    
    uses
      Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;
    
    type
      TForm1 = class(TForm)
        btn1: TButton;
        ListView: TListView;
        btn2: TButton;
        btn3: TButton;
        procedure btn1Click(Sender: TObject);
        procedure btn2Click(Sender: TObject);
        procedure btn3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      //newitem:TListItem; //超级列表框一定要在这里申明 不知道为什么
      //一个程序只用一次就可以了,放在按纽事件里有BUG  坑爹的
    
    implementation
      type
       Snapshot32=record //记录类型的名称
       A1:Integer;
       A2:Integer;
       A3:Integer;
       A4:Integer;
       A5:Integer;
       A6:Integer;
       A7:Integer;
       A8:Integer;
       A9:Integer;
       A10:array[0..259]of char;
       end;
    
        function CreateToolhelp32Snapshot(x,y: Integer): Integer;
    stdcall; external 'kernel32.dll' name 'CreateToolhelp32Snapshot';
        function Process32Next(x:Integer;VAR y: Snapshot32): Integer;
    stdcall; external 'kernel32.dll' name 'Process32Next';
        function Process32First(x:Integer;VAR y: Snapshot32): Integer;
    stdcall; external 'kernel32.dll' name 'Process32First';
        function CloseHandle(x:Integer): Integer;
    stdcall; external 'kernel32.dll' name 'CloseHandle';
    
    {$R *.dfm}
    
    procedure TForm1.btn1Click(Sender: TObject);
    var i,x:Integer;
        m:string;
        k:Snapshot32;
        newitem:TListItem;
    begin
        ListView.Clear;
        i:=CreateToolhelp32Snapshot(2,0);
        k.A1:=1024;
        x:=Process32First(i,k) ;
        while x<>0 do
        begin
          newitem:=Listview.Items.Add;    //要在循环里放入这个 否则他一直加入的是第
          //一行   理解的是 超级列表框添加一行 反回新的行数  下面是新行数的标题 和新
          //行数的列添加
          //循环后再一次添加新一行 ,返回新的行数………依次这样
          //超级列表框增加列表项目为属性 Columns 这里设置 然后必须要把属性ViewStyle
          //设置为vsreport
          newitem.Caption:=k.A10;
          newitem.SubItems.Add(IntToStr(k.A3));
          x:=Process32Next(i,k);
        end;
        CloseHandle(x);
    end;
    
    procedure TForm1.btn2Click(Sender: TObject);
    begin
       if (ListView.Items.count<>0)and (ListView.Selected<>nil) then
       //如果超级列表框总数不为0 且选中项不为空,如果不选中直接读项目值发生内存错误
        begin
         ShowMessage(ListView.Selected.Caption);   //返回选中行标题
         ShowMessage(ListView.Selected.SubItems.Strings[0]); //返回选中行第二列中的值
    
          //ShowMessage(ListView.Selected.SubItems.Strings[1]);
          //返回选中行第三列中的值 这里没有第三列
    
          //listview.Items[i].SubItems.strings[n];//读i行第n列
           ShowMessage(ListView.Items[1].SubItems.strings[0]);
        end;
       //ShowMessage(IntToStr(ListView.Items.count)); //超级列表框项目总数
    
        //ShowMessage(ListView.Items[0].caption); //读第一行标题
        //ShowMessage(ListView.Items[0].SubItems.strings[0]); //读1行第1列
    end;
    
    procedure TForm1.btn3Click(Sender: TObject);
        var i:Integer;
    begin
           //按顺序删除
          // if ListView.Items.count<>0 then    //如果超级列表框总数不为0
          // begin
           //   ListView.Items[0].Delete();    //删除第一行
           //end;
    
           //按选中项删除
          // if (ListView.Items.count<>0)and (ListView.Selected<>nil) then
          // //如果超级列表框总数不为0 且选中项不为空
          // begin
          //    ListView.Selected.Delete();    //删除选中项
          // end;
    
           //按标题删除
           for i:=ListView.Items.Count-1 downto 0 Do
           begin
             if ListView.Items[i].Caption ='System'  then
             begin
                  ShowMessage('zhaodaole');
                  ListView.Items[i].Delete(); //删除当前选中行
             end;
    
           end;
    end;
    
    end.
  • 相关阅读:
    MySQL的max()函数使用时遇到的小问题
    scp命令需要指定端口时要紧跟在scp后
    linux系统之间基于密钥对免输入密码登陆
    c++的引用用法
    预测模型
    mysql出现ERROR 1366 (HY000):的解决办法
    R语言可视化--颜色
    R语言可视化--ggplot函数
    R语言可视化--qplot函数
    R语言可视化二
  • 原文地址:https://www.cnblogs.com/qq32175822/p/3143930.html
Copyright © 2020-2023  润新知