两段delphi 的代码,谁能帮我改写成C#的

问题描述

是电脑与某种机器通讯的,厂家只有delphi的例程,但我没有学过delphi,有哪位热心的朋友帮我改写成C#的代码:如果分不够,可以另开帖赠送,先谢了!//初始化IP机procedureTfrmRealInfo.pdIPSocket;vari:Integer;beginConnCount:=0;SockCount:=0;//ifchkServer.Checkedthenbeginsrvrsckt1.Port:=sePort.Value;srvrsckt1.Active:=Trueendelsebegin//每台IP机都必须初始化,并且保存返回的句柄SetLength(A_Sock,chkListMoc.Items.Count);fori:=0tochkListMoc.Items.Count-1dobeginifnotchkListMoc.Checked[i]thencontinue;SockCount:=SockCount+1;SetLength(SockArray,SockCount);trypdGetPort(chkListMoc.Items[i]);SockArray[SockCount-1]:=TClientSocket.Create(Nil);SockArray[SockCount-1].Active:=False;SockArray[SockCount-1].Port:=1024;SockArray[SockCount-1].Host:=fip;SockArray[SockCount-1].OnRead:=CsockRead;SockArray[SockCount-1].OnError:=CsockError;SockArray[SockCount-1].OnConnect:=CSockConnect;//ClientRBuf[SockCount-1].Ip:=fip;ClientRBuf[SockCount-1].RBuf:=nil;//SockArray[SockCount-1].Active:=True;exceptShowMessage(fip+'--Communicationcannotopen!');end;end;end;end;//读取IP机传来的数据信息procedureTfrmRealInfo.pdServerRead_New(Socket:TCustomWinSocket);varstrTime,CardNo:string;TempBuf0:array[0..100]ofByte;TempBuf:TByteDynArray;Recs,i,OldLen:integer;iCard:Int64;Y,M,D,H,Min:Word;ClientI:Integer;beginedt2.Text:=Socket.RemoteAddress;ClientI:=fnFindClient(Socket.RemoteAddress);ifClientI=-1thenExit;//接收数据包并累加到缓冲区内Recs:=Socket.ReceiveBuf(TempBuf0,Socket.ReceiveLength);OldLen:=High(ClientRbuf[ClientI].Rbuf);SetLength(ClientRbuf[ClientI].Rbuf,OldLen+1+Recs);fori:=0toRecs-1doClientRbuf[ClientI].Rbuf[OldLen+1+i]:=TempBuf0[i];//ifHigh(ClientRbuf[ClientI].Rbuf)>=24thenTempBuf:=fnGetOneCMD(ClientI);//ifHigh(TempBuf)<>7thenExit;//iCard:=TempBuf[0]*65536*256+TempBuf[1]*256*256+TempBuf[2]*256+TempBuf[3];CardNo:=IntToStr(iCard);//CardNo:=stringofchar('0',KHCD-length(CardNo))+CardNo;//分解日期Y:=((TempBuf[4]shr2)and$3F)+2000;M:=((TempBuf[4]and$3)shl2)or(TempBuf[5]shr6);D:=(TempBuf[5]shr1)and$1F;H:=((TempBuf[5]and$1)shl4)or((TempBuf[6]shr4)and$F);Min:=((TempBuf[7]shr6)and$3)or((TempBuf[6]and$f)shl2);strTime:=IntToStr(Y);ifM<9thenstrTime:=strTime+'-0'+inttostr(M)elsestrTime:=strTime+'-'+inttostr(M);ifD<9thenstrTime:=strTime+'-0'+inttostr(D)elsestrTime:=strTime+'-'+inttostr(D);strTime:=strTime+'';ifH<9thenstrTime:=strTime+'0'+inttostr(H)elsestrTime:=strTime+''+inttostr(H);ifMin<9thenstrTime:=strTime+':0'+inttostr(Min)elsestrTime:=strTime+':'+inttostr(Min);//ifCardNo=edt1.TextthenExit;edt1.Text:=CardNo;edt3.Text:=strTime;GetUserInfo(CardNo);//pdDoCMD(CardNo,strTime);end;

解决方案

