Regards,
Ron
--
Bill Todd (TeamB)
"Bill Todd" <n...@no.com> wrote in message
news:42e24639$1...@newsgroups.borland.com...
--
Bill Todd (TeamB)
"Bill Todd" <n...@no.com> wrote in message
news:42e289c7$1...@newsgroups.borland.com...
--
Bill Todd (TeamB)
I don't think I need the workaround if I understand this correctly. I am
trying to use CDS as a standalone file-based db.
If I have filename set and ChangesMade = True then it will auto-save when
closing. However, for ChangesMade to equal true, ChangeCount > 0? And for
the changes to be in the data baseline I need to MergeChangeLog, right? So
if I don't MergeChangeLog, even though ChangeCount is >0, the changes won't
be in the saved data?
I would like to give my users a choice when closing the dataset (either
through closing application or switching to another file) as to whether they
want to save their changes or not. So (assuming filename already set) :
procedure MyForm.CloseCurrentDataset;
BEGIN
if cds.ChangeCount > then
Case YesNoMessageBoxResult of
mrOK: begin
cds.mergechangelog;
{I need to force SavetoFile because mergechangelog
resets ChangesMade?}
cds.SaveToFile(cds.filename, dfXML);
end;
mrNo: Begin
cds.close;
{This is okay because without mergechangelog,
changes won't be saved to an existing file?}
End;
end;
END;
Follow-up question, If I re-open the file and close right away, I am getting
a file prompt (as if ChangeCount > 0)? Is the log maintained outside the
cds component?
"Kostas Terzides" <kt...@otenet.gr> wrote in message
news:42e2...@newsgroups.borland.com...
"Bill Todd" <n...@no.com> wrote in message
news:42e3afa9$1...@newsgroups.borland.com...
Yes, I understand that, but let me try to explain:
-Cds.SaveToFile saves in a cds (or XML) file all the cds metadata (field
definitions e.t.c.), baseline data *and* the change log. That's the
reason you may notice a gradual increase in cds file size even though
you may only have a steady number of records. Cds.MergeChangeLog will
revert file size back to normal. The reason that change log might be
useful (in a file based app) after loading from a file is that you might
want to preserve UndoLastChange, SavePoint e.t.c.
-The check in Dave's work around (that has officialy been applied as a
fix in next versions of Delphi) is:
.....
if (FileName <> '') and not (csDesigning in ComponentState) and
(ChangesMade or not(FileExists(FileName))) then
SaveToFile(FileName);
......
That means that ChangesMade will be taken account of only in case the
cds file does not already exist (this is the first time that it is get
saved).
-ChangesMade will remain true after calling cds.MergeChangeLog.
ChangesMade is not equivalent to ChangeCount>0
-QC 2307 is only related to behaviour related to Cds.FileName property.
Cds.SaveToFile is working as expected.
>
> I don't think I need the workaround if I understand this correctly. I am
> trying to use CDS as a standalone file-based db.
And that's what I had in mind.
>
> If I have filename set and ChangesMade = True then it will auto-save when
> closing. However, for ChangesMade to equal true, ChangeCount > 0? And for
> the changes to be in the data baseline I need to MergeChangeLog, right? So
> if I don't MergeChangeLog, even though ChangeCount is >0, the changes won't
> be in the saved data?
That is not correct. Read above.
>
> I would like to give my users a choice when closing the dataset (either
> through closing application or switching to another file) as to whether they
> want to save their changes or not. So (assuming filename already set) :
>
> procedure MyForm.CloseCurrentDataset;
> BEGIN
> if cds.ChangeCount > then
> Case YesNoMessageBoxResult of
> mrOK: begin
> cds.mergechangelog;
> {I need to force SavetoFile because mergechangelog
> resets ChangesMade?}
> cds.SaveToFile(cds.filename, dfXML);
> end;
> mrNo: Begin
> cds.close;
> {This is okay because without mergechangelog,
> changes won't be saved to an existing file?}
> End;
> end;
> END;
I would simply do that as follows (if cds.FileName is set):
procedure MyForm.CloseCurrentDataset;
BEGIN
if cds.ChangeCount > then
Case YesNoMessageBoxResult of
mrOK: begin
cds.mergechangelog;
{You don't need to force SavetoFile if
cds.FileName is set}
end;
mrNo: Begin
cds.CancelUpdates;
End;
end;
Cds.Close;// That will actually save to the file
END;
>
> Follow-up question, If I re-open the file and close right away, I am getting
> a file prompt (as if ChangeCount > 0)?
Yes, because the file contains the change log. What do you mean file promt?
Is the log maintained outside the
> cds component?
>
No, read above.
function TfrmMain.OkayToClose : Boolean ;
begin
Result := True;
if cdsClient.ChangeCount > 0 then
Begin
Case MessageDlg('Do you want to save your
changes?',mtConfirmation,mbYesNoCancel,0) of
mrOk : cdsclient.MergeChangeLog;
mrNo: cdsclient.CancelUpdates;
mrCancel : Result := False;
end; {endcase}
End;
end;
So if the user says ok, the changelog is merged and then the CDS closed (so
it saves). Now if I open the CDS with either a new filename or re-open the
same file and close it right away, the user is being prompted with the
Messagebox again. So ChangeCount not reset when the cds closed?
"Kostas Terzides" <kt...@otenet.gr> wrote in message
news:42e3...@newsgroups.borland.com...
In the particular case of just:
cds.Open->MergeChangeLog->cds.Close
it is true that ChangesMade will remain false and the routine will not
call SaveToFile. If you consider this a bug, then you could post a new
QC entry (I think it is a bug, a minor one though).
What Bill said at first place is the best approach after all I think,
just use SaveToFile explicitly. May be add this cds.BeforeClose event
handler (as I usually do):
cds.SaveToFile(cds.FileName);
, or even better subclass TClientDataset and override DoBeforeClose to
achieve the same functionality.
After Mergechangelog, changecount is still >0 when I test my function, even
after cds.close. When does changecount reset to zero?
"Kostas Terzides" <kt...@otenet.gr> wrote in message
news:42e5...@newsgroups.borland.com...
ChangeCount should be 0 after MergeChangeLog and CancelUpdates. What I
suspect is (from your description):
Cds.Open->Make some changes-> Cds.Close (this saves the change log to
the file)->cds.Open (ChangeCount>0 at this point)-> Cds.MergeChangeLog
(ChangeCount=0 at this point)->Cds.Close (at *this* point there is *no*
saving)->Cds.Open (it reopens the previous file that had the change log
included)->cds.ChangeCount>0
That is the only possible explanation I can give. If you check
Cds.ChangeCount (during a debugging session) immediately after
cds.MergeChangeLog and *before* closing the cds, then ChangeCount should
be 0, or else we are having another bug here that I am not aware of
Thanks SO much for your patience and help!
Regards,
Ron
--
Bill Todd (TeamB)