Skip to content

Commit

Permalink
refactor: More Application.ProcessMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
gcarreno committed Dec 16, 2023
1 parent 35e7c56 commit 23e67f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/forms/forms.main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ object frmMain: TfrmMain
Menu = mmMain
Position = poDefault
SessionProperties = 'Top;Left;Width;Height;WindowState;pcMain.ActivePage;edtStartIP.Text;edtEndIP.Text'
LCLVersion = '3.99.0.0'
OnCreate = FormCreate
OnDestroy = FormDestroy
object pcMain: TPageControl
Left = 0
Height = 500
Top = 0
Width = 800
ActivePage = tsScan
ActivePage = tsMyIP
Align = alClient
TabIndex = 1
TabIndex = 0
TabOrder = 0
object tsMyIP: TTabSheet
Caption = '&My IP'
ClientHeight = 466
ClientHeight = 469
ClientWidth = 790
object panMyIPButtons: TPanel
Left = 0
Expand Down Expand Up @@ -65,7 +64,7 @@ object frmMain: TfrmMain
end
object tsScan: TTabSheet
Caption = '&Scan IP Range'
ClientHeight = 466
ClientHeight = 469
ClientWidth = 790
object lblStartIP: TLabel
Left = 4
Expand Down Expand Up @@ -165,7 +164,7 @@ object frmMain: TfrmMain
end
object tsPing: TTabSheet
Caption = '&Ping'
ClientHeight = 466
ClientHeight = 469
ClientWidth = 790
object Panel1: TPanel
Left = 0
Expand All @@ -182,7 +181,7 @@ object frmMain: TfrmMain
end
object tsTraceRoute: TTabSheet
Caption = '&Trace Route'
ClientHeight = 466
ClientHeight = 469
ClientWidth = 790
object Panel2: TPanel
Left = 0
Expand Down
8 changes: 6 additions & 2 deletions src/forms/forms.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ procedure TfrmMain.InitShortcuts;

procedure TfrmMain.EnableControls;
begin
actMyIPFetch.Enabled:= True;
pcMain.Enabled:= True;
end;

procedure TfrmMain.DisableControls;
begin
actMyIPFetch.Enabled:= False;
pcMain.Enabled:= False;
end;

procedure TfrmMain.alMainUpdate(AAction: TBasicAction; var Handled: Boolean);
Expand Down Expand Up @@ -168,12 +168,14 @@ procedure TfrmMain.actMyIPFetchExecute(Sender: TObject);
repeat
try
memMyIPLog.Append(Format('Attempting to contact "%s"', [ cMyIPURL[index] ]));
Application.ProcessMessages;
httpResult:= httpClient.SimpleGet(Format('http://%s', [ cMyIPURL[index] ]));
success:= True;
except
on E: Exception do
begin
memMyIPLog.Append(Format('ERROR(%s): %s', [ cMyIPURL[index], E.Message ]));
Application.ProcessMessages;
success:= False;
end;
end;
Expand All @@ -182,10 +184,12 @@ procedure TfrmMain.actMyIPFetchExecute(Sender: TObject);
if success then
begin
memMyIPLog.Append(Format('From "%s", your IP is "%s"', [ cMyIPURL[index], Trim(httpResult) ]));
Application.ProcessMessages;
end
else
begin
memMyIPLog.Append('Something went horribly wrong');
Application.ProcessMessages;
end;
finally
httpClient.Free;
Expand Down

0 comments on commit 23e67f6

Please sign in to comment.