解决方案二:
首先去了解c#的socket,然后对着代码调一下,SetLength是对数组设置长度厂家的一些dll,你需要用dllImport引入其他感觉没啥,语法都差不多
解决方案三:

解决方案四:
直接给你改造,愿意做的人少。你自己试着去改造一下,不明白的在问吧。

时间: 2024-09-20 07:43:13

两段delphi 的代码,谁能帮我改写成C#的的相关文章

函数调用-求大神,帮我改写成函数的形式。

问题描述 求大神,帮我改写成函数的形式. /*输入一个年份和月份,判断是否为闰年,输出年的天数和月的天数*/#include void main(){?int yearmonth;?cout<<""请输入年份和月份:""<?cin>>year>>month;?if(year%4==0&&year%100!=0||year%400==0)??cout<<year<<""

两段Perl脚本代码(数组应用与say用法)_perl

一.数组应用 复制代码 代码如下: #!/usr/bin env perl@zeng = `top -b -n 1`;foreach (@zeng) {print "$_\n";} 二.say的用法:自动换行 复制代码 代码如下: #!/user/bin env perluse 5.010; #表示使用perl 5.10的版本.say "Hello World!";my @fred = above_average(1..10);print "\@fred

我可以不可以在网页上加两段关键和说明?

问题描述 <metaname="keywords"content=""><metaname="description"content="">这两段是给网页加关键字和说明的代码,我可不以在加上两段这样的代码?让它变成这样:<metaname="keywords"content=""><metaname="description"

process-请大家帮我看看两段代码的区别真想不明白了

问题描述 请大家帮我看看两段代码的区别真想不明白了 有两段代码 代码一是单独写成函数来调用的, 我把他们合成一个主函数的代码 就出错 ?好像是变量递增的问题,我怎么也想不通,麻烦大家了. 代码一 ?别人写的: #include #include #include #include #pragma comment(lib,"Psapi.lib") int FindModules( DWORD processID ) { ? ? HMODULE hMods[1024]; ? ? HANDL

C#初学者 代码看不懂,求大神,用了DBhelper之后两段代码是怎么实现的

问题描述 C#初学者 代码看不懂,求大神,用了DBhelper之后两段代码是怎么实现的 //修改学院信息 private void btnupdate_Click(object sender, EventArgs e) { int index = dgvcollege.CurrentRow.Index; //取得选中行的索引 CollId = dgvcollege.Rows[index].Cells["CollegeId"].Value.ToString(); CollName = d

帮我看一下这段服务器端的代码是什么意思

问题描述 帮我看一下这段服务器端的代码是什么意思 if (Request.Params["testKey"] != null) { Response.Write(Request.Params["testKey"]); } 解决方案 如果接收到的参数中有testKey参数,就显示出来 解决方案二: 判断是否传递了testKey参数(包括get/post/cookies/servervariables),传递了就打印参数.http://blog.csdn.net/wor

java-这段代码谁来帮我看看是用来实现什么的

问题描述 这段代码谁来帮我看看是用来实现什么的 第一个for循环我还能看懂是让你先输入一个数n,接下来有n行,后面的循环是干嘛的呢,为什么又来接收一遍date[i][j],下面那个int sum =0又是干嘛 解决方案 看右边 输入3,表示3行 第一行第一个4,表示这行有4个数字,1 2 3 4 输出的10,为这行数字的和1+2+3+4=10 解决方案二: 而且你println已经有回车了,不需要加上 ,这样就有空行了. 解决方案三: 看看这段代码!!!!谁能帮我看看这段代码怎么实现不了小数点功

c#-这两段代码,只能运行其中一段,想用if语句来判断,但不知道条件表达式该怎么写

问题描述 这两段代码,只能运行其中一段,想用if语句来判断,但不知道条件表达式该怎么写 foreach (Uers item in userGroup) //第一段 { Console.WriteLine("请输入账号"); string idC1 = Console.ReadLine(); Console.WriteLine("请输入密码"); string pwd1 = Console.ReadLine(); if (idC1.Equals(item.idC)

请问谁能帮我解决一下这段订购javascript 代码

问题描述 请问谁能帮我解决一下这段订购javascript 代码 CSDN移动问答 只用javascript....可以嗎???