⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 finddialog.pas

📁 GIS地理信息系统开发。 大名鼎鼎的MAPX+DELPHI7.0软件开发
💻 PAS
字号:
// This sample application and corresponding sample code is provided
// for example purposes only.  It has not undergone rigorous testing
// and as such should not be shipped as part of a final application
// without extensive testing on the part of the organization releasing
// the end-user product.

unit FindDialog;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComObj, MapXLib_TLB, Variants;

type
  TFindForm = class(TForm)
    FindLayer: TComboBox;
    ExitButton: TButton;
    FindButton: TButton;
    SearchLabel: TLabel;
    findItem: TEdit;
    RefineItem: TEdit;
    RefineLabel: TLabel;
    FindLayerLabel: TLabel;
    FindDataset: TComboBox;
    FindDatasetLabel: TLabel;
    RefineLayerLabel: TLabel;
    RefineLayer: TComboBox;
    RefineDatasetLabel: TLabel;
    RefineDataset: TComboBox;
    FindFieldLabel: TLabel;
    FindField: TComboBox;
    RefineFieldLabel: TLabel;
    RefineField: TComboBox;
    Abbreviations: TCheckBox;
    ClosestAddress: TCheckBox;
    OtherBoundary: TCheckBox;
    UseRefiningInfo: TCheckBox;
    ReturnCodeLabel: TLabel;
    zoomLevelLabel: TLabel;
    zoomLevelText: TEdit;
    zoomDistLabel: TLabel;
    procedure FormActivate(Sender: TObject);
    procedure ExitButtonClick(Sender: TObject);
    procedure FindButtonClick(Sender: TObject);
    procedure FindDatasetChange(Sender: TObject);
    procedure RefineDatasetChange(Sender: TObject);
    procedure UseRefiningInfoClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FindForm: TFindForm;
  currentMap: TMap;

implementation

Uses
    MainUnit;
{$R *.DFM}

procedure TFindForm.FormActivate(Sender: TObject);
{ This procedure is used to fill combo boxes with
  options for using MapX Find method}
var
   i: integer;
begin

     // Set Variable to MapX Control
     currentMap := MainUnit.MapForm.Map1;

     if currentMap.layers.count = 0 then
        begin
            ShowMessage('There are no layers in Map');
            exit;
        end;
        
     // Fill Find Dataset Combo with available datasets
     findDataset.clear;
     finddataset.items.add('NONE');
     for i := 1 to currentMap.datasets.count do
         finddataset.items.add(currentMap.datasets.Item[i].name);
     finddataset.itemindex := 0;

     // Set Find Field Combo to be NONE by default
     findField.clear;
     findField.items.add('NONE');
     findField.itemindex := 0;

     // Fill Find Layer Combo with available layers
     findLayer.clear;
     for i := 1 to currentMap.Layers.Count do
         findLayer.items.add(currentMap.Layers.Item[i].name);
     findLayer.itemindex := 0;

     // Fill Refine Dataset Combo with available datasets
     refineDataset.clear;
     refineDataset.items.add('NONE');
     for i := 1 to currentMap.datasets.count do
         refinedataset.items.add(currentMap.datasets.Item[i].name);
     refineDataset.itemindex := 0;

     // Set Refine Field combo to be NONE by default
     refineField.clear;
     refineField.items.add('NONE');
     refineField.itemindex := 0;

     // Fill reFine Layer Combo with available layers
     refineLayer.clear;
     refineLayer.items.add('NONE');
     for i := 1 to currentMap.Layers.Count do
         refinelayer.items.add(currentMap.Layers.Item[i].name);
     refinelayer.itemindex := 0;

     // If checkbox for using refineing information is checked, then
     // enable the refine combo boxes
     if UseRefiningInfo.checked then
       Begin
            refineDataset.enabled := True;
            refineField.enabled := True;
            refineLayer.enabled := True;
       End
     else
       Begin
            refineDataset.enabled := False;
            refineField.enabled := False;
            refineLayer.enabled := False;
       End;
end;

procedure TFindForm.ExitButtonClick(Sender: TObject);
begin
     Close;
end;

procedure TFindForm.FindButtonClick(Sender: TObject);
var
   FoundObj, lyr, ds: variant;
   nothing: variant;
