|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
一段代码:
定义:
procedure IdUDPServerLogUDPRead(Sender: TObject; AData:TBytes;
ABinding: TIdSocketHandle);
实现:
procedure TFrmLogData.IdUDPServerLogUDPRead(Sender: TObject; AData: TBytes;
ABinding: TIdSocketHandle);
var
LogStr: string;
begin
try
SetLength(LogStr, Length(AData));
Move(AData[0], LogStr[1], Length(AData));
LogMsgList.Add(LogStr);
except
end;
end;
为何提示说未定义的数据类型呢,我查资料说delphi已经有TBytes这种类型了啊
错误提示:Undeclared identifier 'TBytes'
完整源码:
unit LogDataMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, IniFiles, IdBaseComponent,
IdComponent, IdUDPBase, IdUDPServer, IdSocketHandle,IdGlobal, Menus;
type
TFrmLogData = class(TForm)
Label3: TLabel;
Label4: TLabel;
Timer1: TTimer;
IdUDPServerLog: TIdUDPServer;
StartTimer: TTimer;
MainMenu: TMainMenu;
MainMenu_LogData: TMenuItem;
CloseTimer: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure WriteLogFile();
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure StartTimerTimer(Sender: TObject);
procedure MainMenu_LogDataClick(Sender: TObject);
procedure CloseTimerTimer(Sender: TObject);
procedure IdUDPServerLogUDPRead(Sender: TObject; AData:TBytes;
ABinding: TIdSocketHandle);
private
LogMsgList: TStringList;
m_boRemoteClose: Boolean;
{ Private declarations }
public
procedure MyMessage(var MsgData: TWmCopyData); message WM_COPYDATA;
{ Public declarations }
end;
var
FrmLogData: TFrmLogData;
{This file is generated by DeDe Ver 3.50.02 Copyright (c) 1999-2002 DaFixer}
implementation
uses LDShare, Grobal2, HUtil32, LogManage;
{$R *.DFM}
procedure TFrmLogData.FormCreate(Sender: TObject);
var
Conf: TIniFile;
nX, nY: Integer;
begin
g_dwGameCenterHandle := Str_ToInt(ParamStr(1), 0);
nX := Str_ToInt(ParamStr(2), -1);
nY := Str_ToInt(ParamStr(3), -1);
if (nX >= 0) or (nY >= 0) then begin
Left := nX;
Top := nY;
end;
m_boRemoteClose := False;
SendGameCenterMsg(SG_FORMHANDLE, IntToStr(Self.Handle));
SendGameCenterMsg(SG_STARTNOW, '正在启动日志服务器...');
LogMsgList := TStringList.Create;
StartTimer.Enabled := True;
end;
procedure TFrmLogData.FormDestroy(Sender: TObject);
begin
LogMsgList.Free;
end;
procedure TFrmLogData.CloseTimerTimer(Sender: TObject);
begin
Caption := '正在关闭...';
if SearchStatus then QuitFlag := True else Close;
end;
procedure TFrmLogData.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if m_boRemoteClose then exit;
if Application.MessageBox('是否确认退出服务器?',
'提示信息',
MB_YESNO + MB_ICONQUESTION) = IDYES then begin
m_boRemoteClose := True;
CloseTimer.Enabled := True;
end else CanClose := False;
end;
procedure TFrmLogData.Timer1Timer(Sender: TObject);
begin
WriteLogFile();
end;
procedure TFrmLogData.WriteLogFile();
var
I: Integer;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
sLogDir, sLogFile: string;
s2E8: string;
F: TextFile;
begin
if LogMsgList.Count <= 0 then exit;
DecodeDate(Date, Year, Month, Day);
DecodeTime(Time, Hour, Min, Sec, MSec); //ExtractFilePath(ParamStr(0)) +
sLogDir := sBaseDir + IntToStr(Year) + '-' + IntToString(Month) + '-' + IntToString(Day);
if not DirectoryExists(sLogDir) then begin
CreateDirectoryA(PChar(sLogDir), nil);
end;
sLogFile := sLogDir + '\Log-' + IntToString(Hour) + 'h' + IntToString((Min div 10) * 2) + 'm.txt';
Label4.Caption := sLogFile;
try
AssignFile(F, sLogFile);
if not FileExists(sLogFile) then Rewrite(F)
else Append(F);
for I := 0 to LogMsgList.Count - 1 do begin
Writeln(F, LogMsgList.Strings[I] + #9 + FormatDateTime('yyyy-mm-dd hh:mm:ss', Now));
Flush(F)
end;
LogMsgList.Clear;
finally
CloseFile(F);
end;
end;
procedure TFrmLogData.MainMenu_LogDataClick(Sender: TObject);
begin
FrmLogManage.Show;
end;
procedure TFrmLogData.MyMessage(var MsgData: TWmCopyData);
var
sData: string;
//ProgramType: TProgamType;
wIdent: Word;
begin
wIdent := HiWord(MsgData.From);
// ProgramType:=TProgamType(LoWord(MsgData.From));
sData := StrPas(MsgData.CopyDataStruct^.lpData);
case wIdent of //
GS_QUIT: begin
m_boRemoteClose := True;
CloseTimer.Enabled := True;
Close();
end;
1: ;
2: ;
3: ;
end; // case
end;
procedure TFrmLogData.StartTimerTimer(Sender: TObject);
var
Conf: TIniFile;
boMinimize: Boolean;
begin
StartTimer.Enabled := False;
Conf := TIniFile.Create('.\LogData.ini');
if Conf <> nil then begin
sBaseDir := Conf.ReadString('Setup', 'BaseDir', sBaseDir);
sServerName := Conf.ReadString('Setup', 'Caption', sServerName);
sServerName := Conf.ReadString('Setup', 'ServerName', sServerName);
nServerPort := Conf.ReadInteger('Setup', 'Port', nServerPort);
boMinimize := Conf.ReadBool('Setup', 'Minimize', True);
Conf.Free;
end;
Caption := sCaption + ' (' + sServerName + ')';
IdUDPServerLog.DefaultPort := nServerPort;
IdUDPServerLog.Active := True;
if boMinimize then Application.Minimize;
SendGameCenterMsg(SG_STARTOK, '日志服务器启动完成...');
end;
procedure TFrmLogData.IdUDPServerLogUDPRead(Sender: TObject; AData: TBytes;
ABinding: TIdSocketHandle);
var
LogStr: string;
begin
try
SetLength(LogStr, Length(AData));
Move(AData[0], LogStr[1], Length(AData));
LogMsgList.Add(LogStr);
except
end;
end;
end.
因為你的uses裡面沒有關於TBytes類型的資料
可能要去查看看'TBytes 在哪個lib,加進去使用
|
|