AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Probleme mit ActiveX-Controls

Ein Thema von OlafSt · begonnen am 5. Mär 2014 · letzter Beitrag vom 11. Mär 2014
Antwort Antwort
OlafSt

Registriert seit: 2. Mär 2007
Ort: Hamburg
284 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

Probleme mit ActiveX-Controls

  Alt 5. Mär 2014, 13:51
Hallo Freunde,

ich stehe noch immer auf Kriegsfuß mit Interfaces und all dem Brimborium, der dranhängt. Ich habe schon ein paar dutzend Tutorials gelesen, die aber allesamt beim "jetzt weißt du, wie man ein Interface deklariert" enden. Mein Problem geht aber ein paar Generationen weiter.

Ich habe hier ein ActiveX-Control, das ich mit Delphi importiert habe (Komponente importieren, ActiveX-Steuerelement importieren, Control auswählen, Komponentenwrappe generieren AN, Unit erstellen, Fertig). Delphi produziert dabei folgendes (das kein einziges Tutorial bisher auch nur erwähnt hat):
Delphi-Quellcode:
// *********************************************************************//
// DispIntf: _DiwMapViewCtrl
// Flags: (4112) Hidden Dispatchable
// GUID: {357CEE48-2FD4-4311-9E92-1050A4429D8C}
// *********************************************************************//
  _DiwMapViewCtrl = dispinterface
    ['{357CEE48-2FD4-4311-9E92-1050A4429D8C}']
    property MapDescriptionFilename: WideString dispid 1;
    property FullExtent: IiwGeoRect dispid 2;
    property Extent: IiwGeoRect dispid 3;
    property Appearance: Smallint dispid -520;
    property BackColor: OLE_COLOR dispid 4;
    property BorderStyle: Smallint dispid 5;
    property ZoomFactor: Double dispid 6;
    property Scale: Integer dispid 7;
    property MouseMode: Smallint dispid 8;
    property MapLimits: IiwGeoRect dispid 9;
    property MapLimitMode: Smallint dispid 10;
    property IdentifyRadius: Double dispid 11;
    property IdentifyRadiusUnit: Smallint dispid 12;
    property IdentifyLayerNames: WideString dispid 13;
    property IdentifyGetBorderPolygons: Smallint dispid 14;
    property RefreshCount: Integer dispid 15;
    property Enabled: Shortint dispid -514;
    property BorderStyleCE: Smallint dispid -504;
    function ZoomIn: Integer; dispid 101;
    function ZoomOut: Integer; dispid 102;
    function ZoomToPoints(const geopoints: IiwGeoPoints; xMarginPercent: Integer;
                          yMarginPercent: Integer; minWidth: Double; minHeight: Double): Integer; dispid 103;
    function ZoomByFactor(factor: Double): Integer; dispid 104;
    function Pan(const geopoint: IiwGeoPoint): Integer; dispid 105;
    function ToMapPoint(xval: Integer; yval: Integer; const geopoint: IiwGeoPoint): Integer; dispid 106;
    function FromMapPoint(const geopoint: IiwGeoPoint; var xval: Integer; var yval: Integer): Integer; dispid 107;
    function SetFullExtent: Integer; dispid 108;
    function ActivateDynamicLayer(const key: WideString; const keyvalue: WideString): Integer; dispid 109;
    function DeactivateDynamicLayer(const key: WideString): Integer; dispid 110;
    function PrintMap(hdc: OLE_HANDLE; x: Integer; y: Integer; width: Integer; height: Integer): Integer; dispid 111;
    function RefreshMap: Integer; dispid 112;
    function GetErrorDesc(error: Integer; var description: WideString): Integer; dispid 113;
    function IdentifyVisibleObjects(identifyX: Smallint; identifyY: Smallint;
                                    radiusInPixel: Integer; const IdentifyLayerNames: WideString;
                                    getBorderPolygons: Smallint; var xmlResult: WideString): Integer; dispid 114;
    function IdentifyVisibleObjects1(const maprect: IiwGeoRect; viewWidth: Smallint;
                                     viewHeight: Smallint; identifyX: Smallint;
                                     identifyY: Smallint; radiusInPixel: Integer;
                                     const IdentifyLayerNames: WideString;
                                     getBorderPolygons: Smallint; var xmlResult: WideString): Integer; dispid 115;
    function GetDataProjectionName(var name: WideString): Integer; dispid 116;
    function OutputMap(hdc: OLE_HANDLE; x: Integer; y: Integer; width: Integer; height: Integer): Integer; dispid 117;
    function EventHandled: Integer; dispid 118;
    function GetMapDC(var hdc: OLE_HANDLE): Integer; dispid 119;
    function ReleaseMapDC(hdc: OLE_HANDLE): Integer; dispid 120;
    function SetNextDrawMode(mode: Integer): Integer; dispid 121;
    function SetSecurityKey(const filename: WideString; const key: WideString): Integer; dispid 10000;
    function SetRotationCenterAndAngle(x: Double; y: Double; angle: Double): Integer; dispid 10100;
    function SetLayerVisibility(const layername: WideString; value: Integer): Integer; dispid 10300;
    function SetWaitCursorMode(value: Integer): Integer; dispid 10301;
    function SetErrorHandlingMode(mode: Integer): Integer; dispid 10304;
    function SetLayerGroupVisibility(const groupvalue: WideString; value: Integer): Integer; dispid 10305;
    function SetImageQuality(mode: Integer): Integer; dispid 10306;
    function CreateMap(hdc: OLE_HANDLE; dpi: Integer; const Extent: IiwGeoRect; width: Integer;
                       height: Integer): Integer; dispid 10500;
    procedure AboutBox; dispid -552;
  end;
  //[... Es folgen ein paar Events...]
  TiwMapViewCtrl = class(TOleControl)
  private
    FOnAfterAllLayerDraw: TiwMapViewCtrlAfterAllLayerDraw;
    FOnPopupMenu: TiwMapViewCtrlPopupMenu;
    FOnCustomMenuCommand: TiwMapViewCtrlCustomMenuCommand;
    FOnMapViewError: TiwMapViewCtrlMapViewError;
    FOnFireIdentifyResult: TiwMapViewCtrlFireIdentifyResult;
    FOnSetCursor: TNotifyEvent;
    FOnMeasureDistance: TiwMapViewCtrlMeasureDistance;
    FOnAfterUserDraw: TiwMapViewCtrlAfterUserDraw;
    FOnProgress: TiwMapViewCtrlProgress;
    FIntf: _DiwMapViewCtrl;
    function GetControlInterface: _DiwMapViewCtrl;
  protected
    procedure CreateControl;
    procedure InitControlData; override;
    function Get_FullExtent: IiwGeoRect;
    procedure Set_FullExtent(const Value: IiwGeoRect);
    function Get_Extent: IiwGeoRect;
    procedure Set_Extent(const Value: IiwGeoRect);
    function Get_MapLimits: IiwGeoRect;
    procedure Set_MapLimits(const Value: IiwGeoRect);
  public
    function ZoomIn: Integer;
    function ZoomOut: Integer;
    function ZoomToPoints(const geopoints: IiwGeoPoints; xMarginPercent: Integer;
                          yMarginPercent: Integer; minWidth: Double; minHeight: Double): Integer;
    function ZoomByFactor(factor: Double): Integer;
    function Pan(const geopoint: IiwGeoPoint): Integer;
    function ToMapPoint(xval: Integer; yval: Integer; const geopoint: IiwGeoPoint): Integer;
    function FromMapPoint(const geopoint: IiwGeoPoint; var xval: Integer; var yval: Integer): Integer;
    function SetFullExtent: Integer;
    function ActivateDynamicLayer(const key: WideString; const keyvalue: WideString): Integer;
    function DeactivateDynamicLayer(const key: WideString): Integer;
    function PrintMap(hdc: OLE_HANDLE; x: Integer; y: Integer; width: Integer; height: Integer): Integer;
    function RefreshMap: Integer;
    function GetErrorDesc(error: Integer; var description: WideString): Integer;
    function IdentifyVisibleObjects(identifyX: Smallint; identifyY: Smallint;
                                    radiusInPixel: Integer; const IdentifyLayerNames: WideString;
                                    getBorderPolygons: Smallint; var xmlResult: WideString): Integer;
    function IdentifyVisibleObjects1(const maprect: IiwGeoRect; viewWidth: Smallint;
                                     viewHeight: Smallint; identifyX: Smallint;
                                     identifyY: Smallint; radiusInPixel: Integer;
                                     const IdentifyLayerNames: WideString;
                                     getBorderPolygons: Smallint; var xmlResult: WideString): Integer;
    function GetDataProjectionName(var name: WideString): Integer;
    function OutputMap(hdc: OLE_HANDLE; x: Integer; y: Integer; width: Integer; height: Integer): Integer;
    function EventHandled: Integer;
    function GetMapDC(var hdc: OLE_HANDLE): Integer;
    function ReleaseMapDC(hdc: OLE_HANDLE): Integer;
    function SetNextDrawMode(mode: Integer): Integer;
    function SetSecurityKey(const filename: WideString; const key: WideString): Integer;
    function SetRotationCenterAndAngle(x: Double; y: Double; angle: Double): Integer;
    function SetLayerVisibility(const layername: WideString; value: Integer): Integer;
    function SetWaitCursorMode(value: Integer): Integer;
    function SetErrorHandlingMode(mode: Integer): Integer;
    function SetLayerGroupVisibility(const groupvalue: WideString; value: Integer): Integer;
    function SetImageQuality(mode: Integer): Integer;
    function CreateMap(hdc: OLE_HANDLE; dpi: Integer; const Extent: IiwGeoRect; width: Integer;
                       height: Integer): Integer;
    procedure AboutBox;
    property ControlInterface: _DiwMapViewCtrl read GetControlInterface;
    property DefaultInterface: _DiwMapViewCtrl read GetControlInterface;
  published
    property Anchors;
    property TabStop;
    property Align;
    property DragCursor;
    property DragMode;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property Visible;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnStartDrag;
    property OnMouseUp;
    property OnMouseMove;
    property OnMouseDown;
    property MapDescriptionFilename: WideString index 1 read GetWideStringProp write SetWideStringProp stored False;
  public
    property FullExtent: IiwGeoRect read Get_FullExtent write Set_FullExtent stored False;
  published
  public
    property Extent: IiwGeoRect read Get_Extent write Set_Extent stored False;
  published
    property Appearance: Smallint index -520 read GetSmallintProp write SetSmallintProp stored False;
    property BackColor: TColor index 4 read GetTColorProp write SetTColorProp stored False;
    property BorderStyle: Smallint index 5 read GetSmallintProp write SetSmallintProp stored False;
    property ZoomFactor: Double index 6 read GetDoubleProp write SetDoubleProp stored False;
    property Scale: Integer index 7 read GetIntegerProp write SetIntegerProp stored False;
    property MouseMode: Smallint index 8 read GetSmallintProp write SetSmallintProp stored False;
  public
    property MapLimits: IiwGeoRect read Get_MapLimits write Set_MapLimits stored False;
  published
    property MapLimitMode: Smallint index 10 read GetSmallintProp write SetSmallintProp stored False;
    property IdentifyRadius: Double index 11 read GetDoubleProp write SetDoubleProp stored False;
    property IdentifyRadiusUnit: Smallint index 12 read GetSmallintProp write SetSmallintProp stored False;
    property IdentifyLayerNames: WideString index 13 read GetWideStringProp write SetWideStringProp stored False;
    property IdentifyGetBorderPolygons: Smallint index 14 read GetSmallintProp write SetSmallintProp stored False;
    property RefreshCount: Integer index 15 read GetIntegerProp write SetIntegerProp stored False;
    property Enabled: Shortint index -514 read GetShortintProp write SetShortintProp stored False;
    property BorderStyleCE: Smallint index -504 read GetSmallintProp write SetSmallintProp stored False;
    property OnAfterAllLayerDraw: TiwMapViewCtrlAfterAllLayerDraw read FOnAfterAllLayerDraw write FOnAfterAllLayerDraw;
    property OnPopupMenu: TiwMapViewCtrlPopupMenu read FOnPopupMenu write FOnPopupMenu;
    property OnCustomMenuCommand: TiwMapViewCtrlCustomMenuCommand read FOnCustomMenuCommand write FOnCustomMenuCommand;
    property OnMapViewError: TiwMapViewCtrlMapViewError read FOnMapViewError write FOnMapViewError;
    property OnFireIdentifyResult: TiwMapViewCtrlFireIdentifyResult read FOnFireIdentifyResult write FOnFireIdentifyResult;
    property OnSetCursor: TNotifyEvent read FOnSetCursor write FOnSetCursor;
    property OnMeasureDistance: TiwMapViewCtrlMeasureDistance read FOnMeasureDistance write FOnMeasureDistance;
    property OnAfterUserDraw: TiwMapViewCtrlAfterUserDraw read FOnAfterUserDraw write FOnAfterUserDraw;
    property OnProgress: TiwMapViewCtrlProgress read FOnProgress write FOnProgress;
  end;
