阅读:1623回复:0
Delphi Example of a SafeArray Dataset
procedure TMapForm.SafeArrayButtonClick(Sender: TObject);
var theData: Variant; // Safe Array of data flds: CMapXFields; ds: Dataset; begin { Create a new SafeArray and fill it with sample data. } theData := VarArrayCreate([1,3, 1, 2], varVariant); theData[1,1] := 'ME'; theData[2,1] := 'NH'; theData[3,1] := 'VT'; theData[1,2] := 100; theData[2,2] := 200; theData[3,2] := 300; try { Create a new fields object } flds := CoFields.Create; { Describe the structure of the SafeArray, so that our columns will have names after the Datasets.Add } flds.Add(1, 'State', miAggregationIndividual, miTypeString); flds.Add(2, 'Sales', miAggregationSum, miTypeNumeric); { Create a SafeArray dataset. } ds := Map1.Datasets.Add(miDataSetSafeArray, theData, 'My Dataset', 1, EmptyParam, EmptyParam, flds, EmptyParam); { Create a theme based on the "Sales" column in the new dataset } ds.Themes.Add(miThemeIndividualValue, 'Sales', 'My Theme', EmptyParam); except on E: EOleException do Application.MessageBox(PChar(E.Message), 'Error', MB_OK or MB_ICONERROR); end; end; |
|
|