ProjectPropertyThread.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. unit ProjectPropertyThread;
  2. interface
  3. uses
  4. Classes,
  5. ZjGrid,
  6. Windows,
  7. ProjectFileManager;
  8. type
  9. TProjPtyThread = class(TThread)
  10. private
  11. FProjKind : Integer;
  12. FGrid : TZJGrid;
  13. FProjectFileMgr : TProjectFileMgr;
  14. FReadProperty : Boolean;
  15. FThreadList : TThreadList;
  16. procedure WriteToGrid;
  17. procedure ReadFromGrid;
  18. procedure RemoveFormList;
  19. procedure AddToList;
  20. protected
  21. procedure Execute; override;
  22. public
  23. constructor Create(aProjKind : Integer;
  24. aGrid : TZJGrid;
  25. aProFileMgr : TProjectFileMgr;
  26. AReadProperty : Boolean;
  27. aThreadList : TThreadList);
  28. destructor Destroy; override;
  29. end;
  30. implementation
  31. uses ProjectPropertyUnit;
  32. { TProjPtyThread }
  33. var
  34. gl_CriticalSection_True: TRTLCriticalSection;
  35. gl_CriticalSection_False: TRTLCriticalSection;
  36. procedure TProjPtyThread.AddToList;
  37. var
  38. thrList: TList;
  39. begin
  40. thrList := FThreadList.LockList;
  41. try
  42. thrList.Add(Self);
  43. finally
  44. FThreadList.UnlockList;
  45. end;
  46. end;
  47. constructor TProjPtyThread.Create(aProjKind : Integer;
  48. aGrid : TZJGrid;
  49. aProFileMgr : TProjectFileMgr;
  50. AReadProperty : Boolean;
  51. aThreadList : TThreadList);
  52. begin
  53. FProjKind := aProjKind;
  54. FGrid := aGrid;
  55. FProjectFileMgr := aProFileMgr;
  56. FReadProperty := AReadProperty;
  57. FThreadList := aThreadList;
  58. AddToList;
  59. FreeOnTerminate := True;
  60. inherited Create(False);
  61. end;
  62. destructor TProjPtyThread.Destroy;
  63. begin
  64. RemoveFormList;
  65. inherited;
  66. end;
  67. procedure TProjPtyThread.Execute;
  68. procedure ExecuteReadProperty;
  69. begin
  70. EnterCriticalSection(gl_CriticalSection_True);
  71. try
  72. FProjectFileMgr.RefreshProjectProperty(FProjKind);
  73. Synchronize(WriteToGrid);
  74. finally
  75. LeaveCriticalSection(gl_CriticalSection_True);
  76. end;
  77. end;
  78. procedure ExecuteWriteProperty;
  79. begin
  80. EnterCriticalSection(gl_CriticalSection_False);
  81. try
  82. Synchronize(ReadFromGrid);
  83. FProjectFileMgr.WriteProjectProperty;
  84. finally
  85. LeaveCriticalSection(gl_CriticalSection_False);
  86. end;
  87. end;
  88. begin
  89. inherited;
  90. if FReadProperty then
  91. ExecuteReadProperty
  92. else
  93. ExecuteWriteProperty;
  94. end;
  95. procedure TProjPtyThread.ReadFromGrid;
  96. begin
  97. FProjectFileMgr.ProjectProperty.ProjectType := FGrid.Cells[1, 1].Text;
  98. FProjectFileMgr.ProjectProperty.BuildProjectName := FGrid.Cells[1, 2].Text;
  99. FProjectFileMgr.ProjectProperty.BudgetProjectName := FGrid.Cells[1, 3].Text;
  100. FProjectFileMgr.ProjectProperty.WeaveRange := FGrid.Cells[1, 4].Text;
  101. FProjectFileMgr.ProjectProperty.BuildUnit := FGrid.Cells[1, 5].Text;
  102. FProjectFileMgr.ProjectProperty.ProjectSite := FGrid.Cells[1, 6].Text;
  103. FProjectFileMgr.ProjectProperty.WeaveDate := FGrid.Cells[1, 7].Text;
  104. FProjectFileMgr.ProjectProperty.WeavePerson := FGrid.Cells[1, 8].Text;
  105. FProjectFileMgr.ProjectProperty.WeaveCode := FGrid.Cells[1, 9].Text;
  106. FProjectFileMgr.ProjectProperty.CheckPerson := FGrid.Cells[1, 10].Text;
  107. FProjectFileMgr.ProjectProperty.CheckCode := FGrid.Cells[1, 11].Text;
  108. FProjectFileMgr.ProjectProperty.TenderPerson := FGrid.Cells[1, 12].Text;
  109. FProjectFileMgr.ProjectProperty.DataFileCode := FGrid.Cells[1, 13].Text;
  110. FProjectFileMgr.ProjectProperty.RoadLevel := FGrid.Cells[1, 14].Text;
  111. FProjectFileMgr.ProjectProperty.FirstPeg := FGrid.Cells[1, 15].Text;
  112. FProjectFileMgr.ProjectProperty.LastPeg := FGrid.Cells[1, 16].Text;
  113. FProjectFileMgr.ProjectProperty.RouteLength := FGrid.Cells[1, 17].Text;
  114. FProjectFileMgr.ProjectProperty.RouteWidth := FGrid.Cells[1, 18].Text;
  115. end;
  116. procedure TProjPtyThread.RemoveFormList;
  117. var
  118. thrList: TList;
  119. begin
  120. thrList := FThreadList.LockList;
  121. try
  122. thrList.Remove(Self);
  123. finally
  124. FThreadList.UnlockList;
  125. end;
  126. end;
  127. procedure TProjPtyThread.WriteToGrid;
  128. begin
  129. FGrid.BeginUpdate;
  130. FGrid.Cells[1, 1].Text := FProjectFileMgr.ProjectProperty.ProjectType;
  131. FGrid.Cells[1, 2].Text := FProjectFileMgr.ProjectProperty.BuildProjectName;
  132. FGrid.Cells[1, 3].Text := FProjectFileMgr.ProjectProperty.BudgetProjectName;
  133. FGrid.Cells[1, 4].Text := FProjectFileMgr.ProjectProperty.WeaveRange;
  134. FGrid.Cells[1, 5].Text := FProjectFileMgr.ProjectProperty.BuildUnit;
  135. FGrid.Cells[1, 6].Text := FProjectFileMgr.ProjectProperty.ProjectSite;
  136. FGrid.Cells[1, 7].Text := FProjectFileMgr.ProjectProperty.WeaveDate;
  137. FGrid.Cells[1, 8].Text := FProjectFileMgr.ProjectProperty.WeavePerson;
  138. FGrid.Cells[1, 9].Text := FProjectFileMgr.ProjectProperty.WeaveCode;
  139. FGrid.Cells[1, 10].Text := FProjectFileMgr.ProjectProperty.CheckPerson;
  140. FGrid.Cells[1, 11].Text := FProjectFileMgr.ProjectProperty.CheckCode;
  141. FGrid.Cells[1, 12].Text := FProjectFileMgr.ProjectProperty.TenderPerson;
  142. FGrid.Cells[1, 13].Text := FProjectFileMgr.ProjectProperty.DataFileCode;
  143. FGrid.Cells[1, 14].Text := FProjectFileMgr.ProjectProperty.RoadLevel;
  144. FGrid.Cells[1, 15].Text := FProjectFileMgr.ProjectProperty.FirstPeg;
  145. FGrid.Cells[1, 16].Text := FProjectFileMgr.ProjectProperty.LastPeg;
  146. FGrid.Cells[1, 17].Text := FProjectFileMgr.ProjectProperty.RouteLength;
  147. FGrid.Cells[1, 18].Text := FProjectFileMgr.ProjectProperty.RouteWidth;
  148. FGrid.EndUpdate;
  149. end;
  150. initialization
  151. InitializeCriticalSection(gl_CriticalSection_True);
  152. InitializeCriticalSection(gl_CriticalSection_False);
  153. finalization
  154. DeleteCriticalSection(gl_CriticalSection_True);
  155. DeleteCriticalSection(gl_CriticalSection_False);
  156. end.