Recent

Author Topic: deleting all the FieldDefs from a bufdataset  (Read 15805 times)

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
deleting all the FieldDefs from a bufdataset
« on: July 05, 2011, 07:26:07 pm »
ABufDataset.FieldDefs.Clear;
ABufDataset.Fields.Clear;
ABufDataset.ClearFields;

What are differences?

What is the exact way to clear previously defined Fielddefs of a bufdataset, so that you can define and add new fielddefs from scratch?

Lacak2

  • Guest
Re: deleting all the FieldDefs from a bufdataset
« Reply #1 on: July 06, 2011, 10:48:54 am »
ABufDataset.ClearFields:
from Delphi help: "Clears the contents of all fields for the active record." ... so this is not your case

ABufDataset.FieldDefs:
from Delphi help: "Points to the list of field definitions for the dataset. ... While an application can examine FieldDefs to explore the field definitions for a dataset, it should not change these definitions unless creating a new table with CreateTable or CreateDataSet."

ABufDataset.Fields:
from Delphi help: "Use Fields to access field components. If fields are generated dynamically at runtime, the order of field components in Fields corresponds directly to the order of columns in the table or tables underlying a dataset. If a dataset uses persistent fields, then the order of field components corresponds to the ordering of fields specified in the Fields editor at design time."

So answer to your question depends on what exactly do you want to do ?

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: deleting all the FieldDefs from a bufdataset
« Reply #2 on: July 06, 2011, 09:49:27 pm »
OK, my problem is the following: I have made a TBufDataset descendent called TZMQueryDataset that should be able to execute SQL queries and load the resultset to it.

When I call this from outside:

ZMQueryDataset1.Close;
ZMQueryDataset1.Fields.Clear;
ZMQueryDataset1.FieldDefs.Clear;

fielddefs are removed and then I am able to create new FieldDefs and with CreateDataset to create new empty dataset and afterwards to fill it with data. Everything OK.

However,
When I do the same from inside the class, the previous fielddefs remain intact and I can't create new fielddefs....I am not able to remove fielddefs from within the object!

So, this method does not work:

procedure TZMQueryDataSet.ClearDataSet;
begin
  with self do begin
    Close;
    Fields.Clear;
    FieldDefs.Clear;
  end;
end;   

FieldDefs (or Fields?) is not removed...

Any idea?

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: deleting all the FieldDefs from a bufdataset
« Reply #3 on: July 06, 2011, 11:00:10 pm »
This confused me for a while too (which to use FieldDefs or Fields) - not sure why it was developed this way but I get the impression FieldDefs is a simple TCollection generated from the Fields - so in theory removing the Fields should remove the FieldDefs too although I don't think that's always the case.

If you create a list of Fields dynamically at designtime and there are no FieldDefs set "(0 items)" the individual FieldDefs seem to appear when you attach a control (saya DBGrid) to the component via a datasource and set one of the columns to the fields in the table.

It may make sense to change the order in whch you are clearing them i.e. clear the FieldDefs and then the Fields rather than the other way around.

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: deleting all the FieldDefs from a bufdataset
« Reply #4 on: July 06, 2011, 11:34:15 pm »
No, it didn't help...

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: deleting all the FieldDefs from a bufdataset
« Reply #5 on: July 07, 2011, 12:45:28 am »
yep you're rght - the other memory databases I've been playing with are descended from the old RX memory table but TBufDataset is different.

I've been working on porting the JVCL TJvMemoryData component from the final version of the v2 series release (2.10) of the JVCL which was targeted at Delphi7 and below - as it seemed a better candidate for porting than the current version 3.40.  I managed to get the old RX version running but there were reportedly issues with it (not sure what) so I've semi-abandonded that one on the basis that the JVCL one had fixed most of those bugs - sorting didn't work correctly I don't think & calculated fields didn't work at all - not sure what else didn't work.

I've got the JVCL one working but haven't had much chance to test it yet.  I've added filtering and a streamed persistence mechanism (calculated fields work but not with persistence) so it's got the bits that I think are missing from the TMemDataset memory table which I needed and couldn't get to work properly at all (memo/blob support).  I also managed to compile the extra expression parser bit from version 3 of the JVCL but it threw out too many errors when running and I've not had time to look at whether these were simple or complex to fix. 

I also worked out persistence using XML (structure and data) but not sure how useful this is - I added it to try and find an easy way to change a persisted dataset structure that's been saved to a file (a streamed version has to be copied to a new structure and then saved again which worked but occasionally threw a fit on me wheras the XML file version can just be edited manually and reloaded).  It works (certain fields aren't good for this - autoinc, calculated fields and not sure about lookup-fields - yet to test that bit) but have pulled it for the time being - might just make this an external function facility yet. I saw it that you might use it this way while developing but then finally port it to a streamed version (re-loading is much quicker) when the structure/data has been finalized. If people think this is a useful addition I might re-add it.

I was thinking about what other JVCL components could be ported (from the old 2.10 release anyway as it'll almost certainly be simpler than the latest version) - probably most of these don't make a lot of sense as they're either Windows only specific (or things like BDE) or equivalents have already been created.   

If anyone has any existing issues with these "in memory" datasets I'd be interested in seeing if this version can fix these - just let me know what they are (ideally with some sample code to illustrate the problem) - I'll be testing the JVCL one on Linux/OSX tomorrow (hopefully) and then I'll upload it somewhere so people can try it instead (assuming my testing goes ok)  :D
« Last Edit: July 07, 2011, 12:50:52 am by TheBlackSheep »

plamen_f

  • New member
  • *
  • Posts: 8
Re: deleting all the FieldDefs from a bufdataset
« Reply #6 on: July 07, 2011, 09:54:32 am »
Please leave here the way we can test it (download it).

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: deleting all the FieldDefs from a bufdataset
« Reply #7 on: July 08, 2011, 09:12:39 pm »
Here you can download zmsql package (early stage):
http://www.4shared.com/file/Xi-koKq5/TZMSQLtar.html

and a test project:
http://www.4shared.com/file/kj6mvhbR/TestProjecttar.html

If someone can take a look and debug, I would appreciate...
The test project shows that from outside call can kill fielddefs, while inner call not. I can't figure out why...
« Last Edit: July 08, 2011, 09:49:07 pm by tatamata »

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: deleting all the FieldDefs from a bufdataset
« Reply #8 on: July 10, 2011, 10:35:40 am »
Meanwhile, I'm trying with Memdataset insetad of Bufdataset, the sam happens...
There is also FiedlDefs.Upadate method. What is it used for?

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: deleting all the FieldDefs from a bufdataset
« Reply #9 on: July 10, 2011, 11:03:31 am »
If I want to remove existing fields (fielddefs) and replace it with new fielddefs, what exactly order of callings to FiedDefs.Clear; FieldDefs.Update; Dataset.CreateTable/CreateDataset; ?

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: deleting all the FieldDefs from a bufdataset
« Reply #10 on: July 13, 2011, 06:49:45 am »
OK., after few days of strugle, I figured out that nothings was wrong in my code - it should always be FieldDefs.Clear, but DBGrid does not refresh when the underlying fielddefs are changed.
Thus I must use Datasource.Enabled:=False before loading new dataset definition and Datasource.Enabled:=True afterwards...

 

TinyPortal © 2005-2018