2013-04-26 106 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