Saving a lookup definition and data for a ClientDataset

My ClientDataset has a lookup field.  It's a simple lookup - about 20 two-letter codes which reference long, user-friendly descriptive strings when displayed to the user.  The lookup is more-or-less static - only changing when the user needs a new description.

I want to save the lookup linkage and the lookup table inside the main dataset a) so as to avoid the need to have a secondary lookup dataset and b) more importantly, so that the dataset can be self-contained and its lookup structure and data known to any other application that wants to access it.

I know that TClientDatasets can contain secondary data, but that seems to be on a record-by-record basis and I want to save just one copy of the lookup table.

I can't seem to be able to specify the field as a lookup field in FieldDefs and even if I could, the FieldDefs don't seem to be saved in the XML file.

As a kludge, I can't even save free-form information in the Params.

Furthermore, the source code of the ClientDataset loading and saving routines seem to end in external calls, so I can't extend these methods.

Can any database expert please suggest any solutions ?
0
Ian
8/24/2008 9:41:06 AM
embarcadero.delphi.database 1294 articles. 0 followers. Follow

14 Replies
1053 Views

Similar Articles

[PageSpeed] 36
Get it on Google Play
Get it on Apple App Store

You cannot save two tables in a single file using
TClientDataSet.SaveToFile. I assume that the lookup field
refers to another CDS that contains the lookup data. If so
you must save that CDS to another file.

-- 
Bill Todd (TeamB)
0
Bill
8/24/2008 2:37:53 PM
Bill, 

> You cannot save two tables in a single file using TClientDataSet.SaveToFile.

I could if the source code were released so that I could find out how to inherit from that method.

> I assume that the lookup field refers to another CDS that contains the lookup data. If so you must save that CDS to another file.

OK, but is there any way to have the main CDS file contain some information that specifies one field as a lookup field and the identitifies the secondary file ?  For example, can I get some freeform data into its Params ?

Ian
0
Ian
8/25/2008 7:31:02 AM
Ian Trackman wrote:

> OK, but is there any way to have the main CDS file
> contain some information that specifies one field as a
> lookup field and the identitifies the secondary file ?
> For example, can I get some freeform data into its Params
> ?

No.

-- 
Bill Todd (TeamB)
0
Bill
8/25/2008 2:00:29 PM
Bill,

> No.

Then surely isn't this a worthwhile extension to the language ?  

Either release the code to TClientDataset.Load and Save - or add a property to a field which indicates that it is lookup field and a property to the target field which is a key+value stringlist and an event for a missing key.

Is there a good reason why the source of Load and Save aren't available ?

Ian
0
Ian
8/26/2008 6:09:18 AM
> {quote:title=Ian Trackman wrote:}{quote}
> Bill,
> 
> > No.
> 
> Then surely isn't this a worthwhile extension to the language ?  
> 
> Either release the code to TClientDataset.Load and Save - or add a property to a field which indicates that it is lookup field and a property to the target field which is a key+value stringlist and an event for a missing key.
> 

Or write your own.

CodeGear probably doesn't see a need to use it's resources to develop something that, AFAICT, only a single individual would benefit from. Apparently, you don't see that need either, as you haven't written your own version and want CG's work to modify instead.

> Is there a good reason why the source of Load and Save aren't available ?

Because that code belongs to CodeGear, and they don't want to release it?

Can you make all source code available for your commercial product (whatever it might be) so that I can modify it as I see fit? Thanks. 

Better yet, post your code. I'll review it for features/enhancements I'd like to see and let you know what they are; you can do the work and let me know when it's done. Yeah, that's better. :-)
0
Ken
8/26/2008 2:55:05 PM
Ian Trackman wrote:

> Then surely isn't this a worthwhile extension to the
> language ?

It would be way down on my priority list but if you think
so enter it in QC as a feature request and see how many
votes it gets.

> 
> Either release the code to TClientDataset.Load and Save -
> or add a property to a field which indicates that it is
> lookup field and a property to the target field which is
> a key+value stringlist and an event for a missing key.
> 
> Is there a good reason why the source of Load and Save
> aren't available ?

You would have to ask someone who works for CodeGear. I
have no idea what the reason is.

-- 
Bill Todd (TeamB)
0
Bill
8/26/2008 3:28:55 PM
Ian Trackman wrote:

> Is there a good reason why the source of Load and Save aren't
> available

Because they are called LoadFromFile or LoadFromStream etc. And they
are available in most paid-for distros. (It is there in my D6 Pro which
is the oldest version I have loaded, as well as Rad Studio 2007.)

Are you using the free Turbo version or an old version? (I recall some
limitations with TClientDataSet in D3/4).

Eric
--
0
Eric
8/27/2008 12:17:51 AM
> > Is there a good reason why the source of Load and Save aren't available ?
> 
> Because that code belongs to CodeGear, and they don't want to release it?
> 
> Can you make all source code available for your commercial product (whatever it might be) so that I can modify it as I see fit? Thanks. 
> 
> Better yet, post your code. I'll review it for features/enhancements I'd like to see and let you know what they are; you can do the work and let me know when it's done. Yeah, that's better. :-)

I guess you are trying to be witty, but what is in the Delphi package is the IDE, the compiler and (almost all of ) the VCL source code.  This is one of the bits of VCL source code that is missing.
0
Ian
8/27/2008 7:22:39 AM
> Because they are called LoadFromFile or LoadFromStream etc. 

I was using shorthand.  TClientDataset.SaveToFile inherits (finally) from IDSBase.StreamDS which is a stdcall.  LoadFromFile similarly ends in a stdcall.  So without the code to those methods, it's not possible to know exactly how the higher-level methods should be overridden.

The problem is that even if StoreDefs is true, the FieldDefs information is not saved in the XML file (and apparently not in the binary file), so that an external application can't know the structure of the dataset, particularly its lookup links.
0
Ian
8/27/2008 7:37:19 AM
Ian Trackman wrote:

> The problem is that even if StoreDefs is true, the FieldDefs
> information is not saved in the XML file (and apparently not in the
> binary file), so that an external application can't know the
> structure of the dataset, particularly its lookup links

That bit is all buried in the inner workings of Midas - if you changed
that all sorts of things would break. I can't see CG contemplating it.
I think you have to take an alternative approach!

Eric
--
0
Eric
8/27/2008 12:55:58 PM
<Ian Trackman> wrote in message news:6143@forums.codegear.com...
> My ClientDataset has a lookup field.  It's a simple lookup - about 20 
> two-letter codes which reference long, user-friendly descriptive strings 
> when displayed to the user.  The lookup is more-or-less static - only 
> changing when the user needs a new description.
>
> I want to save the lookup linkage and the lookup table inside the main 
> dataset a) so as to avoid the need to have a secondary lookup dataset and 
> b) more importantly, so that the dataset can be self-contained and its 
> lookup structure and data known to any other application that wants to 
> access it.
>
Why not just create a class that contains 2 datasets, one for the data and 
the other for your lookup values. You can then treat this as a single entity 
which creates & links the lookup field when it loads your data from file/DB 
or wherever. This would be the closest solution to your requirements IMO.

Regards, Paul.
0
Paul
8/27/2008 1:23:13 PM
> Why not just create a class that contains 2 datasets, one for the data and 
> the other for your lookup values. You can then treat this as a single entity 
> which creates & links the lookup field when it loads your data from file/DB 
> or wherever. This would be the closest solution to your requirements IMO.

Yes, it is a solution, but very specific.  What I'm trying to do is to produce a single XML file that is self-contained and generic.  As it is, the saved dataset doesn't contain any indication that a particular field is a lookup field and has a limited range of possible values which correspond to descriptive strings.

I'm trying to produce a descendant of TClientDataset which extends the properties of a field defined as fkLookup to hold a small key->value sub-table.  Creating the object itself is relatively easy.  But because the ancestor's loading and saving code is not available, the hard part is to write the extensions to those methods.
0
Ian
8/27/2008 5:20:59 PM
> {quote:title=Ian Trackman wrote:}{quote}
> I guess you are trying to be witty, but what is in the Delphi package is the IDE, the compiler and (almost all of ) the VCL source code.  This is one of the bits of VCL source code that is missing.

Apparently, you don't have a sense of humor, but that's OK.

The relevant part of my post you actually mentioned in your reply above, but apparently missed it: the compiler and (+almost all of+) the VCL source code. Notice the part in parentheses?

Just because you think it should be included doesn't mean it should be. It's always been the case that, if you want specific functionality that's not included in some of the VCL, you write your own class (or descendent of the class missing the functionality you want). 

I don't understand the issue here, unless you're just being lazy and expecting CG to do your work for you when there doesn't appear to be a viable commercial reason for them to do so. If they thought there was a reason to provide that functionality, they would have done so*. If they didn't feel they had reason to withhold it, they would have made the source available.

*Unless it was an oversight on their part, in which case your option is to post the enhancement request in  Code Central.
0
Ken
8/27/2008 7:43:10 PM
You could create a phantom string (or memo) field(s) on 
TDatasetProvider.OnGetRecords and write both the lookup linkage and 
XMLData of the lookup dataset.
That way you get a stand-alone, self-contained xml.


Ian Trackman escreveu:
>> Why not just create a class that contains 2 datasets, one for the data and 
>> the other for your lookup values. You can then treat this as a single entity 
>> which creates & links the lookup field when it loads your data from file/DB 
>> or wherever. This would be the closest solution to your requirements IMO.
> 
> Yes, it is a solution, but very specific.  What I'm trying to do is to produce a single XML file that is self-contained and generic.  As it is, the saved dataset doesn't contain any indication that a particular field is a lookup field and has a limited range of possible values which correspond to descriptive strings.
> 
> I'm trying to produce a descendant of TClientDataset which extends the properties of a field defined as fkLookup to hold a small key->value sub-table.  Creating the object itself is relatively easy.  But because the ancestor's loading and saving code is not available, the hard part is to write the extensions to those methods.
0
Fabricio
8/29/2008 12:44:03 AM
Reply:

Similar Artilces:

How to edit the Data I retrieve from DataBase and Edit Data and then save it as a .txt file?
hi I need to retrieve Data From DB  ( I know how to do it) if the data is like Code (column name) ---------------------------------- xx1234 xx3293 xx5211 xx9230 xx1342   How to modify the Data I got from DB and Modify "xx" as "99" so the result would be  (only modify the Data retrive from DB , Don't modify the Data in DataBase) Code (column name) ---------------------------------- 991234 993293 995211 999230 991342   and output this result to a .txt file?   I using SQL2000 and Asp.Net C#   thank you   Use ...

Saving the data to database
I am trying to use FCKeditor to edit some content that is stored in a MS Access-database. But where am I going wrong? The html-markup that is stored in the database is shown in the editor, but it won't save... Any suggestions? This is my editpage.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="editpage.aspx.cs" Inherits="admin_editpage" Debug="true" ValidateRequest="false" %><%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Na...

Saving data to a database.
I'm building a web page in ASP .NET and i've got all my data that i want to put into a database but am unsure how i go about it. The examples that come with Visual Studio only deal with inputing data via a datalist or dataview. I have my access datasource configured. But where do i go from there. I would perfer not to make the data visible on the page and do it all via code. I've been looking on the net and haven't found any thing. Any help would be appreciated. are you using sqldataapdaters? datareaders? dataadapter w/datasets? and are you using sql w/stored procedures?My Regards to All,J...

Data not saving to the database
Hi,  I wanted to create a table to mark attendance. However, i've been spending a long time trying to debug why my user values are not saving back to the database. Please help me.. i'm a newbie in ASP.net I've been using GRIDVIEW using ObjectDataSource (AttnDS1). The feature is suppose to generate a list of student names and let the users put in the attendance by checking the checkboxes. After which they will save.. when they save, there's no error particular to the saving. Just that the values are not capture back to the database. Please help me on this .. here are the codes to it. ...

save data in database
Iam use ASP.NET to create Programming  under MS sql server How can save data in database from dataset You may starting from here.This posting is provided "AS IS" with no warranties, and confers no rights....

saving data into database
Im using MS visual web developer 2005 express edition. I have created a website and used the database they set up by using admin tools. One page requires to the take the users comment and to save it into the database. I've tried a formview and connected it to the database which worked. the problem is i cannot save whatever the user types into the textbox. insert query didnt work with this set upINSERT INTO aspnet_Membership(Comment) VALUES ('CommentTextBox.Text') Error: cannot set userId or to null. and if i make it allow nulls its going to move on to the next column a...

Data not saving to database
Hi,  This is a bit of a strange one to me. I was adding data to the database without any trouble and I havent changed any code and now instead of saving, i go my exception screen in the de-bugger I get the following message below, any iades?  I have also added my test code on the .vb screen. thanks A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Web.dll A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll An exception of type 'System.Threading.ThreadAbortException' o...

saving data into database
Im using MS visual web developer. I have created a website and used the database they set up by using admin tools. One page requires the take the users comment and to save it into the database. I've tried a formview and connected it to the database which worked. the problem is i cannot save whatever the user types into the textbox. {insert query didnt work with this set up }INSERT INTO aspnet_Membership(Comment) VALUES ('CommentTextBox.Text') Error: cannot set userId or to null. and if i make it allow nulls its going to move on to the next column. I would appreciate som...

Saving Data To A Database
Hi there, I have a web page (Visual Studio 2005, Asp.net 2.0) that has a series of textboxes and dropdownlists on it.  I want people to be able to enter their information and click submit.  When they click the submit button I want their information to save to a Sql Server 2005 database.  I am having a lot of trouble finding any information on this topic.  If someone could give me some sample code I would really appreciate it.  Thanks have you checked out ASPNet101.com? There are many basic samples, showing inserting records into a SQL Server database using...

how to get the Data saved messege populated when data is saved to data base on asp form
I am able to save data to the data base from the asp form which I have created. how ever I want that when the data is saved, i should get a pop up message or an alert box stating DATA SAVED or RECORD UPDATEd.   I am not able to fin out the way to do this in asp.net 2.0 using visual web developer.   the data base wich I am using is MY SQL Regards punit.  After your data is saved you can use the following to display a message:ClientScript.RegisterStartupScript(Page.GetType(), "msg", "alert('Record Saved');", True) ** Hope this helps!DennyDotNet.comSocial42.com Tha...

Call data from database and change data in database.
How can I call the value of a field from a database and then use an "if" to do different things when the user clicks on a button? Also, how can I then change that value of the field when I want to? Thanks, Sam  Could you please explain the question in detail.......     From the question, we can get the value by   OdbcConnection con = new OdbcConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString; con.Open(); OdbcCommand cmd = new OdbcCommand("SELECT ID FROM tabl...

Saving data to the database
Hi,   i have a program where i have to save some info to the database. In the main form i select add club, then i get a second form in which I can select a group and then type in the clubsname (the clubID is autmatically generated). i click OK and it is saved to the dataset. When i close the program and run it again, I can see the club in the group (in the main form i cans elect all groups and see the related clubs. But when I close Visual Studio 2005 and then open VS2005 again and run my program, the club isn't there anymore. So i added the club again using the program and looked ad...

FireDac not saving data into my database.Why?
Hi! I am making an application for mac with FireDac (fdconnection,fdquery) everything is fine.I run it and it shows my 2 records I have in my database. But when I insert a record with the following code it shows on my grid but if I close the app and open it again the new record disappears.I try applyupdates,commit updates, commit, I tried using updatasql and nothing worked.What can I do to make it work? Code: with fdquery do begin fieldbyname('name').asstring := edit1.text; fieldbyname('phone').asstring := edit2.text; post; close; open; End; what am I missing? ...

Saving formatted data to the database
I have a web application that requires entry of data in a TextBox. Data may be just a line or two typed in, but may also be a word document cut and pasted. At the moment the data is saved in the SQL 2005 database (nvarchar(max) field) ok, but when I try to display the data it is totally unformatted - a continuous stream of data, no carriage returns, etc. Does anyone know how to solve this dilema? Thanks, Mike Not a problem, after all. The Boundfield in my Gridview displayed it in a rubbish formt, but another Textbox displayed it as it should be....

Web resources about - Saving a lookup definition and data for a ClientDataset - embarcadero.delphi.database

Determining the file format from the data
AWare Systems TechTalk 001 Determining the file format from the data > I have a either a .bmp, .jpg, and .gif file in a ClientDataset's Blob ...

FireMonkey Q&A
Questions and answers from a FireMonkey webinar

Resources last updated: 11/28/2015 12:42:55 AM