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

📄 mapformimpl1.pas

📁 此代码是关于mapgis的在
💻 PAS
字号:
unit MapFormImpl1;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ActiveX, AxCtrls, MapFormCOM_TLB, StdVcl, DLog, StdCtrls;

const
  {$I CompConstants.inc}
  
type
  TMapForm = class(TActiveForm, IMapForm)
  private
    { Private declarations }
    FEvents: IMapFormEvents;
    procedure ActivateEvent(Sender: TObject);
    procedure ClickEvent(Sender: TObject);
    procedure CreateEvent(Sender: TObject);
    procedure DblClickEvent(Sender: TObject);
    procedure DeactivateEvent(Sender: TObject);
    procedure DestroyEvent(Sender: TObject);
    procedure KeyPressEvent(Sender: TObject; var Key: Char);
    procedure PaintEvent(Sender: TObject);
    function CreateInplaceReportDesigner:TForm;
  protected
    { Protected declarations }
    procedure DoDestroy; override;
    procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
    procedure EventSinkChanged(const EventSink: IUnknown); override;
    function Get_Active: WordBool; safecall;
    function Get_AlignDisabled: WordBool; safecall;
    function Get_AutoScroll: WordBool; safecall;
    function Get_AutoSize: WordBool; safecall;
    function Get_AxBorderStyle: TxActiveFormBorderStyle; safecall;
    function Get_Caption: WideString; safecall;
    function Get_Color: OLE_COLOR; safecall;
    function Get_DoubleBuffered: WordBool; safecall;
    function Get_DropTarget: WordBool; safecall;
    function Get_Enabled: WordBool; safecall;
    function Get_Font: IFontDisp; safecall;
    function Get_HelpFile: WideString; safecall;
    function Get_KeyPreview: WordBool; safecall;
    function Get_PixelsPerInch: Integer; safecall;
    function Get_PrintScale: TxPrintScale; safecall;
    function Get_Scaled: WordBool; safecall;
    function Get_ScreenSnap: WordBool; safecall;
    function Get_SnapBuffer: Integer; safecall;
    function Get_Visible: WordBool; safecall;
    function Get_VisibleDockClientCount: Integer; safecall;
    procedure _Set_Font(var Value: IFontDisp); safecall;
    procedure Set_AutoScroll(Value: WordBool); safecall;
    procedure Set_AutoSize(Value: WordBool); safecall;
    procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle); safecall;
    procedure Set_Caption(const Value: WideString); safecall;
    procedure Set_Color(Value: OLE_COLOR); safecall;
    procedure Set_DoubleBuffered(Value: WordBool); safecall;
    procedure Set_DropTarget(Value: WordBool); safecall;
    procedure Set_Enabled(Value: WordBool); safecall;
    procedure Set_Font(const Value: IFontDisp); safecall;
    procedure Set_HelpFile(const Value: WideString); safecall;
    procedure Set_KeyPreview(Value: WordBool); safecall;
    procedure Set_PixelsPerInch(Value: Integer); safecall;
    procedure Set_PrintScale(Value: TxPrintScale); safecall;
    procedure Set_Scaled(Value: WordBool); safecall;
    procedure Set_ScreenSnap(Value: WordBool); safecall;
    procedure Set_SnapBuffer(Value: Integer); safecall;
    procedure Set_Visible(Value: WordBool); safecall;
    procedure SetupParent(AHandle, pAppId: Integer); safecall;
    procedure SubStationWarning(SubStationID: Integer;
      const WarningMessage: WideString; BoundSeed: Double); safecall;
    procedure LoadMapInstance(const Path: WideString); safecall;
    procedure UnLoadMapInstance; safecall;
    procedure Connect(const UserName, Password: WideString); safecall;
    function ConnectToDataBase(const Server, UserName,
      Password: WideString): WordBool; safecall;
    procedure GoToSubStation(SubStationID: Integer; BoundSeed: Double);
      safecall;
    procedure SetCurrentUnit(UnitID: Integer); safecall;
    procedure SetGISPageVisible(Index: Integer; Visible: WordBool); safecall;
  public
    { Public declarations }
    procedure Initialize; override;
  end;

implementation

uses ComObj, ComServ, UnitMainForm, UnitEagleEye, UnitNavigation,
  UnitMainLinkObjects, UnitDMLinks, UnitProject, UnitLayerControl,
  MainFormInstance, UnitQCGISProject, UnitGISShell, UnitAppTypes,
  UnitShellAPIs, WinFileSystem, AppDebug, UnitAboutForm;
  
{$R *.DFM}

{ TMapForm }

procedure TMapForm.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
begin
  { Define property pages here.  Property pages are defined by calling
    DefinePropertyPage with the class id of the page.  For example,
      DefinePropertyPage(Class_MapFormPage); }
end;

procedure TMapForm.EventSinkChanged(const EventSink: IUnknown);
begin
  FEvents := EventSink as IMapFormEvents;
  inherited EventSinkChanged(EventSink);
end;

procedure TMapForm.Initialize;
begin
  inherited Initialize;
  OnActivate := ActivateEvent;
  OnClick := ClickEvent;
  OnCreate := CreateEvent;
  OnDblClick := DblClickEvent;
  OnDeactivate := DeactivateEvent;
  OnDestroy := DestroyEvent;
  OnKeyPress := KeyPressEvent;
  OnPaint := PaintEvent;
end;

function TMapForm.Get_Active: WordBool;
begin
  Result := Active;
end;

function TMapForm.Get_AlignDisabled: WordBool;
begin
  Result := AlignDisabled;
end;

function TMapForm.Get_AutoScroll: WordBool;
begin
  Result := AutoScroll;
end;

function TMapForm.Get_AutoSize: WordBool;
begin
  Result := AutoSize;
end;

function TMapForm.Get_AxBorderStyle: TxActiveFormBorderStyle;
begin
  Result := Ord(AxBorderStyle);
end;

function TMapForm.Get_Caption: WideString;
begin
  Result := WideString(Caption);
end;

function TMapForm.Get_Color: OLE_COLOR;
begin
  Result := OLE_COLOR(Color);
end;

function TMapForm.Get_DoubleBuffered: WordBool;
begin
  Result := DoubleBuffered;
end;

function TMapForm.Get_DropTarget: WordBool;
begin
  Result := DropTarget;
end;

function TMapForm.Get_Enabled: WordBool;
begin
  Result := Enabled;
end;

function TMapForm.Get_Font: IFontDisp;
begin
  GetOleFont(Font, Result);
end;

function TMapForm.Get_HelpFile: WideString;
begin
  Result := WideString(HelpFile);
end;

function TMapForm.Get_KeyPreview: WordBool;
begin
  Result := KeyPreview;
end;

function TMapForm.Get_PixelsPerInch: Integer;
begin
  Result := PixelsPerInch;
end;

function TMapForm.Get_PrintScale: TxPrintScale;
begin
  Result := Ord(PrintScale);
end;

function TMapForm.Get_Scaled: WordBool;
begin
  Result := Scaled;
end;

function TMapForm.Get_ScreenSnap: WordBool;
begin
  Result := ScreenSnap;
end;

function TMapForm.Get_SnapBuffer: Integer;
begin
  Result := SnapBuffer;
end;

function TMapForm.Get_Visible: WordBool;
begin
  Result := Visible;
end;

function TMapForm.Get_VisibleDockClientCount: Integer;
begin
  Result := VisibleDockClientCount;
end;

procedure TMapForm._Set_Font(var Value: IFontDisp);
begin
  SetOleFont(Font, Value);
end;

procedure TMapForm.ActivateEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnActivate;
end;

procedure TMapForm.ClickEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnClick;
end;

procedure TMapForm.CreateEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnCreate;
end;

procedure TMapForm.DblClickEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnDblClick;
end;

procedure TMapForm.DeactivateEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnDeactivate;
end;

procedure TMapForm.DestroyEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnDestroy;
end;

procedure TMapForm.KeyPressEvent(Sender: TObject; var Key: Char);
var
  TempKey: Smallint;
begin
  TempKey := Smallint(Key);
  if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  Key := Char(TempKey);
end;

procedure TMapForm.PaintEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnPaint;
end;

procedure TMapForm.Set_AutoScroll(Value: WordBool);
begin
  AutoScroll := Value;
