⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 provided a modified version of this example that is designed to be more user friendly. It is coded i
💻 PAS
字号:
{*******************************************************************************

   WinLIRC Demo (c) 2002 Dominik Bruhn

   WinLIRC Demo (Modification 2005) (c) 2005 WavE (wav-e@wp.pl)

*******************************************************************************}

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ScktComp, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button3: TButton;
    GroupBox1: TGroupBox;
    Label5: TLabel;
    Label4: TLabel;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    cs: TClientSocket;
    Edit1: TEdit;
    Label16: TLabel;
    Edit2: TEdit;
    Label18: TLabel;
    Label3: TLabel;
    Memo1: TMemo;
    Memo2: TMemo;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Button4: TButton;
    Panel1: TPanel;
    procedure csConnect(Sender: TObject; Socket: TCustomWinSocket);
    procedure csConnecting(Sender: TObject; Socket: TCustomWinSocket);
    procedure csDisconnect(Sender: TObject; Socket: TCustomWinSocket);
    procedure csError(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure csLookup(Sender: TObject; Socket: TCustomWinSocket);
    procedure csRead(Sender: TObject; Socket: TCustomWinSocket);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button2.Enabled := False;
  Edit1.Color := clWindow;
  Edit2.Color := clWindow;
  Panel1.Color := clRed;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if (Edit1.Text = '') or (Edit2.Text = '') then
  begin
    Memo1.Lines.Add(' Error: Bad IP address or Port');
  end
  else
  begin
    cs.Address := Edit1.Text;
    cs.Port := StrToInt(Edit2.Text);
    cs.Active := True;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  cs.Active := False;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  cs.Active := False;
  Application.Terminate;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  cs.Active := False;
  Application.Terminate;
end;

procedure TForm1.csConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
  Memo1.Lines.Add(' Connected');
  Button1.Enabled := False;
  Button2.Enabled := True;
  Edit1.ReadOnly := True;
  Edit1.Color := clBtnFace;
  Edit2.ReadOnly := True;
  Edit2.Color := clBtnFace;
  Panel1.Color := clLime;
end;

procedure TForm1.csConnecting(Sender: TObject; Socket: TCustomWinSocket);
begin
  Memo1.Lines.Add(' Connecting');
  Button1.Enabled := False;
  Button2.Enabled := False;
  Edit1.ReadOnly := True;
  Edit1.Color := clBtnFace;
  Edit2.ReadOnly := True;
  Edit2.Color := clBtnFace;
  Panel1.Color := clYellow;
end;

procedure TForm1.csDisconnect(Sender: TObject; Socket: TCustomWinSocket);
begin
  Memo1.Lines.Add(' Disconnected');
  Button1.Enabled := True;
  Button2.Enabled := False;
  Edit1.ReadOnly := False;
  Edit1.Color := clWindow;
  Edit2.ReadOnly := False;
  Edit2.Color := clWindow;
  Panel1.Color := clRed;
end;

procedure TForm1.csError(Sender: TObject; Socket: TCustomWinSocket;
  ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
  Memo1.Lines.Add(' Error: ' + IntToStr(ErrorCode));
  Button1.Enabled := True;
  Button2.Enabled := False;
  Edit1.ReadOnly := False;
  Edit1.Color := clWindow;
  Edit2.ReadOnly := False;
  Edit2.Color := clWindow;
  Panel1.Color := clRed;
end;

procedure TForm1.csLookup(Sender: TObject; Socket: TCustomWinSocket);
begin
  Memo1.Lines.Add(' Lookup');
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  Memo2.Clear;
  Label2.Caption := '...';
  Label12.Caption := '...';
  Label13.Caption := '...';
  Label14.Caption := '...';
  Label15.Caption := '...';
end;

procedure TForm1.csRead(Sender: TObject; Socket: TCustomWinSocket);
var
  s, t : string;
  i : integer;
  partbeg, partend : integer;
  params : array[1..4] of string;
begin
  s := cs.Socket.ReceiveText;
  Memo2.Lines.Add(' ' + s);
  partbeg := 0;
  partend := 0;
  t := s;
  for i := 1 to 3 do
  begin
    partend := Pos(' ', t);
    params[i] := Copy(t, 1, partend - 1);
    Delete(t, 1, partend);
  end;
  params[4] := t;
  Delete(params[4], length(params[4]), 1);
  Label2.Caption := params[4] + ' -> ' + params[3];
  Label12.Caption := params[1];
  Label13.Caption := params[2];
  Label14.Caption := params[3];
  Label15.Caption := params[4];
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -