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

📄 commondef.~pas

📁 使用delphi自带的控件
💻 ~PAS
字号:
unit CommonDef;

interface
const
  //Log on/off the server
  Login = 'Login';
  Logoff = 'Logoff';
  LoginOk = 'Login Ok';
  LogoffOk = 'Logoff Ok';
  LoginError = 'Login ERROR';
  LogoffError = 'Logoff ERROR';

  //set status of itself and send to server
  SetStatus = 'Set-Status';
  SetStatusOk = 'Set-Status OK';
  SetStatusError = 'Set-Status ERROR';

  //get corrman list from server
  GetCList = 'Get-CList';
  GetCListOk = 'Get-CList OK';
  GetCListError = 'Get-CList ERROR';

  //add a corrman to list, send to server
  AddCorrMan = 'Add-CorrMan';
  AddCorrManOk = 'Add-CorrMan OK';
  AddCorrManError = 'Add-CorrMan ERROR';

  //delete the corrman from the list, send to server
  DelCorrMan = 'Del-CorrMan';
  DelCorrManOk = 'Del-CorrMan OK';
  DelCorrManError = 'Del-CorrMan ERROR';

  //send the corrman status to client
  SetCStatus = 'Set-CStatus';
  SetCStatusOk = 'Set-CStatus OK';
  SetCStatusError = 'Set-CStatus ERROR';

type
  TCorrManStatus = (cnsOffline, cnsOnline, cnsBusy,
    cnsLeave, cnsEating, cnsBeingBack);

  TMyCorrMan = record
  UserName      : String;
  UserTitle     : String;
  EmailAddress  : String;
  MessageCount  : Integer;
  Status        : TCorrManStatus;
  end;

function EncodeCorrManPropertyLine(CorrMan: TMyCorrMan): String;
function DecodeCorrManPropertyLine(var CorrMan: TMyCorrMan; Line: String): Boolean;

implementation
{*******************************************
服务器端将发送给用户的详细信息数据传输给
客户端之前,将指定的数据组装成用户可以
理解的数据形式
*******************************************}
function EncodeCorrManPropertyLine(CorrMan: TMyCorrMan): String;
begin
  Result := CorrMan.UserName + ' ' + CorrMan.UserTitle + ' '
    + CorrMan.EmailAddress + ' ' + IntToStr(CorrMan.MessageCount)
    + IntToStr(Integer(CorrMan.Status));
end;

{*******************************************
客户端收到来自服务器的联系人详细信息数据时,
以结构体方式返回给调用者
*******************************************}
function DecodeCorrManPropertyLine(var CorrMan: TMyCorrMan; Line: String): Boolean;
var
  I: Integer;
  Str: string;
begin
  Str := Line;

  //User name
  I := Pos(' ', Str);
  if (I < 1) then
  begin
    Result := False;
    Exit;
  end;
  CorrMan.UserName := Copy(Str, 1, I-1);
  Str := Copy(Str, I+1, Length(Str)-I);

  //user Caption
  I := Pos(' ', Str);
  if (I < 1) then
  begin
    Result := False;
    Exit;
  end;
  CorrMan.UserTitle := Copy(Str, 1, I-1);
  Str := Copy(Str, I+1, Length(Str)-I);

  //email address
  I := Pos(' ', Str);
  if (I < 1) then
  begin
    Result := False;
    Exit;
  end;
  CorrMan.EmailAddress := Copy(Str, 1, I-1);
  Str := Copy(Str, I+1, Length(Str)-I);

  //message count
  I := Pos(' ', Str);
  if (I < 1) then
  begin
    Result := False;
    Exit;
  end;
  CorrMan.MessageCount := StrToInt(Copy(Str, 1, I-1));
  Str := Copy(Str, I+1, Length(Str)-I);

  //status
  I := Pos(' ', Str);
  if (I < 1) then
  begin
    Result := False;
    Exit;
  end;
  CorrMan.Status := TCorrManStatus(StrToInt(Str));

  Result := True;

end;


end.

⌨️ 快捷键说明

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