Hey WP,
First and foremost, thank you so very much for taking the time to suss things out!!
Really appreciate it.
As a preamble: I was just playing around with things under the impression that
TBufDataset was gonna be the same beast as
TMemDataset, but with internal changes only, not the polar opposite of it.
In this context, I tried to transfer what I learned with
TMemDataset, which was easy, simple and worked right out of the box, to
TBufDataset and the thing was like nitroglycerine without the stabilising compound that turns it into dynamite. It went boom at the slightest touch.
Is there a reason why you did not set the BufDataset's Filename?
More than one:
- The wiki article for TMemDataset did not mention the need for it, but I do realise that the section dedicated to TBufDataset was just focusing on sorting, and nothing more.
- Again, TMemDataset worked ok without it.
- My main purpose for this whole endeavour of testing TMemDataset, TBufDataset, TRxMemoryData and ZMSQL is to not rely on, what I'm assuming should only be memory only and volatile by nature, a file or database engine, but to have the Dataset holding the data, a visual component that has way better features than a TStringGrid and some small piece of code to make filter and sorting happen.
I want the persistence of the data to be some custom, black box, thing that I can create, re-create and have my mind changed on how to read/write it every time I need to display the data.
So, in this context, having a file on the
TBufDataset, made no sense and because
TMemDataset did not have an issue with it's absence, I guess I made a bad assumption.
I am not sure if it is possible at all to use TBufdataset without a file, buf even if it is you will lose all records when the application terminates.
That does not have any impact, the data will come and be persisted by other means.
Second issue: persistent fields. Once you have persistent fields you cannot access fields by FieldByName[fieldname], but only by their variable name, e.g. bdsAccountsBalance rather than bdsAccounts.FieldByName['Balance']. An annoyance which I already hated in my Delphi times...
Okies, that's going on the notepad for future reference, many, many thanks!!
I deleted the persistent fields from the lfm file, added a Filename to the bdsAccounts dataset and made sure that the dataset is created properly - now the application does not crash any more:
procedure TfrmMain.FormCreate(Sender: TObject);
begin
Caption:= Format('%s v%s', [ Application.Title, cVersion ]);
InitShortcuts;
Application.OnHint:= @DisplayHint;
bdsAccounts.FileName := 'test.db';
if not FileExists(bdsAccounts.FileName) then
bdsAccounts.CreateDataset;
bdsAccounts.Open;
end;
These things should either be better documented, or raise an exception if it impacts the more simplistic operation I'm aiming, wouldn't you agree?
Still... Clear does not seam to work. It clears the dataset in the current session, but when the app starts another time the data are back again.
This
Clear was a naive attempt to mimic
TMemDataset.
Even the Lazarus wiki mentions that a clear is too slow and it provides a quicker solution, a bit hefty on the code, hence me being a bit lazy and tried it the easy and less optimal way.
And the loss of data between sessions is of no consequence.
Filtering seems to crash the application still. Well - I would not execute the filter in the OnChange event of the edit control, I would add a button to toggle bdsAccounts.Filtered and use the edit filter text once it is completed. This works, but I don't understand why your code report "Index based on unknown field" while typing the condition...
The filtering has a blatant error due to my ignorance of the syntax needed.
After I posted this, I progressed in doing my tests with
TRxMemoryData, and after some head butting with the wall I realized that I need:
DataSet.Filter:= 'Alias="*<value or partial>*"';
And with this, it now works.
I've always struggled with the many syntaxes(SQL with the Like and the % and never knowing if I should quote the value or not) for this filtering since there is not a place where this is discussed in any docs or examples that I've stumbled upon!
There is a blatant lack of documentation on the correct syntax parsed in this
Filter property, that's for sure!!
Ok, summarising your findings:
- Have a filename on the respective property
- Do not use the FieldByName way
- Maybe not use the Fields, just the FieldDefs. (Is this what you mean by persistent fields?)
Am I missing something?
Nonetheless, oh so many thanks for the time you've spent on this !!!
Cheers,
Gus