📄 unit1.dfm
字号:
object Form1: TForm1
Left = 192
Top = 114
Width = 362
Height = 510
Caption = #21457#36865#31383#20307
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 24
Top = 296
Width = 84
Height = 13
Caption = #21457#36865#30340#23383#33410#25968
end
object Label2: TLabel
Left = 24
Top = 328
Width = 126
Height = 13
Caption = #27599#21457#36865#19968#20010#21253#30340#38388#38548
end
object Label3: TLabel
Left = 24
Top = 352
Width = 140
Height = 13
Caption = #35748#20026#26159#20002#21253#30340#36229#26102#26102#38388
end
object Label4: TLabel
Left = 168
Top = 352
Width = 126
Height = 13
Caption = #21457#36865#38431#21015#30340#23481#32435#25968#37327
end
object Label5: TLabel
Left = 24
Top = 392
Width = 84
Height = 13
Caption = #27599#20010#21253#30340#22823#23567
end
object Label6: TLabel
Left = 168
Top = 392
Width = 66
Height = 13
Caption = #25509#25910#31471#30340'IP'
end
object Button1: TButton
Left = 55
Top = 442
Width = 78
Height = 25
Caption = #21457#36865
TabOrder = 0
OnClick = Button1Click
end
object Memo1: TMemo
Left = 19
Top = 17
Width = 309
Height = 277
Lines.Strings = (
'{*******************************************************}'
'{ '#21333#20803#21517#65306' UntUdpCtl.pas }'
'{ '#21019#24314#26085#26399#65306'2006-6-9 14:20:12 }'
'{ '#21019#24314#32773' '#39532#25935#38026' }'
'{ '#21151#33021#65306' V1.0 }'
'{ UDP'#30340#23433#20840#20256#36755#25511#21046#31867#26242#26102#22522#20110'NMUDP '
'}'
'{ '#36127#36131' }'
'{ '#20998#21253#25511#21046' }'
'{ '#24212#31572#25511#21046' }'
'{ '#37325#21457#25511#21046' }'
'{ '#21253#22836#22823#20110'CSafeUdpData'#30340#25968#25454#23601#26159#26412#31867#30340' '
'}'
'{ '#25511#21046#22788#29702#21327#35758' }'
'{*******************************************************}'
''
'unit UntUdpCtl;'
''
'interface'
''
'uses Classes, NMUDP, sysutils;'
''
'const'
' CSafeUdpData = 100000; {UDP'#25968#25454#25511#21046#21253#30340#26368#20302#21629#20196
#21495'}'
' CSafeUdpData_Uses = 200000; {'#29992#25143#20351#29992#30340#21629#20196'}'
' CSafeUdpData_RecvResp = CSafeUdpData_Uses + 1; //'#22238
#24212#25910#21040#21629#20196
''
'type'
' EUdpCtlReTryNoResp = class(Exception); {'#37325#35797'N'#27425#21518#25253
#38169'}'
' EUdpCtlTimeOut = class(Exception); {'#19968#30452#37325#35797#30452#21040#36229#26102'}'
' {'#20002#21253#30340#22788#29702#26041#24335'}'
' SHeadLv = (SDoDrop {'#37325#35797'N'#27425#21518#23601#19981#20877#21457#36865'}, '
'SDoError {'
#37325#35797'N'#27425#21518#25253#38169'}, SDoTimeOut {'#19968#30452#37325#35797#30452#21040#36229#26102'});'
' {'#21253#22836'}'
' PSafeUdphead = ^RSafeUdphead;'
' RSafeUdphead = packed record'
' Id: Integer; {'#21629#20196#21495'}'
' Part, TotPart: Byte; {'#21253#30340#31532#20960#37096#20998','#20849#26377#20960#37096#20998',}'
' Lv: SheadLv; {'#21253#30340#31561#32423' 0'#12289' 1'#12289' 2}'
' PackedId: Cardinal; {'#21253#30340'ID'#21495' '#65292#22914#26524#27492#21495#22823#20110'0'#35828#26126
#38656#35201
#22238#24212'}'
' Size: Cardinal; {'#22823#23567'}'
' end;'
' {'#25968#25454#21253'}'
' PSafeUdpData = ^RSafeUdpData;'
' RSafeUdpData = packed record'
' Head: RSafeUdphead; {'#21253#22836'}'
' Data: Pointer; {'#21253#20307'}'
' SendTime: Cardinal; {'#21457#36865#26102#38388'}'
' ReTryCount: Byte; {'#37325#35797#27425#25968'}'
' end;'
' {'#28151#21512#21253#31867'}'
' TDataMixer = class'
' public'
' Id: Cardinal; {'#21253#30340'ID}'
' BeginTime: Cardinal; {'#24320#22987#28151#21512#30340#26102#38388'}'
' TotPart, CurrPart: Byte; {'#21253#30340#24635#25968#65292#29616#26377#30340#21253#25968'}'
' DataList: TStrings; {'#25968#25454#21015#34920'}'
' constructor Create();'
' destructor Destroy; override;'
' end;'
''
' SUDPSendKind = (SUSKFreeWindows {'#28369#21160#31383#21475#27169#24335'}, '
'SUSKOnlyOne {'#27599#27425#21482#21457#36865#19968#20010#21629#20196#30452#21040#36820#22238#25165#32487#32493
'});'
' SUdpCtlState = (SRaiseExpection {'#25243#20986#24322#24120'}, '
'SUseErrorEvent {'#25191#34892#38169#35823#20107#20214'}); {Udp'#25511#21046#29366#24577'}'
' TudpCtl = class;'
' TUdpSenderThread = class(TThread) {'#25968#25454#21457#36865#22788#29702#32447#31243
'}'
' public'
' Owner: TudpCtl;'
' procedure Execute; override;'
' constructor Create(ISStop: boolean; IOwner: TudpCtl);'
' end;'
' TSafeUDPRecData = procedure(ISender: TudpCtl; IData: '
'Pointer; ISize: Cardinal;'
' IFromIP: string; IPort: integer) of object;'
' TSafeUDPError = procedure(Sender: TObject; IData: '
'PSafeUdpData; IErrorKind: SHeadLv) of object;'
' TudpCtl = class(TNMUDP)'
' private'
' FSendKind: SUDPSendKind;'
' FErrorKind: SUdpCtlState;'
' FFreeWindowsCount: Byte;'
' FPackedId: Cardinal;'
' procedure ClearOneData(iidx: Integer; IList: Tstrings); '
'overload; {'#37322#25918#19968#20010#21253'}'
' procedure ClearList(IList: TStrings); {'#28165#31354#21015#34920'}'
' function GetAnPackedId: Cardinal; {'#33719#21462#19968#20010#25968#25454#21253'ID}'
' function GetAnPackedData(IDataSize: integer): '
'PSafeUdpData; {'#33719#21462#19968#20010#21253'}'
' procedure CheckState; {'#29366#24577#26816#26597'}'
' procedure OnData(Sender: TComponent; NumberBytes: '
'Integer; FromIP: string; Port: integer); {'#22788#29702#25509#25910#25968#25454'}'
' protected'
' SenderThread: TUdpSenderThread; {'#21457#36865#22788#29702#32447#31243'}'
' SendedList, SendingList, DataMixList: TStrings; {'#24050#21457#36865#30340
#25968
#25454#21015#34920#65292#38431#21015#20013#31561#24453#21457#36865#30340#25968#25454#21015#34920'}'
' SendMemory: TMemoryStream; {'#27491#22312#21457#36865#32531#20914#65292#21644#21097
#20313#21457
#36865#32531#20914'}'
'//--------------------------------------------------------------' +
'----------------'
'// '#33258#21160#35302#21457#30340#20107#20214' 2006-6-5 '#39532#25935#38026
'//--------------------------------------------------------------' +
'----------------'
' procedure OnReSendEvent(Sender: TObject); {'#21040#26102#37325#21457
#20107
#20214'}'
' procedure OnTimeOutEvent(Sender: TObject); {'#25509#25910#36229#26102
#20107
#20214'}'
'//--------------------------------------------------------------' +
'----------------'
'// '#21487#20379#23376#31867#25913#20889#30340#26041#27861' 2006-6-9 '#39532#25935#38026
'//--------------------------------------------------------------' +
'----------------'
' procedure PackedData(var IBuff; ISize: Cardinal; Ilv: '
'SheadLv); {'#21253#35065#25968#25454'}'
' procedure UnPackedData(IMixer: TDataMixer); {'#21453#21253#35065#25968
#25454
'}'
' procedure AddToSendList(IId: string; IData: Pointer);'
' procedure DidSend(IData: PSafeUdpData); {'#23454#38469#30340#21457#36865
#36807
#31243'}'
' function CheckPacked(IData: PSafeUdphead): Integer;'
' function MixData(IData: PSafeUdpData; Iidx: integer): '
'boolean;'
' public'
' MaxReSendCount: Byte; {'#26368#22823#37325#35797#27425#25968' '#40664#35748#20026'3}'
' PeerSize: Word; {'#20998#21253#26102#27599#20010#21253#30340#22823#23567' '#40664#35748#20026'1024}'
' WaiteTimeOut, ReSendTime: Cardinal; {'#36229#26102#26102#38388' '#40664#35748
#20026'3000,'#20002#21253#37325#21457#26102#38388'500}'
' CurrRealData {'#24403#21069#30340#23454#38469#24050#32463#22788#29702#23436#27605#30340#21253'}: '
'TMemoryStream;'
' CurrDataSize: Cardinal; {'#24403#21069#25968#25454#30340#22823#23567'}'
' OnDataCase: TSafeUDPRecData; {'#29992#25143#33258#24049#30340#22788#29702#20107
#20214'}'
' OnDataError: TSafeUDPError; {'#25968#25454#38169#35823#26102#35302#21457#30340#20107#20214
'}'
'//--------------------------------------------------------------' +
'----------------'
'// '#23646#24615' 2006-6-9 '#39532#25935#38026
'//--------------------------------------------------------------' +
'----------------'
' {'#38169#35823#22788#29702#26041#24335' '#40664#35748#20026#20351#29992#20107#20214'}'
' property ErrorKind: SUdpCtlState read FErrorKind write '
'FErrorKind;'
' {'#21457#36865#27169#24335' '#40664#35748#20026#28369#21160#31383#21475#26041#24335'}'
' property SendKind: SUDPSendKind read FSendKind write '
'FSendKind;'
' {'#28369#21160#31383#21475#25968#37327' '#40664#35748#20026'3}'
' property FreeWindowsCount: Byte read FFreeWindowsCount '
'write FFreeWindowsCount;'
'//--------------------------------------------------------------' +
'----------------'
'// '#25552#20379#32473#22806#30028#30340#25509#21475' 2006-6-5 '#39532#25935#38026
'//--------------------------------------------------------------' +
'----------------'
' class procedure ClearOneData(IData: PSafeUdpData); '
'overload; {'#37322#25918#19968#20010#21253'}'
' {'#23433#20840#21457#36865#25968#25454' '#33258#21160#20998#21253'}'
' class function IsUdpCtlData(IData: Pointer; ISize: Integer):' +
' '
'boolean;'
' procedure SetCurrData(Idata: Pointer; ISize: Integer); {'#35774#32622
#24403#21069#30340#25968#25454'}'
' procedure SafeSendBuff(IIp: string; IPort: Word; var IBuff; '
'ISize: Cardinal;'
' Ilv: SheadLv); overload;'
' procedure SafeSendBuff(var IBuff; ISize: Cardinal; Ilv: '
'SheadLv = SDoError);'
' overload;'
' {'#23433#20840#25511#21046#25968#25454#22788#29702#36807#31243' '#36820#22238#20540#20026#26159#21542#38656#35201#20132#32473
#36923#36753#31243
#24207#32487#32493#22788#29702'}'
' function CaseData(IData: Pointer; IPeerIP: string; IPeerPort' +
', '
'IDataLen:'
' Integer): Boolean;'
' constructor Create(AOwner: TComponent); override;'
' destructor Destroy; override;'
' end;'
''
'implementation'
''
'uses IniFiles, windows, untfunctions, UntProctol, '
'pmybasedebug;'
''
'function OrderShort(List: TStringList; Index1, Index2: Integer):' +
' '
'Integer; {'#25490#24207'}'
'begin'
' try'
' Result := IfThen(StrToInt(List.Strings[Index1]) > '
'StrToInt(List.Strings[Index2]), 1, -1);'
' except'
' end;'
'end;'
'{ TudpCtl }'
''
'constructor TudpCtl.Create(AOwner: TComponent);'
'begin'
' inherited Create(AOwner);'
' MaxReSendCount := 3;'
' WaiteTimeOut := 3000;'
' PeerSize := 1024; //512 + 256;'
' FPackedId := 0;'
' ReSendTime := 500;'
' FSendKind := SUSKFreeWindows;'
' FErrorKind := SUseErrorEvent;'
' FFreeWindowsCount := 10;'
' SendedList := THashedStringList.Create;'
' SendingList := THashedStringList.Create;'
' DataMixList := THashedStringList.Create;'
' SendMemory := TMemoryStream.Create;'
' CurrRealData := TMemoryStream.Create;'
' SenderThread := TUdpSenderThread.Create(False, Self);'
' OnDataReceived := OnData;'
'end;'
''
'destructor TudpCtl.Destroy;'
'var'
' i: Integer;'
'begin'
' SenderThread.FreeOnTerminate := True;'
' SenderThread.Terminate;'
' Sleep(20);'
' for i := 0 to DataMixList.Count - 1 do'
' DataMixList.Objects[i].Free;'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -