CfgParams.pas 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. unit CfgParams;
  2. interface
  3. uses Classes, SysUtils;
  4. const
  5. cfgName = 'cfgPort.txt';
  6. type
  7. TScCfgPort = class
  8. private
  9. FPort: Integer;
  10. FIP: string;
  11. FFileDir: string;
  12. FPortStr: TStringList;
  13. public
  14. constructor Create;
  15. destructor Destroy; override;
  16. procedure ReadPort;
  17. procedure WritePort;
  18. property Port: Integer read FPort write FPort;
  19. property IP: string read FIP write FIP;
  20. property FileDir: string read FFileDir write FFileDir;
  21. end;
  22. implementation
  23. { TScCfgPort }
  24. constructor TScCfgPort.Create;
  25. begin
  26. FPortStr := TStringList.Create;
  27. end;
  28. destructor TScCfgPort.Destroy;
  29. begin
  30. FPortStr.Free;
  31. inherited;
  32. end;
  33. procedure TScCfgPort.ReadPort;
  34. begin
  35. if FileExists(FFileDir + cfgName) then
  36. FPortStr.LoadFromFile(FFileDir + cfgName)
  37. else Exit;
  38. if FPortStr.Count > 0 then
  39. begin
  40. FPort := StrToInt(FPortStr.Strings[0]);
  41. FIP := FPortStr.Strings[1];
  42. end;
  43. end;
  44. procedure TScCfgPort.WritePort;
  45. begin
  46. FPortStr.Clear;
  47. FPortStr.Add(IntToStr(FPort));
  48. FPortStr.Add(FIP);
  49. FPortStr.SaveToFile(FFileDir + cfgName);
  50. end;
  51. end.