Zu diesem Steuerelement gibt es einen Berg Hilfsklassen, die ich als Typbibliothek importiert habe. Diese Hilfsklassen treiben mich in den Wahnsinn, denn egal, was ich auch anstelle, der Compiler meckert oder das Programm crasht:

Delphi-Quellcode:
// *********************************************************************//
// Interface: IiwGeoRect
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {2DFE1A47-4E0F-4639-9CA7-E63C760CAC63}
// *********************************************************************//
  IiwGeoRect = interface(IDispatch)
    ['{2DFE1A47-4E0F-4639-9CA7-E63C760CAC63}']
    function Get_TopLeft: IiwGeoPoint; safecall;
    procedure Set_TopLeft(const pVal: IiwGeoPoint); safecall;
    function Get_BottomRight: IiwGeoPoint; safecall;
    procedure Set_BottomRight(const pVal: IiwGeoPoint); safecall;
    property TopLeft: IiwGeoPoint read Get_TopLeft write Set_TopLeft;
    property BottomRight: IiwGeoPoint read Get_BottomRight write Set_BottomRight;
  end;

// *********************************************************************//
// DispIntf: IiwGeoRectDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {2DFE1A47-4E0F-4639-9CA7-E63C760CAC63}
// *********************************************************************//
  IiwGeoRectDisp = dispinterface
    ['{2DFE1A47-4E0F-4639-9CA7-E63C760CAC63}']
    property TopLeft: IiwGeoPoint dispid 1;
    property BottomRight: IiwGeoPoint dispid 2;
  end;
