123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- unit ProjectPropertyThread;
- interface
- uses
- Classes,
- ZjGrid,
- Windows,
- ProjectFileManager;
- type
- TProjPtyThread = class(TThread)
- private
- FProjKind : Integer;
- FGrid : TZJGrid;
- FProjectFileMgr : TProjectFileMgr;
- FReadProperty : Boolean;
- FThreadList : TThreadList;
- procedure WriteToGrid;
- procedure ReadFromGrid;
- procedure RemoveFormList;
- procedure AddToList;
- protected
- procedure Execute; override;
- public
- constructor Create(aProjKind : Integer;
- aGrid : TZJGrid;
- aProFileMgr : TProjectFileMgr;
- AReadProperty : Boolean;
- aThreadList : TThreadList);
-
- destructor Destroy; override;
- end;
- implementation
- uses ProjectPropertyUnit;
- { TProjPtyThread }
- var
- gl_CriticalSection_True: TRTLCriticalSection;
- gl_CriticalSection_False: TRTLCriticalSection;
- procedure TProjPtyThread.AddToList;
- var
- thrList: TList;
- begin
- thrList := FThreadList.LockList;
- try
- thrList.Add(Self);
- finally
- FThreadList.UnlockList;
- end;
- end;
- constructor TProjPtyThread.Create(aProjKind : Integer;
- aGrid : TZJGrid;
- aProFileMgr : TProjectFileMgr;
- AReadProperty : Boolean;
- aThreadList : TThreadList);
- begin
- FProjKind := aProjKind;
- FGrid := aGrid;
- FProjectFileMgr := aProFileMgr;
- FReadProperty := AReadProperty;
- FThreadList := aThreadList;
-
- AddToList;
- FreeOnTerminate := True;
- inherited Create(False);
- end;
- destructor TProjPtyThread.Destroy;
- begin
- RemoveFormList;
- inherited;
- end;
- procedure TProjPtyThread.Execute;
- procedure ExecuteReadProperty;
- begin
- EnterCriticalSection(gl_CriticalSection_True);
- try
- FProjectFileMgr.RefreshProjectProperty(FProjKind);
- Synchronize(WriteToGrid);
- finally
- LeaveCriticalSection(gl_CriticalSection_True);
- end;
- end;
- procedure ExecuteWriteProperty;
- begin
- EnterCriticalSection(gl_CriticalSection_False);
- try
- Synchronize(ReadFromGrid);
- FProjectFileMgr.WriteProjectProperty;
- finally
- LeaveCriticalSection(gl_CriticalSection_False);
- end;
- end;
- begin
- inherited;
-
- if FReadProperty then
- ExecuteReadProperty
- else
- ExecuteWriteProperty;
- end;
- procedure TProjPtyThread.ReadFromGrid;
- begin
- FProjectFileMgr.ProjectProperty.ProjectType := FGrid.Cells[1, 1].Text;
- FProjectFileMgr.ProjectProperty.BuildProjectName := FGrid.Cells[1, 2].Text;
- FProjectFileMgr.ProjectProperty.BudgetProjectName := FGrid.Cells[1, 3].Text;
- FProjectFileMgr.ProjectProperty.WeaveRange := FGrid.Cells[1, 4].Text;
- FProjectFileMgr.ProjectProperty.BuildUnit := FGrid.Cells[1, 5].Text;
- FProjectFileMgr.ProjectProperty.ProjectSite := FGrid.Cells[1, 6].Text;
- FProjectFileMgr.ProjectProperty.WeaveDate := FGrid.Cells[1, 7].Text;
- FProjectFileMgr.ProjectProperty.WeavePerson := FGrid.Cells[1, 8].Text;
- FProjectFileMgr.ProjectProperty.WeaveCode := FGrid.Cells[1, 9].Text;
- FProjectFileMgr.ProjectProperty.CheckPerson := FGrid.Cells[1, 10].Text;
- FProjectFileMgr.ProjectProperty.CheckCode := FGrid.Cells[1, 11].Text;
- FProjectFileMgr.ProjectProperty.TenderPerson := FGrid.Cells[1, 12].Text;
- FProjectFileMgr.ProjectProperty.DataFileCode := FGrid.Cells[1, 13].Text;
- FProjectFileMgr.ProjectProperty.RoadLevel := FGrid.Cells[1, 14].Text;
- FProjectFileMgr.ProjectProperty.FirstPeg := FGrid.Cells[1, 15].Text;
- FProjectFileMgr.ProjectProperty.LastPeg := FGrid.Cells[1, 16].Text;
- FProjectFileMgr.ProjectProperty.RouteLength := FGrid.Cells[1, 17].Text;
- FProjectFileMgr.ProjectProperty.RouteWidth := FGrid.Cells[1, 18].Text;
- end;
- procedure TProjPtyThread.RemoveFormList;
- var
- thrList: TList;
- begin
- thrList := FThreadList.LockList;
- try
- thrList.Remove(Self);
- finally
- FThreadList.UnlockList;
- end;
- end;
- procedure TProjPtyThread.WriteToGrid;
- begin
- FGrid.BeginUpdate;
- FGrid.Cells[1, 1].Text := FProjectFileMgr.ProjectProperty.ProjectType;
- FGrid.Cells[1, 2].Text := FProjectFileMgr.ProjectProperty.BuildProjectName;
- FGrid.Cells[1, 3].Text := FProjectFileMgr.ProjectProperty.BudgetProjectName;
- FGrid.Cells[1, 4].Text := FProjectFileMgr.ProjectProperty.WeaveRange;
- FGrid.Cells[1, 5].Text := FProjectFileMgr.ProjectProperty.BuildUnit;
- FGrid.Cells[1, 6].Text := FProjectFileMgr.ProjectProperty.ProjectSite;
- FGrid.Cells[1, 7].Text := FProjectFileMgr.ProjectProperty.WeaveDate;
- FGrid.Cells[1, 8].Text := FProjectFileMgr.ProjectProperty.WeavePerson;
- FGrid.Cells[1, 9].Text := FProjectFileMgr.ProjectProperty.WeaveCode;
- FGrid.Cells[1, 10].Text := FProjectFileMgr.ProjectProperty.CheckPerson;
- FGrid.Cells[1, 11].Text := FProjectFileMgr.ProjectProperty.CheckCode;
- FGrid.Cells[1, 12].Text := FProjectFileMgr.ProjectProperty.TenderPerson;
- FGrid.Cells[1, 13].Text := FProjectFileMgr.ProjectProperty.DataFileCode;
- FGrid.Cells[1, 14].Text := FProjectFileMgr.ProjectProperty.RoadLevel;
- FGrid.Cells[1, 15].Text := FProjectFileMgr.ProjectProperty.FirstPeg;
- FGrid.Cells[1, 16].Text := FProjectFileMgr.ProjectProperty.LastPeg;
- FGrid.Cells[1, 17].Text := FProjectFileMgr.ProjectProperty.RouteLength;
- FGrid.Cells[1, 18].Text := FProjectFileMgr.ProjectProperty.RouteWidth;
- FGrid.EndUpdate;
- end;
- initialization
- InitializeCriticalSection(gl_CriticalSection_True);
- InitializeCriticalSection(gl_CriticalSection_False);
- finalization
- DeleteCriticalSection(gl_CriticalSection_True);
- DeleteCriticalSection(gl_CriticalSection_False);
- end.
|