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

Delphi Example of a GlobalHandle Dataset

楼主#
更多 发布于:2003-09-03 21:40
procedure TMapForm.GlobalButtonClick(Sender: TObject);
var
 hGlobalData: Cardinal;
 pHandleData: PChar;
 tabifiedData: String;
 ds: Dataset;
begin
 { Our source data in the correct tab-deliminated form.
   In practice, this could come from a text file or some
   other source. }
 { The # signs are control escapes: #9 is a tab, #13 is a
   carriage return, and #10 is a linefeed. }
 tabifiedData := '"NY"'#9'105.40'#13#10'"MA"'#9'245.13'#13#10'"AK"'#9'195.30'#13#10'"CA"'#9'56.65'#13#10'"WI"'#9'100.00'#13#10;

 { Allocate space for the handle's data and copy the source
   data into it }
 hGlobalData := GlobalAlloc(GMEM_MOVEABLE, Length(tabifiedData)+1);
 pHandleData := GlobalLock(hGlobalData);
 strcopy(pHandleData, PChar(tabifiedData));
 GlobalUnlock(hGlobalData);

 try
  { now add the dataset to the datasets collection }
  ds := Map1.Datasets.Add(miDataSetGlobalHandle, hGlobalData,
   'TestDS', EmptyParam, EmptyParam, EmptyParam, EmptyParam,
   EmptyParam);

  { and create a simple theme from the data }

  ds.Themes.Add(EmptyParam, EmptyParam, EmptyParam,
   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
游客

返回顶部