//[...Tonnen anderer Klassen...]

// *********************************************************************//
// Die Klasse CoiwGeoRect stellt die Methoden Create und CreateRemote zur
// Verfügung, um Instanzen des Standard-Interface IiwGeoRect, dargestellt
// von CoClass iwGeoRect, zu erzeugen. Diese Funktionen können
// von einem Client verwendet werden, der die CoClasses automatisieren
// will, die von dieser Typbibliothek dargestellt werden.
// *********************************************************************//
  CoiwGeoRect = class
    class function Create: IiwGeoRect;
    class function CreateRemote(const MachineName: string): IiwGeoRect;
  end;
//[...Tonnen anderer Co-Dinger...]
class function CoiwGeoRect.Create: IiwGeoRect;
begin
  Result := CreateComObject(CLASS_iwGeoRect) as IiwGeoRect;
end;

class function CoiwGeoRect.CreateRemote(const MachineName: string): IiwGeoRect;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_iwGeoRect) as IiwGeoRect;
end;
Meine Software initialisiert nun so ein TiwMapViewCtrl, alles mit Wasser gekocht:
Delphi-Quellcode:
     CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
     FMap:=TIwMapViewCtrl.Create(FTargetView); //FTargetView ist ein normales TPanel
     FMap.Align:=alClient;
     FMap.MapLimitMode:=0;
     FMap.Name:='iwMapViewCtrl1';
     FMap.RefreshCount:=-1;
     FMap.Scale:=50000000;
     FMap.ZoomFactor:=2;
     SetBounds(0,0,TargetView.ClientWidth,TargetView.ClientHeight);
     FTargetView.InsertControl(FMap);
