Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Jobthread für Client / Server Protokoll. Fehler im Protokoll (https://www.delphipraxis.net/121517-jobthread-fuer-client-server-protokoll-fehler-im-protokoll.html)

Jackie1983 29. Sep 2008 15:57


Jobthread für Client / Server Protokoll. Fehler im Protokoll
 
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

sirius 29. Sep 2008 16:08

Re: Jobthread für Client / Server Protokoll. Fehler im Proto
 
Eher so:
Delphi-Quellcode:
fClient.Socket.SendBuf(PChar(s),length(s));

Jackie1983 30. Sep 2008 15:11

Re: Jobthread für Client / Server Protokoll. Fehler im Proto
 
werde ich ändern, und der rest müste doch eigentlich ok sein?


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:39 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz