a.pas

来自「采用Delphi编程」· PAS 代码 · 共 47 行

PAS
47
字号
unit a;

interface

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

type
  TForm1 = class(TForm)
    udp1: TCnUDP;
    mmo1: TMemo;
    btn1: TButton;
    procedure udp1DataReceived(Sender: TComponent; Buffer: Pointer;
      Len: Integer; FromIP: String; Port: Integer);
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.udp1DataReceived(Sender: TComponent; Buffer: Pointer;
  Len: Integer; FromIP: String; Port: Integer);
begin
  mmo1.Lines.Add(FromIP);
end;

procedure TForm1.btn1Click(Sender: TObject);
var
 sBuff:array [1..1024] of Char;
 sInfo:String;
begin
 sInfo:='hello world!';
 sBuff:=sInfo^;
 udp1.SendBuffer(sBuff,Length(sBuff));
end;

end.

⌨️ 快捷键说明

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