Einzelnen Beitrag anzeigen

Jackie1983

Registriert seit: 12. Mär 2007
486 Beiträge
 
#1

Jobthread für Client / Server Protokoll. Fehler im Protokoll

  Alt 29. Sep 2008, 15:57
servus.....

habe ein einfaches Protokoll gebastelt. Nur leider bekomme ich hier noch einen Fehler. Weis aber leider nicht ganz genau wo..... es gibt bestimmt auch eine bessere Lösung als wie ich es hier gelöst habe....

Delphi-Quellcode:
  TCommandHandling = class(TObject)
  private
    fFrames : string;
    function fGet(index : integer) : string;
  public
    constructor Create(const ACmd: TCommand);
    //Parameter hinzufügen
    procedure AddParameter(const Value: TCommand); overload;
    procedure AddParameter(const Value: String); overload;
    procedure AddParameter(const Value: Integer); overload;
    //auslesen von befehl und parameter
    function GetCmd : TCommand;
    function GetParameter(const index : integer; AsType : TAsType) : variant;
    function GetParamaterCount : integer;
    //Setzen und auslesen der Frames
    function SendFrames(Terminator : Boolean=True) : string;
    procedure SetFrames(frames : string);
  end;

...

function TCommandHandling.fGet(index: integer): string;
var
  l : TStringlist;
begin
  l := TStringlist.Create;
  l.Text := FFrames;
  result := '';
  if index <= l.Count-1 then
    result := l.Strings[index];
  l.Free;
end;

constructor TCommandHandling.Create(const ACmd: TCommand);
begin
  FFrames := Inttostr(Integer(ACmd)) + #13;
end;

procedure TCommandHandling.AddParameter(const Value: TCommand);
begin
  AddParameter(Integer(Value));
end;

procedure TCommandHandling.AddParameter(const Value: String);
begin
  FFrames := FFrames + Value + #13;
end;

procedure TCommandHandling.AddParameter(const Value: Integer);
begin
  FFrames := FFrames + IntToStr(Value) + #13;
end;

function TCommandHandling.GetCmd: TCommand;
begin
  result := TCommand(StrToInt(fGet(0)));
end;

function TCommandHandling.GetParameter(const index: integer;
  AsType: TAsType): variant;
var
  str : string;
begin
  str := fGet(index);
  try
    case AsType of
      AsString : result := str;
      AsInteger : result := StrToInt(str);
    end;
  except
    case AsType of
      AsString : result := '';
      AsInteger : result := -1;
    end;
  end;
end;

function TCommandHandling.SendFrames(Terminator: Boolean): string;
begin
  result := fframes;
  if Terminator then //Default True
    result := fframes + #10;
end;

....
//senden
begin
  s := cmd.SendFrames;
  fClient.Socket.SendBuf(PChar(s)^,length(s));
end;
thx
  Mit Zitat antworten Zitat