Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. unit Kompaniya_unit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8. Classes, SysUtils, Garaji_unit;
  9.  
  10. const
  11. Garaj_Slot = 100;
  12.  
  13. type
  14. TKompaniya = class
  15. private
  16. Mas: array[1..Garaj_Slot] of TGaraji;
  17. Mas_First, Mas_Last: integer;
  18. Mas_Count: integer;
  19. public
  20. constructor Create();
  21.  
  22. function Add_Garaj(aGaraj_Info: TGaraji): boolean;
  23. function Del_Garaj: boolean;
  24.  
  25. function Get_Garaz_Zanat_Slot: integer; {Выдает количество занятых мест}
  26.  
  27. function Save(Save_File: string): boolean;
  28. function Load(Load_File: string): boolean;
  29. end;
  30.  
  31. implementation
  32.  
  33. constructor TKompaniya.Create();
  34. begin
  35. Mas_First := 1;
  36. Mas_Last := 1;
  37. Mas_Count := 0;
  38. end;
  39.  
  40. function TKompaniya.Add_Garaj(aGaraj_Info: TGaraji): boolean;
  41. begin
  42. Result := False;
  43.  
  44. if Mas_Count <> Garaj_Slot then
  45. begin
  46. Mas[Mas_Last] := aGaraj_Info;
  47. Mas_Last := Mas_Last + 1;
  48. Mas_Count := Mas_Count + 1;
  49. if Mas_Last > Garaj_Slot then
  50. Mas_Last := 1;
  51. Result := True;
  52. end;
  53. end;
  54.  
  55. function TKompaniya.Del_Garaj: boolean;
  56. begin
  57. Result := False;
  58. if Mas_Count <> 0 then
  59. begin
  60. Mas[Mas_First] := nil;
  61. Mas_First := Mas_First + 1;
  62. if Mas_First > Garaj_Slot then
  63. Mas_First := 1;
  64. Mas_Count := Mas_Count - 1;
  65. Result := True;
  66. end;
  67. end;
  68.  
  69. function TKompaniya.Get_Garaz_Zanat_Slot: integer;
  70. begin
  71. Result := Mas_Count;
  72. end;
  73.  
  74. function TKompaniya.Save(Save_File: string): boolean;
  75. var
  76. i: integer;
  77. txt: file of TGaraji;
  78. begin
  79. AssignFile(txt, Save_File);
  80. rewrite(txt);
  81.  
  82. Result := False;
  83.  
  84. if Mas_Count <> 0 then
  85. begin
  86. for i := Mas_First to Mas_Last do
  87. Write(txt, Mas[i]);
  88. Close(txt);
  89. Result := True;
  90. end;
  91. end;
  92.  
  93. function TKompaniya.Load(Load_File: string): boolean;
  94. var
  95. txt: file of TGaraji;
  96. begin
  97. Result := False;
  98. AssignFile(txt, Load_File);
  99. Reset(txt);
  100. Mas_Count := 0;
  101. while not EOF(txt) do
  102. begin
  103. Mas_Count := Mas_Count + 1;
  104. Read(txt, Mas[Mas_Count]);
  105. end;
  106. CloseFile(txt);
  107. Result := True;
  108. end;
  109. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement