![]() |
2 Dimensionales OleVariant Array erstellen?
Hi,
das folgende Beispiel wollte ich von VB nach Delphi überstetzen. Allerdings gibt es Schwierigkeiten mit der Übergabe eines 2 Dim. OleVariant Array. Ich habe das Array folgendermaßen deklariert:
Delphi-Quellcode:
So erhalte ich allerdings den Fehler: [Error] uRouteFrm.pas(175): Types of actual and formal var parameters must be identical
tmpObj : array[0..2] of array[0..2] of OleVariant;
Hier mal meine nicht funktionierende delphi Übersetzung:
Delphi-Quellcode:
Hier der original VB Code:procedure TForm1.Button3Click(Sender: TObject); Var Country, PlzTown, Street : String; GeocodeResult : Variant; tmpObj : array[0..2] of array[0..2] of OleVariant; // Pseudo 2 Dim array of OleVariant (Funktioniert nicht) begin Country := 'D'; PlzTown := '20354 Hamburg'; Street := 'Gänsemarkt'; GeocodeResult := MGCMapControl1.Map.Geocode(1, Country, PlzTown, Street); // Objekt für den Temp-Layer anlegen tmpObj [0, 0] := 'ID'; tmpObj [1, 0] := 1; tmpObj [0, 1] := 'X'; tmpObj [1, 1] := GeocodeResult[egriX, 0]; tmpObj [0, 2] := 'Y'; tmpObj [1, 2] := GeocodeResult[egriY, 0]; // Objekt Darstellung vbRed MGCMapControl1.Map.AddressDB.SetTMPSymbol(easSTAR, clred, 50); // Data | Layer : OleVar MGCMapControl1.Map.AddressDB.Insert(tmpObj, '#TMP'); // <= Hier kommt der oben genannte Fehler // tmpObj needs to be a 2*X array { Inserts a new entry into the address data base. The describing VARAINT needs to be a 2*X array, where X is the number of describing fields. [0,i] should contain the Name of the field [1,i] should contain the Value for that field. minimum requirements are the ID, X & Y fields. If the value field for ID is EMPTY it will be filled by this method. ID 1 x 2342242432 y 24523452343 } MGCMapControl1.RefreshMap;
Code:
Thanx Salomon
Private Sub Command1_Click()
Dim GeocodeResult As Variant Dim tmpObj Dim Country As String, PlzTown As String, Street As String 'In diesem Beispiel ist eine Adresse hart codiert 'sie muß zuerst geocodiert werden Country = "D" PlzTown = "20354 Hamburg" Street = "Gänsemarkt" GeocodeResult = MGCMapControl1.Map.Geocode(1, Country, PlzTown, Street) 'Objekt für den Temp-Layer anlegen ReDim tmpObj(1, 2) tmpObj(0, 0) = "ID" tmpObj(1, 0) = 1 tmpObj(0, 1) = "X" tmpObj(1, 1) = GeocodeResult(egriX, 0) tmpObj(0, 2) = "Y" tmpObj(1, 2) = GeocodeResult(egriY, 0) 'Festlegen wie Objekte im Temp-Layer dargestellt werden sollen MGCMapControl1.Map.AddressDB.SetTMPSymbol easSTAR, vbRed, 50 'Objekt in den Temp-Layer einfügen MGCMapControl1.Map.AddressDB.Insert tmpObj, "#TMP" MGCMapControl1.RefreshMap End Sub |
Re: 2 Dimensionales OleVariant Array erstellen?
Du hast kein Variant-Array erstellt, sondern ein Array mit Variants.
Schau mal in der OH nach VarArrayCreate, dort ist auch ein Bsp. |
Re: 2 Dimensionales OleVariant Array erstellen?
Du hast recht. Das varArrayCreate hatte ich mir schonmal kurz angeschaut. Das sah mir so aus, als ob ich damit nur 1 Dimensionale Variant Array erzeugen kann.
Ich schaus mir aber nochmal an. |
Re: 2 Dimensionales OleVariant Array erstellen?
Das Bsp zeigt auch wie man 2 Dim Array's erstellt.
|
Re: 2 Dimensionales OleVariant Array erstellen?
Bei mir werden in den Beispielen immer nur 1 Dim. Arrays verwendet. Ich habe das Array jetzt mal folgendermaßen deklariert, ist das so richtig?
tmpObj := VarArrayCreate([0,2,0,2], varVariant); Das ganze läst sich so kompilieren. Allerdings erhalte ich zur Laufzeit die Fehlermeldung "Wrong Data Variant Layout". Scheint also doch nicht 100% richtig zu sein. Ein kleines Deklarationsbeispiel zum 2 Dim. Variant Array könnte ich brauchen. Thanx Salomon |
Re: 2 Dimensionales OleVariant Array erstellen?
Delphi-Quellcode:
das funktioniert bei mir einwandtfrei! :gruebel:
var vCells : Variant;
... vCells := VarArrayCreate([0, fData.Count, 0, 6], varVariant); ... vCells[0, 0] := 'Vorgang'; vCells[0, 1] := 'Bezeichnung'; vCells[0, 2] := 'Zeit [' + fData.TE + ']'; vCells[0, 3] := 'Direkter Nachfolger'; vCells[0, 4] := 'Rangwerte Nachf. [' + fData.TE + ']'; vCells[0, 5] := 'Rangwert [' + fData.TE + ']'; vCells[0, 6] := 'Rang'; |
Re: 2 Dimensionales OleVariant Array erstellen?
Es funktioniert :-D
Ich hab mir nochmal den VB Code angeschaut. Der ReDim tmpObj(1, 2) Befehl gibt in den Klammern die Obergrenzen für das 2 Dim. Array an! Es muss also wie folgt definiert werden:
Delphi-Quellcode:
Danke für die Hilfe
tmpObj := VarArrayCreate([0,1,0,2], varVariant);
tmpObj [0, 0] := 'ID'; tmpObj [1, 0] := 1; tmpObj [0, 1] := 'X'; tmpObj [1, 1] := GeocodeResult[egriX, 0]; tmpObj [0, 2] := 'Y'; tmpObj [1, 2] := GeocodeResult[egriY, 0]; Salomon |
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:07 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz