2013-04-26 109 views
1

是有,我可以翻譯下面的代碼德爾福網站。 :C#德爾福翻譯/轉換器

 var newpin = new IntPtr(); 


     newpin = Marshal.AllocHGlobal(8); // what is this function? 
     retcode = Namespace.CashierCardInstallation("1234", ref newpin); // static method 
     if (retcode != 0) 
     { 
      MessageBox.Show("installation failed"); 

     } 



     var pin = new byte[8]; 
     Marshal.Copy(newpin, pin, 0, 8); // what is this function? 

或者什麼是delphi相當於這些方法的評論?謝謝!

+0

「Marshal.Copy(newpin,pin,0,8); //這是什麼功能?」 - http://msdn.microsoft.com/en-us/library/ms146635.aspx - 將數據從非託管內存指針複製到託管的32位有符號整數數組。 – RBA 2013-04-26 09:54:37

+0

「newpin = Marshal.AllocHGlobal(8); //這是什麼功能?」 - http://msdn.microsoft.com/en-us/library/s69bkh17.aspx - 使用指定的字節數從進程的非託管內存中分配內存。 – RBA 2013-04-26 09:56:04

+0

你在這段代碼上做了些什麼? – RBA 2013-04-26 09:56:26

回答

3

它只是使用AllocHGlobal分配非託管內存,並Marshal做純粹的內存拷貝。在Delphi中,您不需要任何這些功能,因爲您已經擁有了本地內存。

var 
    retcode: Integer; 
    Pin: array [0..7] of Byte;//or whatever the underlying data type is 
begin 
    retcode := Namespace.CashierCardInstallation('1234', @Pin); 
    if retcode <> 0 then 
    begin 
    ShowMessage("installation failed"); 
    end; 
end; 
+0

@David Ahh是的,忘了你可以這麼做:) – Lloyd 2013-04-26 10:01:52

+0

@DavidHeffernan Nah很好,很多年來沒有做過任何Delphi。 – Lloyd 2013-04-26 10:53:53

+0

非常感謝! – 2013-05-03 02:33:27