begin
     //Set nothing to be a varDispatch variant
    TVarData(nothing).VType := varDispatch;

    lyr := currentMap.Layers.Item[findLayer.text];
    // If there is at least one dataset and it was chosen in the comb
    // box, set it as the find dataset and set the field to the correct field
    if (currentMap.Datasets.Count > 0) and (finddataset.text <> 'NONE') then
      Begin
        ds := currentMap.Datasets.Item[findDataset.text];
        lyr.Find.FindDataset := currentMap.Datasets.Item[findDataset.text];
        lyr.Find.FindField := ds.Fields.Item[findField.text];
      End
    else
      // Reset the find dataset & field to nothing
      Begin
        lyr.Find.FindDataset := VarAsType(nothing, varDispatch);
        lyr.Find.FindField := VarAsType(nothing, varDispatch);
      End;

    // set or unset abbreviation check box
    if (Abbreviations.checked = true) then
       lyr.Find.Abbreviations := true
    else
        lyr.Find.Abbreviations := False;

    // set or unset closest address
    if (closestAddress.checked = true) then
       lyr.find.closestAddr := true
    else
        lyr.find.closestAddr := false;

    // set or unset other boundary
    if (otherBoundary.checked = true) then
       lyr.find.otherBoundary := true
    else
        lyr.find.otherBoundary := False;

    // If refining, set correct info
    if (useRefiningInfo.checked) then
      Begin
        if (refineLayer.text <> 'NONE') then
          Begin
            lyr.Find.RefineLayer := currentMap.Layers.Item[refineLayer.text];
            FoundObj := lyr.Find.Search(FindItem.text, refineItem.Text);
          End
        else
          if (refineDataset.text <> 'NONE') then
            Begin
              lyr.Find.RefineLayer := VarAsType(nothing, varDispatch);
              ds := currentMap.Datasets.Item[refineDataset.text];
              lyr.Find.RefineDataSet := currentMap.Datasets.Item[refineDataset.text];
              lyr.Find.RefineField := ds.Fields.Item[refineField.text];
              FoundObj := lyr.Find.Search(FindItem.text, refineItem.Text);
            End
          else
            Begin
               ShowMessage('No Refining Information specified, but checkbox checked');
               exit;
            End
      End
    else
      // Reset Refining properties to nothing
      Begin
        lyr.Find.RefineLayer := VarAsType(nothing, varDispatch);
        lyr.Find.RefineDataSet := VarAsType(nothing, varDispatch);
        lyr.Find.RefineField := VarAsType(nothing, varDispatch);
        FoundObj := lyr.Find.Search(FindItem.text, '');
      End;

    ReturnCodeLabel.caption := intToStr(foundObj.findrc);

    // Determine if match return code satifies our criteria
    if (foundObj.findrc Mod 10 = 1) then
       currentMap.ZoomTo(strToInt(zoomLeveltext.text), FoundObj.CenterX, FoundObj.CenterY)
    else
       showmessage('Exact Match Not found');
 end; //Procedure

procedure TFindForm.FindDatasetChange(Sender: TObject);
var
   i: integer;
   ds: variant;
begin
     if finddataset.text <> 'NONE' then
       Begin
         findField.clear;
         ds := currentMap.Datasets.Item[finddataset.text];
         for i := 1 to ds.Fields.Count do
            findField.items.add(ds.fields.Item[i].name);
         findField.itemindex := 0;
       End
     else
       Begin
            findField.clear;
            findField.items.add('NONE');
            findField.itemindex := 0;
       End;
end;

procedure TFindForm.RefineDatasetChange(Sender: TObject);
var
   i: integer;
   ds: variant;
begin
     if Refinedataset.text <> 'NONE' then
       Begin
            RefineField.clear;
            ds := currentMap.Datasets.Item[Refinedataset.text];
            for i := 1 to ds.Fields.Count do
                RefineField.items.add(ds.fields.Item[i].name);
            RefineField.itemindex := 0;
       End
     else
       Begin
            RefineField.clear;
            RefineField.items.add('NONE');
            RefineField.itemindex := 0;
       End;
end;

procedure TFindForm.UseRefiningInfoClick(Sender: TObject);
begin
     if UseRefiningInfo.Checked then
       Begin
            refineDataset.enabled := True;
            refineField.enabled := True;
            refineLayer.enabled := True;
       End
     else
       Begin
            refineDataset.enabled := False;
            refineField.enabled := False;
            refineLayer.enabled := False;
       End;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -