Autor Beitrag
Sl0w
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 63

Win 7, Win 8
Delphi 2009, VS2012
BeitragVerfasst: Di 27.11.07 15:37 
Moinsen,

ich bräuchte Hilfe den folgenden .NET Code in Delphi Code zu übersetzen.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
               
                l_Filename = Application.CommonAppDataPath + "\\ERP-Account " + l_SendParameter.AccountID + ".cer";
                byte[] l_Certificate;
                using (FileStream i_FileStream = System.IO.File.Open(l_Filename, FileMode.Open))
                {
                    BinaryReader l_Reader = new BinaryReader(i_FileStream);
                    l_Certificate = l_Reader.ReadBytes((int)i_FileStream.Length);
                }


                l_InvoiceClient.Init(i_InvoiceURL, i_InvoiceURL2, l_SendParameter.AccountID, l_Certificate, Guid.NewGuid(), "Client", "1.0", "XiErpTestClient");


Das Problem ist das ich als Rückgabetyp ein PSafeArray benötige.

Meine Funktion sieht zur Zeit so aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
function HoleZertifikat(AcountID: String): PSafeArray;
var
   Datei: TFileStream;
begin
   Datei := TFileStream.Create(ExtractFilePath(ParamStr(0)+'\Zertifikate\'+AcountID+'.cer'), fmOpenRead);

end;


Der Importassistent für die Typbibliothek hat die Init-Methode folgendermaßen in Delphi übersetzt.

ausblenden Delphi-Quelltext
1:
2:
3:
procedure Init(const URL: WideString; const URL2: WideString; const AccountID: WideString; 
                   Certificate: PSafeArray; ClientGuid: TGUID; const ClientName: WideString; 
                   const ProductVersion: WideString; const ProgramID: WideString); safecall;



Ich weiß aber nicht wie ich den Inhalt der Datei in ein PSafeArray bekommen soll.

Kennt jemand von euch eine Lösung?

MFG

Lars
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Di 27.11.07 16:57 
PSafeArray scheint anscheinend ein Pointer auf ein TSafeArray zu sein. Vielleicht gibt es einen passenden Konstruktor von TSafeArray. Ein Typecast könnte eventuell auch helfen.
Sl0w Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 63

Win 7, Win 8
Delphi 2009, VS2012
BeitragVerfasst: Di 27.11.07 17:09 
Habe nach längerem Probieren die Lösung gefunden.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
function TFormMain.FileToPSafeArray(Datei: String): PSafeArray;
var
   aArray: Variant;
   aDatei: TStringList;
   i:integer;
begin
   aDatei := TStringList.Create;
   aDatei.LoadFromFile(Datei);

   aArray := VarArrayCreate([0, aDatei.Count-1], varOleStr);
   try
      for i:=0 to aDatei.Count-1 do begin
         aArray[i] := aDatei[i];
      end;
      result := PSafeArray(TVarData(aArray).VArray);
   finally
      freeandnil(aDatei);
   end;
end;


MFG
Lars