c# fonksiyon ve kodlarını delphi koduna dönüştürme

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
dynamo
Üye
Mesajlar: 96
Kayıt: 21 Haz 2005 02:05
Konum: istanbul

c# fonksiyon ve kodlarını delphi koduna dönüştürme

Mesaj gönderen dynamo »

c# da aşağıdaki fonksiyonları yapabildiğim kadarıyla delphi'ye dönüştürdüm ama hata alıyorum.GetMachineNumber fonsiyonunu delphi'de çalıştırdığımda "acccess vailation" hatası alıyorum.

Kod: Tümünü seç

//open commport 
        [DllImport("DLLK500.dll")]  
        public static extern bool OpenCommPort(char[] ComNum);

        //close commport
        [DllImport("DLLK500.dll")]
        public static extern bool CloseCommPort();

        //get reader#
        [DllImport("DLLK500.dll")]
        public static extern int GetMachineNumber(Byte[] getchar);

        //set reader#
        [DllImport("DLLK500.dll")]
        public static extern int SetMachineNumber(Byte[] getchar, char[] OldMachineNumber);

        //set reader time
        [DllImport("DLLK500.dll")]
        public static extern int SetTime(Byte[] getchar, char[] MachineId, char[] pStrTime, char[] PStrWeek);

        //get records number
        [DllImport("DLLK500.dll")]
        public static extern int GetRecordNumbers(Byte[] getchar, char[] MachineId);

        //get the Frist record
        [DllImport("DLLK500.dll")]
        public static extern int GetFristRecordEx(Byte[] getchar, char[] MachineId, int RecNo);

        //get the next record
        [DllImport("DLLK500.dll")]
        public static extern int GetNextRecordEx(Byte[] getchar, char[] MachineId, int RecNo);

        //delete records
        [DllImport("DLLK500.dll")]
        public static extern int DeleteAllRecord(Byte[] getchar, char[] MachineId); 

delphi karşılığı .kendim çevirdim.eksik yada hatalı olabilir.:

Kod: Tümünü seç

  function OpenCommPort(ComNum:string):Boolean; stdcall; external 'DLLK500.dll';
  function CloseCommPort():Boolean; stdcall; external 'DLLK500.dll';
  function GetMachineNumber(getchar:array of Byte):integer; stdcall; external 'DLLK500.dll';
  function SetMachineNumber(getchar:Byte;OldMachineNumber:string):integer; stdcall; external 'DLLK500.dll';
  function SetTime(getchar:Byte;MachineId:string;pStrTime:string;PStrWeek:string):integer; stdcall; external 'DLLK500.dll';
  function GetRecordNumbers(getchar:Byte;MachineId:string):integer; stdcall; external 'DLLK500.dll';
  function GetFristRecordEx(getchar:Byte;MachineId:string;RecNo:integer):integer; stdcall; external 'DLLK500.dll';
  function GetNextRecordEx(getchar:Byte;MachineId:string;RecNo:integer):integer; stdcall; external 'DLLK500.dll';
  function DeleteAllRecord(getchar:Byte;MachineId:string):integer; stdcall; external 'DLLK500.dll';

c# da çalışan kod.bu kodun delphi karşılığı tam yapamadım.:

Kod: Tümünü seç

private void button2_Click(object sender, EventArgs e)
        {
            Byte[] GetChar = new Byte[12];
            if (GetMachineNumber(GetChar) == 0)
            {
                textBox1.Text += "get reader# fail.\r\n";
            }
            else
            {
                textBox2.Text = "";
                for (int i = 0; i < GetChar.Length; i++)
                {
                    textBox2.Text += Convert.ToChar(GetChar[i]).ToString();
                }
            }
        }
Kullanıcı avatarı
dynamo
Üye
Mesajlar: 96
Kayıt: 21 Haz 2005 02:05
Konum: istanbul

Re: c# fonksiyon ve kodlarını delphi koduna dönüştürme

Mesaj gönderen dynamo »

c#'ta GetMachineNumber fonsiyonunu çalıştırdığımda GetChar byte dizisi değişkeni aldığı değerler:
GetChar={49,48,0,0,0,0,0,0,0,0,0,0}

delphi'de aşağıdaki kodu çalıştırdığımda

Kod: Tümünü seç

procedure TForm1.Button7Click(Sender: TObject);
var GetChar:array[0..11] of byte;
i:integer;

begin
   for i:=0 to 11 do begin
      GetMachineNumber(GetChar[i]);
   end;
   for i:=0 to 11 do begin
      Memo1.Lines.Add(inttostr(GetChar[i]));
   end;
   showmessage('aa');

end;
GetChar={49,49,49,49,49,49,49,49,49,49,49,49}

alıyor ardından "access vailation" hatası veriyor. :shock:


yardımcı olabilecek arkadaşlara minnettar kalacağım. :(
orhancc
Üye
Mesajlar: 585
Kayıt: 24 Ağu 2010 02:14
Konum: İstanbul / Kadıköy
İletişim:

Re: c# fonksiyon ve kodlarını delphi koduna dönüştürme

Mesaj gönderen orhancc »

Örnek proje gönderme şansın olursa bir inceleriz.
Cevapla