Delphi - ADODataSet Subset - delphi

I am building a form in Delphi that has a dropdown of Services and a grid of Add-Ons for the select service. The data I am getting comes from an API and I am storing the data for the Services in an ADODataSet as follows:
ID (integer)
Name (string)
Description (string)
BasePrice (currency)
AddOns (array of AddOn, not currently stored in the ADODataSet)
I would like to have the grid populate with the AddOn data based on the selection from the dropdown (each Service has a different list of Add-Ons). How do I store the AddOn information so that it can be related back to the Service info? Do I need to create a second ADODataSet or is there a way to store it in the same ADODataSet as the Services?
The AddOns have the following fields:
ID (integer)
Name (string)
Description (string)
UnitPrice (currency)
Quantity (integer)
I am using Delphi 2005 and have Indy for Delphi.
EDIT
In digging around the Fields editor for Datasets I found that I can create a field of type 'DataSet'. Would this allow me to tie the two together? If so can someone explain how that is done?
I tried to do it by creating a second dataset (ADODataSetAddOns) and assigning the new dataset to the dataset field in the first dataset (ADODataSetServices.AddOns) but get the error message 'No matching ADO data type for Dataset', which I assume is referring to the AddOns field not finding a dataset.

You can use 2 datasets (master-detail) to show the relation between the Services and Addons and then using TClientDataset as memory dataset you can store the selections using the Service Id, Addon Id pair as Index, the structure of this client dataset can be created in runtime like this
ClientDataSet1.FieldDefs.Clear;
ClientDataSet1.FieldDefs.Add('IdService', ftInteger);
ClientDataSet1.FieldDefs.Add('IdAddon ', ftInteger);
//add morr fieldd here is you want
ClientDataSet1.IndexDefs.Add('Index1','IdService;IdAddon',[ixPrimary, ixUnique]);
ClientDataSet1.IndexName:='Index1';
ClientDataSet1.CreateDataSet;
and finally when you need pass the data selected by the user to the service you can iterate over the ClientDataset just as any TDataset.

Related

Do all measurements (tables) in an influx database share field keys (columns)

I am used to Microsoft SQL server, but I have a task requiring use of a clients Influx server
From what I understand of the schema, and what I've been able to explore with the CLI, once you select a database, you can view all the field keys in that database, but there are not field keys that are exclusive to each measurement.
Is this true? If not, I will make a second question regarding how to access the field keys that ARE exclusive to a measurement and I will link it immediately following an answer.
Relevant links are
https://docs.influxdata.com/influxdb/v1.7/concepts/crosswalk/
https://docs.influxdata.com/influxdb/v1.8/query_language/explore-schema/
I have tried using client.query("SHOW FIELD KEYS").get_points() and it returns all field keys in all measurements in the database, since the client is only connected at the database level. But there does not seem to be a "use " options, like exists for "use "
Yes, each measurement has its own columns or field keys.
You can get the columns that are relevant to a single measurement by using
columns = client.query("SHOW FIELD KEYS").get_points(measurement = measurement_selection)
where measurement_selection is a string that matches the name of the measurement you wish to observe

access 2010 listbox OLE field

I have a simple query showing serial numbers and a machine type for a simple searchable function within a form. this query also contains an OLE column whih contains customer gathered data from a machine (parameters and alarm histories etc). I want the OLE section to be included within the list box so when the machine is searched for, the searcher will have access to all of the data for that machine.
is there an 'on click' or 'on enter' command for this?
Many thanks in advance
You put the recordID, along with the serial number and machine type in the query for the list box. then when the listbox selection is made, the event can trigger filling in the OLE field on the form - by using the recordID of the selected item.
All that being said - it's a huge guess as to even what you're talking about because you haven't shown us any form or table design or query.

How to implement a TDataSet-bound combobox with not-in-list values

I need to implement a combobox, which is bound to a TpFIBDataSet (descendant of TDataSet). I've done this several times before. It's not a big thing if it contains only predefined values.
This time, I'd like to have a combobox that accepts custom values entered by the user, also giving the ability to the user to select some predefined value. Newly entered values shall be inserted into some table of the database just before the record the combobox's field belongs to is posted.
The main problem seems to me, that predefined values are internally represented as integer IDs (the combobox I use is TwwDBComboBox from Roy Woll's InfoPower package, as it implements maplist functionality) because the field is a foreign key, while custom values may be nearly everything (only restricted by a mask).
How can I distinguish between an integer ID and integer user-input, for example?
See the set properties of the combobox:
AComboBox.Style := csDropDown;
AComboBox.MapList := True;
I don't request a solution as take this piece of code and be happy. I'm rather looking for some advice by others who might have or had a similar problem.
How can I distinguish between an integer ID and integer user-input, for example?
You go back to the database. Either query directly select count(*) from table where id = ComboBoxId.
Or use the Locate method of the dataset.
Or keep a cache handy in a MyList: TList<Integer> and do a MyList.BinarySearch to see if the item is already in the DB.
Obviously the cache will only work if the DB is single-user, because otherwise you will not be able to keep it up-to-date.
If it is not in the DB, you run the insert query.
After it's inserted you run the default combobox behavior, because now the values is sure to be in the DB.

Make Stored Procedure parameters cascading in Crystal Reports

I don't have a lot of experience using Stored Procedure as a data source for Crystal Reports. My question is that when you connect to an Oracle Stored procedure which has 2 parameters - Country and City, the parameters are already mapped in Crystal individually. Is there a way i can make these parameters cascading i.e. Country > City, either on front end or backend
After you add a stored procedure to the report, you should see the two parameters listed in the Parameter Fields section in the Field Explorer.
Edit one of the parameters, select 'Dynamic' from the List of Values picklist. Click the first row below in the Value column to select which field in your SP will contain the value (key) for Country. Do the same for the description. Click the second row to follow the same process for the City.
The parameters' values will be limited to what the SP returns.
If you publish the report to BusinessObjects Enterprise, it will create a BusinessView (and lots of other objects) to host the List of Values. This allows you to specify a broader (not just limited to the SP's result) set of values.

How filter a dataset based on a nested dataset record count?

I have a Dataset i want to apply a filter based on a dataset-type field record count, something like: 'NESTED_DATASET_FIELD.RecordCount > 0'
If the dataset comes from a SQL based storage engine, use a select distict query on the joined table with only fields from the master table in the result set. Let the SQL engine do the work for you.
Depending on your situation, you can use:
In OnFilterRecord event you can have:
Accept := myDataSetField.NestedDataSet.RecordCount>0;
If you have a SQL backend you can use the Exists or Count in order to fetch only the records which you need. Perhaps is the best approach if you are over a network. However I don't know what infrastructure you have.
In OnFilterRecord event you can have:
Accept := not myDataSetField.IsNull;
//Just testing if the DataSet field is empty - which is one of the fastest ways to do it
...but this depends on the structure of your data / dataset etc.
Sometimes is better to have a dedicated field in your DataSet / Table to specify this status because usually getting such info from the nested dataset can be expensive. (One must fetch it at least partially etc.)
Also, for the same considerations (see 4. above) perhaps you can have a Stored Procedure (if your DB backend permits) to get this info.
HTH

Resources