I'm encountering some problems with converting Delpi7 pascal to C#, maybe a fresh set of eyes will see what I can't.
Pascal
procedure TForm1.Button5Click(Sender: TObject);
var Data: TData;
i: integer;
s: string;
begin
if not (CheckBox1.Checked) then
begin StatusBar1.SimpleText:='Bidirectional operation not allowed'; exit; end;
for i:=0 to 255 do Data[i]:=0;
Data:=Receive($02,8);
if (Data[1]=0) then
begin StatusBar1.SimpleText:='Failed'; exit; end;
s:='';
for i:=1 to 8 do
s:=s+Chr(Data[i+1]);
Edit1.Text:=s;
end;
C#
private void btnRX_Click(object sender, EventArgs e)
{
byte[] Data = null;
int i;
string s;
if (!(checkBox1.Checked))
{
toolStripStatusLabel1.Text = "Bidirectional operation not allowed";
return;
}
for (i = 0; i <= 255; i++)
{
Data[i] = 0;
}
Data = Receive(0x02, 8);
if ((Data[1] == 0))
{
toolStripStatusLabel1.Text = "Failed";
return;
}
s = "";
for (i = 1; i <= 8; i++)
{
s = s + (char)(Data[i + 1]);
}
txtBox1.Text = s;
}
I crash at
Data[i] = 0;