end;

procedure TMapForm.Set_AutoSize(Value: WordBool);
begin
  AutoSize := Value;
end;

procedure TMapForm.Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
begin
  AxBorderStyle := TActiveFormBorderStyle(Value);
end;

procedure TMapForm.Set_Caption(const Value: WideString);
begin
  Caption := TCaption(Value);
end;

procedure TMapForm.Set_Color(Value: OLE_COLOR);
begin
  Color := TColor(Value);
end;

procedure TMapForm.Set_DoubleBuffered(Value: WordBool);
begin
  DoubleBuffered := Value;
end;

procedure TMapForm.Set_DropTarget(Value: WordBool);
begin
  DropTarget := Value;
end;

procedure TMapForm.Set_Enabled(Value: WordBool);
begin
  Enabled := Value;
end;

procedure TMapForm.Set_Font(const Value: IFontDisp);
begin
  SetOleFont(Font, Value);
end;

procedure TMapForm.Set_HelpFile(const Value: WideString);
begin
  HelpFile := String(Value);
end;

procedure TMapForm.Set_KeyPreview(Value: WordBool);
begin
  KeyPreview := Value;
end;

procedure TMapForm.Set_PixelsPerInch(Value: Integer);
begin
  PixelsPerInch := Value;
end;

procedure TMapForm.Set_PrintScale(Value: TxPrintScale);
begin
  PrintScale := TPrintScale(Value);
end;

procedure TMapForm.Set_Scaled(Value: WordBool);
begin
  Scaled := Value;
end;

procedure TMapForm.Set_ScreenSnap(Value: WordBool);
begin
  ScreenSnap := Value;
end;

procedure TMapForm.Set_SnapBuffer(Value: Integer);
begin
  SnapBuffer := Value;
end;

procedure TMapForm.Set_Visible(Value: WordBool);
begin
  Visible := Value;
end;

procedure TMapForm.DoDestroy;
begin
  UnLoadMapInstance;
  inherited DoDestroy;
end;

function TMapForm.CreateInplaceReportDesigner: TForm;
begin
  if Form_Main<>nil then
  begin
    Result:=Form_Main;
    Exit;
  end;
  //--------------------------------------------------------------------------//
  //取消远东模式//
  SysLocale.FarEast:=False;
  //--------------------------------------------------------------------------//
  OleInitialize(nil);
  CoInitialize(nil);
  //--------------------------------------------------------------------------//
  if Form_Main=nil then
  begin
    Form_Main:=TForm_Main.Create(nil);
    Form_Main.BorderStyle:=bsNone;
    Form_Main.Parent:=Self;
  end;
  {创建连接数据模块}
  if dm_Links=nil then
    dm_Links:=Tdm_Links.Create(nil);
  {创建主连接数据模块,里面有所有设计期间定义的数据存取组件。但发现一个问题:
  在非EXE类程序中,创建主连接数据模块后,里面的所有数据存取组件在设计期间设置
  的Connection属性值,都变成了nil。为了重新保持设计期间的Connection属性值,在
  后面连接数据库后,调用函数ReLinkConnection重新设置dm_MainLinkObjects中数据
  存取组件的Connection属性值}
  if dm_MainLinkObjects=nil then
    dm_MainLinkObjects:=Tdm_MainLinkObjects.Create(nil);
  if FrmEagleEye=nil then
    FrmEagleEye:=TFrmEagleEye.Create(nil);
  if FrmNavigation=nil then
    FrmNavigation:=TFrmNavigation.Create(nil);
  if Form_About=nil then
    Form_About:=TForm_About.Create(nil);   
  //--------------------------------------------------------------------------//
  Result:=Form_Main;
  //--------------------------------------------------------------------------//
end;

procedure TMapForm.SetupParent(AHandle, pAppId: Integer);
begin
  CallerHandle:=AHandle;
  ParentAppId:=pAppId;
  MyGIS.LoadParentInstanceModules;
end;

procedure TMapForm.SubStationWarning(SubStationID: Integer;
  const WarningMessage: WideString; BoundSeed: Double);
begin
  TqcGISProject(MyGIS).SubStationWarning(SubStationID, WarningMessage, BoundSeed);
end;

