I am writing a streem to a file with a index as to keep track of where wich streem has been saved but any way
when I load a streem from a file like this
Function TSFICont.Add(ItemID: Word; aFileName: String): word;
Var tF: TFileStream;
Begin
tF := TFileStream.Create(aFileName, fmOpenRead);
Try
If FCount<MAX_FILES Then
Begin
IncrementCount;
SetLength(FItems, FCount);
FItems[FCount-1].Size := tF.Size;
FItems[FCount-1].Position := FFileStream.Size;
With FFileStream Do
Begin
If FCount=1 Then
//First time a file is created ignore the 1st 4 bytes
Seek(SizeOf(FCount), soFromBeginning)
Else
Seek(SizeOf(FCount)+(SizeOf(FItems[0])*(FCount-1)), soFromBeginning);
Write(FItems[FCount-1], SizeOf(FItems[0]));
Seek(0, soFromEnd);
CopyFrom(tF, tF.Size);
End;
SQL_ResetAndExec(adoQ, 'Insert INTO IDEX (ItemID) VALUES ( '+IntToStr(ItemID)+')');
End
Else
Raise Exception.Create('Sorry cannot insert more files!');
Finally
tF.Free;
End;
Result := FCount;
End;
I have no problems at all but then I needed to add directly from a class Tsreem type
so I made this
Function TSFICont.AddFromMemStreem(ItemID: Word; aMS: TMemoryStream): word;
Begin
If FCount<MAX_FILES Then
Begin
IncrementCount;
SetLength(FItems, FCount);
FItems[FCount-1].Size := aMS.Size;
FItems[FCount-1].Position := FFileStream.Size;
With FFileStream Do
Begin
If FCount=1 Then
//First time a file is created ignore the 1st 4 bytes
Seek(SizeOf(FCount), soFromBeginning)
Else
Seek(SizeOf(FCount)+(SizeOf(FItems[0])*(FCount-1)), soFromBeginning);
Write(FItems[FCount-1], SizeOf(FItems[0]));
Seek(0, soFromEnd);
CopyFrom(aMS, aMS.Size);
End;
SQL_ResetAndExec(adoQ, 'Insert INTO IDEX (ItemID) VALUES ( '+IntToStr(ItemID)+')');
End
Else
Raise Exception.Create('Sorry cannot insert more files!');
Result := FCount;
End;
which does the job just fine as long as you are loading a prev add item from the file into the aMS var
and then I had the problem for some reson which I haven't worked out yet there is a diffrence between a
sreem loaded from a file and one created in memory but I am not to sure about how to go about solving it
any suggestions .. thanks for the help
when I load a streem from a file like this
Function TSFICont.Add(ItemID: Word; aFileName: String): word;
Var tF: TFileStream;
Begin
tF := TFileStream.Create(aFileName, fmOpenRead);
Try
If FCount<MAX_FILES Then
Begin
IncrementCount;
SetLength(FItems, FCount);
FItems[FCount-1].Size := tF.Size;
FItems[FCount-1].Position := FFileStream.Size;
With FFileStream Do
Begin
If FCount=1 Then
//First time a file is created ignore the 1st 4 bytes
Seek(SizeOf(FCount), soFromBeginning)
Else
Seek(SizeOf(FCount)+(SizeOf(FItems[0])*(FCount-1)), soFromBeginning);
Write(FItems[FCount-1], SizeOf(FItems[0]));
Seek(0, soFromEnd);
CopyFrom(tF, tF.Size);
End;
SQL_ResetAndExec(adoQ, 'Insert INTO IDEX (ItemID) VALUES ( '+IntToStr(ItemID)+')');
End
Else
Raise Exception.Create('Sorry cannot insert more files!');
Finally
tF.Free;
End;
Result := FCount;
End;
I have no problems at all but then I needed to add directly from a class Tsreem type
so I made this
Function TSFICont.AddFromMemStreem(ItemID: Word; aMS: TMemoryStream): word;
Begin
If FCount<MAX_FILES Then
Begin
IncrementCount;
SetLength(FItems, FCount);
FItems[FCount-1].Size := aMS.Size;
FItems[FCount-1].Position := FFileStream.Size;
With FFileStream Do
Begin
If FCount=1 Then
//First time a file is created ignore the 1st 4 bytes
Seek(SizeOf(FCount), soFromBeginning)
Else
Seek(SizeOf(FCount)+(SizeOf(FItems[0])*(FCount-1)), soFromBeginning);
Write(FItems[FCount-1], SizeOf(FItems[0]));
Seek(0, soFromEnd);
CopyFrom(aMS, aMS.Size);
End;
SQL_ResetAndExec(adoQ, 'Insert INTO IDEX (ItemID) VALUES ( '+IntToStr(ItemID)+')');
End
Else
Raise Exception.Create('Sorry cannot insert more files!');
Result := FCount;
End;
which does the job just fine as long as you are loading a prev add item from the file into the aMS var
and then I had the problem for some reson which I haven't worked out yet there is a diffrence between a
sreem loaded from a file and one created in memory but I am not to sure about how to go about solving it
any suggestions .. thanks for the help