袁绍伦
路人甲
路人甲
  • 注册日期2003-08-08
  • 发帖数654
  • QQ164646905
  • 铜币1336枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1623回复:0

Delphi Example of a SafeArray Dataset

楼主#
更多 发布于:2003-09-03 21:42
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;
喜欢0 评分0
愿意和大家交朋友! QQ:47559983 MSN:shaolun_yuan@hotmail.com eMail:shaolun-yuan@163.com
游客

返回顶部