procedure TMapForm.LoadMapInstance(const Path: WideString);
var
  AForm:TForm;
begin
  DebugLog.Add('Load\UnLoad', ['LoadMapInstance']);
  //--------------------------------------------------------------------------//
  CallerHandle:=0;
  AppType:=atWeb;
  AppPath:=Path;
  if (AppPath='')or(not DirectoryExists(AppPath)) then
    AppPath:=ForceCreateWebMapPath;
  AppPath:=CheckPath(AppPath);
  DebugLog.Add('Load\UnLoad', ['AppPath='+AppPath]);
  //--------------------------------------------------------------------------//
  AForm:=CreateInplaceReportDesigner;
  if AForm<>nil then
  begin
    AForm.Align:=alClient;
    AForm.Show;
  end;
  DebugLog.Add('Load\UnLoad', ['Main Form Show']);
  //--------------------------------------------------------------------------//
end;

procedure TMapForm.UnLoadMapInstance;
begin
  DebugLog.Add('Load\UnLoad', ['Begin UnLoadMapInstance']);
  if Form_Main=nil then
  begin
    DebugLog.Add('Load\UnLoad', ['Already UnLoad']);
    DebugLog.Add('Load\UnLoad', ['Complete UnLoadMapInstance']);
    Exit;
  end;

  OleUninitialize;
  CoUninitialize;
  DebugLog.Add('Load\UnLoad', ['OleUninitialize']);

  if FrmEagleEye<>nil then
  begin
    FreeAndNil(FrmEagleEye);
    FrmEagleEye:=nil;
  end;
  DebugLog.Add('Load\UnLoad', ['UnLoad FrmEagleEye']);
  if FrmNavigation<>nil then
  begin
    FreeAndNil(FrmNavigation);
    FrmNavigation:=nil;
  end;
  DebugLog.Add('Load\UnLoad', ['UnLoad FrmNavigation']);
  if Form_Main<>nil then
  begin
    FreeAndNil(Form_Main);
    Form_Main:=nil;
  end;
  DebugLog.Add('Load\UnLoad', ['UnLoad Form_Main']);
  if Form_About<>nil then
  begin
    FreeAndNil(Form_About);
    Form_About:=nil;
  end;
  DebugLog.Add('Load\UnLoad', ['UnLoad Form_About']);
  if dm_MainLinkObjects<>nil then
  begin
    dm_MainLinkObjects.Free;
    dm_MainLinkObjects:=nil;
  end;
  DebugLog.Add('Load\UnLoad', ['UnLoad dm_MainLinkObjects']);
  if dm_Links<>nil then
  begin
    dm_Links.Free;
    dm_Links:=nil;
  end;
  DebugLog.Add('Load\UnLoad', ['UnLoad dm_Links']);
  DebugLog.Add('Load\UnLoad', ['Complete UnLoadMapInstance']);
end;

procedure TMapForm.Connect(const UserName, Password: WideString);
begin
  TqcGISProject(MyGIS).Connect(UserName, Password);
end;

function TMapForm.ConnectToDataBase(const Server, UserName,
  Password: WideString): WordBool;
begin
  Result:=TqcGISProject(MyGIS).ConnectToDataBase(Server, UserName, Password);
end;

procedure TMapForm.GoToSubStation(SubStationID: Integer;
  BoundSeed: Double);
begin
  TqcGISProject(MyGIS).GoToSubStation(SubStationID, BoundSeed);
end;

procedure TMapForm.SetCurrentUnit(UnitID: Integer);
begin
  TqcGISProject(MyGIS).SetCurrentUnit(UnitID);
end;

procedure TMapForm.SetGISPageVisible(Index: Integer; Visible: WordBool);
begin
  TqcGISProject(MyGIS).SetGISPageVisible(Index, Visible);
end;

initialization
  TActiveFormFactory.Create(
    ComServer,
    TActiveFormControl,
    TMapForm,
    Class_MapForm,
    1,
    '',
    OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
    tmApartment);
  DebugLog.Add('Load\UnLoad', ['Active Form Created']);

finalization
  if DebugLog<>nil then
    DebugLog.Add('Load\UnLoad', ['Active Form Destroy']);

end.

⌨️ 快捷键说明

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