salut julio mon projet c'est faire le ping sur un reseau alors dans ma forme il y'a un listview qui contient 255 ordinateur(par imagelist) unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ImgList, ComCtrls, IniFiles, ExtCtrls, UPingUtils; type TForm1 = class(TForm) ListView1: TListView; ImageList1: TImageList; Button6: TButton; Button7: TButton; PingMonitor1: TPingMonitor; procedure Button6Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure PingMonitor1Echo(Sender: TObject; Timing: TDateTime; PipeHandle: Cardinal; PacketId: Integer; BufferSize: Cardinal; SAddr: String; RTT: Cardinal; TTL: Byte); procedure PingMonitor1Timeout(Sender: TObject; Timing: TDateTime; PipeHandle, PacketId: Cardinal); private { Déclarations privées } public { Déclarations publiques } function FindIndex(APipeHandle: DWord): Integer; end; Tposte = record PipeHandle: DWord; ItemIndex: Integer; end; Tlistepostes=array of Tposte; var Form1: TForm1; Nbrpostes:byte=8; Listepostes:Tlistepostes; implementation uses Unit2; {$R *.dfm} //listView1.ItemIndex:= FindIndex(0); //listView1.Selected.ImageIndex:= 1 function TForm1.FindIndex; begin for Result:= 0 to Length(ListePostes)- 1 do if ListePostes[Result].PipeHandle= APipeHandle then Exit; result:= -1 end; procedure TForm1.Button6Click(Sender: TObject); var I: Byte; begin with TIniFile.Create(ExtractFilePath(Application.ExeName) +'config.ini') do try for I:= 1 to 255 do WriteString('USER_IP', '192.168.0.'+IntToStr(I), 'Y'); finally Free end end; procedure TForm1.Button7Click(Sender: TObject); var I: Byte; Section: TStrings; S: String; ListItem: TListItem; begin with TIniFile.Create(ExtractFilePath(Application.ExeName) +'config.ini') do try Section:= TStringList.Create; ReadSection('USER_IP', Section); for I:= 0 to Section.Count- 1 do begin SetLength(ListePostes, Length(ListePostes)+1); with ListePostes[Length(ListePostes)-1] do begin PipeHandle:= PingMonitor1.AddPipeEx(Section[I]); ListItem:= ListView1.Items.add; ListItem.ImageIndex:= 0; ListItem.Caption:= Section[I]; ItemIndex:= ListItem.Index end end finally Section.Free; Free end end; procedure TForm1.PingMonitor1Echo(Sender: TObject; Timing: TDateTime; PipeHandle: Cardinal; PacketId: Integer; BufferSize: Cardinal; SAddr: String; RTT: Cardinal; TTL: Byte); begin listView1.ItemIndex:= FindIndex(PipeHandle); listView1.Selected.ImageIndex:= 01 end; procedure TForm1.PingMonitor1Timeout (Sender: TObject; Timing: TDateTime; PipeHandle, PacketId: Cardinal); begin listView1.ItemIndex:= FindIndex(PipeHandle); listView1.Selected.ImageIndex:= 02 end; end. danc je veut faire pour chaque ordinateur dans le listview un popupmenu (donc 255popup menu) pour activer l'ordinateur ou le suspendre merci bien julio
|