Klappt alles, Karte wird angezeigt, ist Zoombar, bewegbar etcpp. Nun möchte ich einen selbsterstellten Punkt anzeigen. Der Punkt wird also in die Karte eingefügt und wir verschieben dann die Karte zu diesem Punkt hin:
Delphi-Quellcode:
procedure TMapInfoMap.MoveToPosition(Bounds: TRect; GP: GPSPosition; const WithZoom: boolean);
var
   Pts: IiwGeoPoints;
   pt, cpt: IIwGeoPoint;
   x,y: Double;
   Ctr: IiwGeoRect;
begin
     //Compiler meckert hier, das CoInitialize nicht aufgerufen wurde, obwohl das DREIMAL im
     //Code passiert, wenn auch als CoInitializeEx
     CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
     GPToFloat(GP,x,y); //x,y enthalten nun GPS-Koordinaten im Dezimalkomma-Format
     pt:=CoIwGeoPoint.Create; //Funktioniert
     pt.SetPoint(y,x,'WGS84'); //Funktioniert

     //Mittelpunkt des Kartenausschnitts ermitteln
     cpt:=CoIwGeoPoint.Create; //Funktioniert

     //FMap.Extent ist ein IiwGeoRect
     Ctr:=FMap.Extent;
     //Funktioniert, Ctr wird mir als Pointer ($irgendwo) as IiwGeoRect angezeigt, was mich so schon
     //stutzig macht
     x:=(Ctr.BottomRight.x - Ctr.TopLeft.x) / 2; //Schutzverletzung, BottomRight existiert nicht
     y:=(Ctr.TopLeft.y - Ctr.BottomRight.y) / 2; //TopLeft auch nicht
     //Zum rest kommen wir natürlich nicht mehr

     //Und Karte hinschubsen
     FMap.Pan(pt);
     Ctr:=nil;
     pt:=nil;
