Recent

Author Topic: Ping a couple of computers  (Read 19034 times)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Ping a couple of computers
« Reply #15 on: November 06, 2015, 09:54:36 am »
Ah. that make sense.

Thanks.
Too much regarding the other suggestion ?   ;)

No problemo. New form, 5 labels one button, code looking like this (will hopefully get you going). I cheated though by combining the two mentioned solutions into one.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     Label3: TLabel;
  19.     Label4: TLabel;
  20.     Label5: TLabel;
  21.     procedure Button1Click(Sender: TObject);
  22.   private
  23.     { private declarations }
  24.   public
  25.     { public declarations }
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35.  
  36. { TForm1 }
  37.  
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. Var
  40.   i : Integer;
  41.   LabelArray : Array[1..5] of TLabel;
  42. begin
  43.   // Temp disable button
  44.   (Sender as TButton).Enabled := false;
  45.  
  46.   // Fill array with labels
  47.   For i := Low(labelArray) to High(labelArray) do
  48.   begin
  49.     LabelArray[i] := FindComponent('Label' + IntToStr(i)) as TLabel;
  50.   end;
  51.  
  52.   For i := 1 to 5 do
  53.   begin
  54.     // Do some other stuff
  55.  
  56.     // Change colour based on result from other stuff done above
  57.     // As for an example: use odd/even
  58.     if Odd(i)
  59.     then LabelArray[i].Font.Color:= clGreen
  60.     else LabelArray[i].Font.Color:= clRed;
  61.  
  62.     // Make sure GUI gets updated between changes
  63.     Application.ProcessMessages;
  64.  
  65.     // Perform some delay in order to humanly be able to follow GUI changes
  66.     Sleep(3000);
  67.   end;
  68.  
  69.   // Restore default colour
  70.   For i := 1 to 5
  71.     do LabelArray[i].Font.Color:= clDefault;
  72.  
  73.   // Enable button
  74.   (Sender as TButton).Enabled := True;
  75. end;
  76.  
  77. end.
  78.  

Quote
Is there a possibility to put more condition into a "If" statement?

Like:  If i = 4 or 7 or 12 then

instead of
if i = 4 then
if i = 7 then
if i = 12 then
Again several solutions available, depending on the exact circumstances.

Code: Pascal  [Select][+][-]
  1. If  (
  2.   (i = 4) or
  3.   (i =7) or
  4.   (i = 12)
  5. )
  6. then
  7.  
Or
Code: Pascal  [Select][+][-]
  1. Case i of
  2.   1,2,3,4: begin {do something when i = 1,2,3 or 4} end;
  3.   5 : begin  {do something when i = 5} end;
  4.   else begin {do something if i didn't match any of the above values } end;
  5. end;
  6.  
« Last Edit: November 06, 2015, 09:59:07 am by molly »

jma_sp

  • Full Member
  • ***
  • Posts: 154
  • El conocimiento si ocupa lugar.
Re: Ping a couple of computers
« Reply #16 on: November 06, 2015, 01:15:46 pm »
OK, if you download the lastest version of synapse, actually 40 from:

http://synapse.ararat.cz/doku.php/download

Uncompress it. It contains two simple demo / examples:

source\demo\scan

It have an example of multithreaded ping, fast for a Class C Network, best that a simple thread. :), best option.

Ignore .dpr for delphi project file, read .pas.

The other is testping.pas

\source\demo\FreePascal
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

nomorelogic

  • Full Member
  • ***
  • Posts: 196
Re: Ping a couple of computers
« Reply #17 on: November 06, 2015, 03:39:08 pm »
Ah. that make sense.

Thanks.

Is there a possibility to put more condition into a "If" statement?

Like:  If i = 4 or 7 or 12 then

instead of
if i = 4 then
if i = 7 then
if i = 12 then

in this case I test "i" as included in "set of ..."

if i in [4,7,12] then ....

christian1987

  • New Member
  • *
  • Posts: 30
Re: Ping a couple of computers
« Reply #18 on: November 06, 2015, 03:56:13 pm »
So easy:
Lab:=
Form1.FindComponent('KFZ'+IntToStr(I)) as TLabel;

christian1987

  • New Member
  • *
  • Posts: 30
Re: Ping a couple of computers
« Reply #19 on: November 06, 2015, 04:44:14 pm »
Lab:=KFZ1.parent.
FindComponent('KFZ'+IntToStr(I)) as TLabel;

 

TinyPortal © 2005-2018