Moin Thomas,
ich hab' da mal eben was zusammengeschrieben, wie ich mir das so ungefähr vorstelle. Ist natürlich nicht getestet, aber probiers mal aus, bzw. schau's Dir mal an.
Code:
[b]type[/b]
TcsFileLockEntry =
[b]packed[/b] [b]record[/b]
sFilePath : [b]string[/b];
fsFile : TFileStream;
[b]end[/b];
TcsFileLocker = [b]class[/b](TObject)
[b]private[/b]
FaFilelist : [b]array[/b] [b]of[/b] TcsFileLockEntry;
[b]public[/b]
[b]constructor[/b] Create;
[b]destructor[/b] Destroy; override;
[b]procedure[/b] LockFile([b]const[/b] p_sFilePath : [b]string[/b]);
[b]procedure[/b] UnlockFile([b]const[/b] p_sFilePath : [b]string[/b]);
[b]end[/b];
[b]implementation[/b]
[color=#000080]{$R *.DFM}[/color]
[color=#000080]{ TcsFileLocker }[/color]
[b]constructor[/b] TcsFileLocker.Create;
[b]begin[/b]
[b]inherited[/b] Create;
[color=#000080]// Nur der Ordung halber, eigentlich nicht notwendig[/color]
SetLength(FaFileList,0);
[b]end[/b];
[b]destructor[/b] TcsFileLocker.Destroy;
[b]var[/b]
i : integer;
[b]begin[/b]
[b]for[/b] i := 0 [b]to[/b] High(FaFileList) [b]do[/b]
[b]begin[/b]
FreeAndNil(FaFileList[i].fsFile);
[b]end[/b];
SetLength(FaFileList,0);
[b]inherited[/b] Destroy;
[b]end[/b];
[b]procedure[/b] TcsFileLocker.LockFile([b]const[/b] p_sFilePath: [b]string[/b]);
[b]begin[/b]
[color=#000080]// Neuen Eintrag erzeugen[/color]
SetLength(FaFileList,Length(FaFileList)+1);
FaFileList[High(FaFileList)].sFilePath := p_sFilePath;
FaFileList[High(FaFileList)].fsFile := TFileStream.Create(p_sFilePath,fmShareExclusive);
[b]end[/b];
[b]procedure[/b] TcsFileLocker.UnlockFile([b]const[/b] p_sFilePath: [b]string[/b]);
[b]var[/b]
i : integer;
iDeleted : integer;
[b]begin[/b]
iDeleted := -1;
[b]for[/b] i := 0 [b]to[/b] High(FaFileList) [b]do[/b]
[b]begin[/b]
[b]if[/b] FaFileList[i].sFilePath = p_sFilePath [b]then[/b]
[b]begin[/b]
FreeAndNil(FaFileList[i].fsFile);
iDeleted := i;
break;
[b]end[/b];
[b]end[/b];
[b]if[/b] iDeleted > -1 [b]then[/b]
[b]begin[/b]
[b]for[/b] i := iDeleted+1 [b]to[/b] High(FaFileList) [b]do[/b]
[b]begin[/b]
FaFileList[i-1] := FaFileList[i];
[b]end[/b];
SetLength(FaFileList,Length(FaFileList)-1);
[b]end[/b];
[b]end[/b];