end;
Ich verstehe beim besten Willen nicht, wieso da NOCH EINMAL CoInitialize aufgerufen werden muß. Ich kapiere außerdem nicht, wie ich einen definitiv existierenden IiwGeoRect (FMap.Extent) einer lokalen Variable (Ctr) desselben Typs zuweisen kann, vom dem Ding aber nur die Hälfte überhaupt "existiert".

Habe ich beim Import schon was falsch gemacht ? Wenn nein, wo ist mein Fehler, wie behebe ich den und wieso muß man das so machen ?

Ich weiß, viele Fragen... Aber ich hoffe, an diesem konkreten Beispiel endlich das Kriegsbeil mit Interfaces unter die Erde bringen zu können

Danke schon jetzt für eure Mühen und eure Geduld.
  Mit Zitat antworten Zitat
Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#2

AW: Probleme mit ActiveX-Controls

  Alt 5. Mär 2014, 17:48
Hast du die unit ComObj eingebunden?
Diese Unit sorgt dafür dass automatisch CoInitialize() aufgerufen wird.
fork me on Github
  Mit Zitat antworten Zitat
OlafSt

Registriert seit: 2. Mär 2007
Ort: Hamburg
284 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#3

AW: Probleme mit ActiveX-Controls

  Alt 5. Mär 2014, 19:04
Unglaublich, aber wahr - jetzt funktioniert das ganze. ich dachte, die Unit ActiveX würde genügen - wieder was gelernt.

1000 Dank für diesen Tip, war schon am verzweifeln.
  Mit Zitat antworten Zitat
OlafSt

Registriert seit: 2. Mär 2007
Ort: Hamburg
284 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#4

AW: Probleme mit ActiveX-Controls

  Alt 11. Mär 2014, 11:24
Hat nicht lange vorgehalten, der Tip. Nächsten Tags hatte ich denselben Mist wieder am Hals.

In letzter Verzweiflung habe ich dann XE4 komplett neu installiert - seitdem ist Ruhe im Karton. Da hat sich wohl was "die Karten gelegt".
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:06 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz