阅读:1460回复:0
Delphi Example of a GlobalHandle Dataset
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; |
|
|