这是我发数据的方法,发String 250长度以内的可以,怎样把ACCESS中备注格式的发过去? 
type 
  MyRecord = Packed Record 
  Myid : Integer; 
  Mysn: String[250]; 
  Myifshare : Boolean; 
  myshuyu:string[250]; 
  mycontent:String; 
  mysubject:string[250]; end; 
with MySendingRecord do 
  begin 
  mycontent := DataModule1.ADOQuery1.fieldbyname('content').Value  ; 
  mysubject:= DataModule1.ADOQuery1.fieldbyname('subject').asstring; 
  myshuyu:= DataModule1.ADOQuery1.fieldbyname('shuyu').asstring; 
  Myid := DataModule1.ADOQuery1.fieldbyname('id').Value ; 
  Mysn := sn; 
  Myifshare := ifshare; 
  end; 
// send and receive 
with  IdTCPClient1 do 
  begin 
  Host :='219.232.245.198'; 
  Port :=9099; 
  Connect; 
  WriteBuffer(MySendingRecord,SizeOf(MySendingRecord),true); 
  ReadBuffer(MyReceivingRecord,SizeOf(MyReceivingRecord)); 
  Disconnect; 
  end; 
end;

解决方案 »

  1.   

    type 
      MyRecord = Packed Record 
      Myid : Integer; 
      Mysn: String[250]; 
      Myifshare : Boolean; 
      myshuyu:string[250]; 
      mycontent:String; 
      mysubject:array[0..1024] of char;end; rec:myrecord;
    strpcopy(@rec.mysubject,'');取的时候
    strpas(strpas(@rec.mysubject));
      

  2.   

    我服务端是放在SQL库里的,这个备注字段在SQL中我用NTEXT存,行吗?现在感觉能传长一点的了,但是超过几百字就不行了
      

  3.   

    我改成mysubject:array[0..12048] of char;了,能传好多数据了
    是不是再加个0也行?有一些小说特别长
      

  4.   

    那不如生成XML,通知客户端下载
      

  5.   

    先说上传吧,上传搞定,估计下载就好办了能不是定义一个不定长的数组?我刚才试了一下,取的时候 
    不让取不定长的,发的时候让发
     mycontent:array of char;下面过不去:
    strpas(Myrec.mycontent)
      

  6.   

    干嘛非要发string啊 你不会变成内存流来发么 不管是什么类型数据 不管大小多少 用内存流来发最好
      

  7.   

    直接给代码吧 用indy 缓冲发送大string例子 
    发送端 KK为string类型
    client.WriteInteger(Length(kk));
    client.WriteBuffer(kk[1],Length(kk));
    服务器接收端 temp为string类型
    TheSize :=AThread.Connection.ReadInteger;
       SetLength(temp, TheSize);
        AThread.Connection.ReadBuffer(temp[1],TheSize);
      

  8.   

    这样好处很明显 string有多大就传多大 不受任何限制
      

  9.   

    成功了一大半,就是有的时候服务端报错,内在不能为READ
      

  10.   


    type
      MyRecord = Packed Record
      Myid : Integer;
      Mysn: String[250];
      Myifshare : Boolean;
      myshuyu:string[250];
      mycontentlen:integer;
      mysubject:string[250];
      end;procedure TfrmMain.IdTCPServerExecute(AThread: TIdPeerThread);
    var
      MyRec : MyRecord;  temp:string;
    beginif AThread.Connection.ReadLn='senddata' then
    beginAThread.connection.ReadBuffer(MyRec,SizeOf(MyRec));if      MyRec.Myifshare then
    begin
    memo1 .Text :=memo1 .Text+MyRec.Mysn+' 共享了 '+MyRec.mysubject+#13#10;
    SetLength(temp, MyRec.mycontentlen);
    AThread.Connection.ReadBuffer(temp[1],MyRec.mycontentlen);
    with DataModule1.ADOQuery1 do
    begin
    Close;
    sql.clear;
    sql.add('insert into sub_table (sn,id,subject,content,shuyu) values ('''+(MyRec.mysn)+''','+inttostr(MyRec.myid)+','''+MyRec.mysubject+''',:content,'+(myrec.myshuyu)+' )');
    Parameters.ParamByName('content').value:=temp;
    ExecSQL;
    end;
    end
    else
    begin
    Executesql('delete from sub_table where sn='''+(MyRec.mysn)+''' and id not in (select id from sub_table where shuyu=0 or  shuyu  in (select id from sub_table where  sn='''+(MyRec.mysn)+'''  ) ) ');
    Executesql('delete from sub_table where sn='''+(MyRec.mysn)+''' and id='+inttostr(MyRec.myid)+' ');
    memo1 .Text :=memo1 .Text+MyRec.Mysn+' 删除了 '+MyRec.mysubject+#13#10;end;
    SendMessage(Memo1.Handle, EM_SCROLL, SB_BOTTOM, 0); 
    //AThread.connection.WriteBuffer(MyRec,SizeOf(MyRec),true);
    end;end;
      

  11.   

    废话啊 这肯定会出错啊!!! IdTCPServerExecute 就是在线程下啊 你在线程下用query 最好是动态创建adoquery  执行完了就 free 不然多个连接都会调用同一个query 不出错才怪 SetLength(temp, MyRec.mycontentlen); 
    AThread.Connection.ReadBuffer(temp[1],MyRec.mycontentlen);
    你这两句为何要这么处理啊  最好是这样 前面发了一个结构以后 再发一次下一个string的 length 然后在
     readbuffer 记住 动态创建adoquery的时候 要记得创建前   coinitialize(nil);  free后       couninitialize;
    而且 引入activex 
      

  12.   

    而且你这个应用最好不要发结构数据  你这些基本上全部可以用string来表示
    那么你应该这么做 把你的结构数据变成数据1^数据2^数据3^数据4^....   变成一个大的string 这个数据可以不用规范多大  只是发的时候用我的方法法一下大小在发流即可   收到数据后 在把string拆开  根据^号的分割逐一取出数据给不同的变量 
    这样你完全可以一次发送完毕 而不用先发个数据结构在发一个大string 这样是不是简单多了 
      

  13.   

    定义有问题的:
    type 
      MyRecord = Packed Record 
      Myid : Integer; 
      Mysn: String[250]; 
      Myifshare : Boolean; 
      myshuyu:string[250]; 
      mycontent:String;   //问题在这里,
      mysubject:string[250]; 
    end; 记录中不要用string类型.必须是指定长度的数据.比如用array[1..2048]of byte;
    并且如果你的内容过长,你可以分多次发,自己定义一套可行的协议.+++++++++++++++++++++++++++++++++++++++++++++++++
    你测试一下,看看这个记录的大小是否为5?:
      TMyTestRecord = packed record
        Name : string;
        Age  : Byte;
      end;procedure TFormTransTest.btnTestSizeClick(Sender: TObject);
    var
      tstRcd : TMyTestRecord;
    begin
      tstRcd.Name := '我们祖上曾经辉煌过';
      tstRcd.Age := 35;
      ShowMessage(IntToStr(SizeOf(tstRcd ) ));
    end;
      

  14.   

    其实不需要这么麻烦的根本就不需要建个结构数据  你全部用数据1^数据2^数据3..用^隔开合成一个大string  然后用我给的方法传输  然后客户端接受后 按照^分析拆开string即可
      

  15.   

    procedure TfrmMain.IdTCPServerExecute(AThread: TIdPeerThread);
    var
      myadoquery:Tadoquery;
      temp,str:string;
      myid,mysn,Myifshare,myshuyu,mycontentlen,mysubject:string;
      sl:TStringList;
    begin
    if AThread.Connection.ReadLn='senddata' then
    begin
    str:=AThread.connection.Readln;
    sl:=split(str,'^');if sl[2]='-1' then
    begin
    SetLength(temp, strtoint(sl[4]));
    AThread.Connection.ReadBuffer(temp[1],strtoint(sl[4]));
    try
    coinitialize(nil);
    myadoquery:=TADOQuery.Create(Application);
    myadoquery.Connection:=DataModule1.ADOConnection1;
    with myadoquery do
    begin
    Close;
    sql.clear;
    sql.add('insert into sub_table (sn,id,subject,content,shuyu) values ('''+sl[1]+''','+sl[0]+','''+sl[5]+''',:content,'+sl[3]+' )');
    Parameters.ParamByName('content').value:=temp;
    ExecSQL;
    memo1 .Text :=memo1 .Text+sl[1]+' 共享了 '+sl[5]+#13#10;
    end;
    finally
    couninitialize;
    myadoquery.Free;
    end;
    end
    else
    begin
    try
    coinitialize(nil);
    Executesql('delete from sub_table where sn='''+sl[1]+''' and id not in (select id from sub_table where shuyu=0 or  shuyu  in (select id from sub_table where  sn='''+sl[1]+'''  ) ) ');
    Executesql('delete from sub_table where sn='''+sl[1]+''' and id='+sl[0]+' ');
    memo1 .Text :=memo1 .Text+sl[1]+' 删除了 '+sl[5]+#13#10;
    finally
    couninitialize;
    end;
    end;
    SendMessage(Memo1.Handle, EM_SCROLL, SB_BOTTOM, 0); 
    //AThread.connection.WriteBuffer(MyRec,SizeOf(MyRec),true);
    end;end;
      

  16.   

    现在改成一个串发送结构体了,但是还是报错,
    1,长的CONTENT不行
    2,短的有时候突然说内存错误,感觉是不是哪有问题呀
      

  17.   

    procedure TfrmMain.IdTCPServerExecute(AThread: TIdPeerThread); 
    var 
      myadoquery:Tadoquery; 
      temp,,tempstr,str:string;
      TheSize:integer; 
      myid,mysn,Myifshare,myshuyu,mycontentlen,mysubject:string; 
      sl:TStringList; 
    begin 
    TheSize :=AThread.Connection.ReadInteger; 
    SetLength(temp, TheSize); 
    AThread.Connection.ReadBuffer(temp[1],TheSize);
     myid:=copy(temp,0,pos('^',temp)-1);  从字符串找出第一个^号左边的数据取出
         tempstr:=copy(str,pos('^',temp)+1,length(temp)-pos('^',temp)); 从字符串找出第一个^号右边数据取出
         temp:=tempstr;重新赋值
    mysn:=copy(temp,0,pos('^',temp)-1); 在获取第一个^号左边数据  往下以此类推
     tempstr:=copy(str,pos('^',temp)+1,length(temp)-pos('^',temp));
         temp:=tempstr;
    Myifshare:=copy(temp,0,pos('^',temp)-1);
     tempstr:=copy(str,pos('^',temp)+1,length(temp)-pos('^',temp));
         temp:=tempstr;
    ......我就不写完了 一次类推 把所有的数据取出 要注意最后一组时候 也就是拆开只剩下 ***^@@@的时候 就要直接这样
    变量a:=copy(temp,0,pos('^',temp)-1); 
    变量B:=copy(str,pos('^',temp)+1,length(temp)-pos('^',temp)); 
    try 
    coinitialize(nil); 
    myadoquery:=TADOQuery.Create(Application); 
    myadoquery.Connection:=DataModule1.ADOConnection1; 
    with myadoquery do 
    begin 
    Close; 
    sql.clear; 
    sql.add('insert into sub_table (sn,id,subject,content,shuyu) values ('''+sl[1]+''','+sl[0]+','''+sl[5]+''',:content,'+sl[3]+' )'); 
    Parameters.ParamByName('content').value:=temp; 
    ExecSQL; 
    memo1 .Text :=memo1 .Text+sl[1]+' 共享了 '+sl[5]+#13#10; 
    end;
    myadoquery.Free;  //注销内存要放这里 
    finally 
    couninitialize; end; 
    end 
    else 
    begin 
    try 
    //coinitialize(nil);   这里错了 只有创建query控件的时候 要用这句 这里这句不应该要
    Executesql('delete from sub_table where sn='''+sl[1]+''' and id not in (select id from sub_table where shuyu=0 or  shuyu  in (select id from sub_table where  sn='''+sl[1]+'''  ) ) '); 
    Executesql('delete from sub_table where sn='''+sl[1]+''' and id='+sl[0]+' '); 
    memo1 .Text :=memo1 .Text+sl[1]+' 删除了 '+sl[5]+#13#10; 这里要改成 memo1.lines.add(内容);
    这里要加上 myadoquery.free;
    finally 
    couninitialize; //这句可以留着
    end; 
    end; 
    SendMessage(Memo1.Handle, EM_SCROLL, SB_BOTTOM, 0);  //这句完全没必要
    //AThread.connection.WriteBuffer(MyRec,SizeOf(MyRec),true); 
    end; end;
    你那边发送时候要这么构造 数据1+'^'+数据2..........这样 构造好后  在按我那样发送  
    你这样还搞不定的话 就要改行了
      

  18.   

    写错了一行
    把  myadoquery.free; 
    放在
    couninitialize;前面
      

  19.   

    Executesql
    这里在另一个地方也创建了query控件
    是不是都要加?
      

  20.   

    看你的代码就创建了一个query对象啊 
      

  21.   

    用流传送前,最好压缩一下,看时再解压,DELPHI中可以用一下函数来实现//压缩函数procedure Zip(var fs: TMemoryStream);varcs: TCompressionStream; ms: TMemoryStream; num: Integer;beginif not(Assigned(fs) and (fs.Size>0)) then Exit;    num := fs.Size;   ms := TMemoryStream.Create;  cs := TCompressionStream.Create(clMax, ms);try   fs.SaveToStream(cs);  cs.Free;  //ms.Position := 0;   fs.Clear;   fs.WriteBuffer(num, sizeof(num));   fs.CopyFrom(ms, 0);finally   ms.Free;end;end; //解压函数procedure UnZip(var fs: Tmemorystream);vards: TDecompressionStream; ms: TMemoryStream; num: Integer;beginif not(Assigned(fs) and (fs.Size>0)) then Exit;  fs.Position := 0; fs.ReadBuffer(num,sizeof(num)); ms := TMemoryStream.Create;ds := TDecompressionStream.Create(fs);try   ms.SetSize(num);  ds.Read(ms.Memory^, num);  //ms.Position := 0;   fs.Clear;   fs.CopyFrom(ms, 0);finally  ds.Free;   ms.Free;end;end;
      

  22.   

    procedure Executesql(sqlstr:string);
    var my_query:Tadoquery;
    begin
    my_query:=Tadoquery.Create(Application);
    try
    with my_query do
    begin
    Connection:=DataModule1.ADOConnection1;
    Close;
    sql.clear;
    sql.add(sqlstr);
    sql.SaveToFile('1.txt');
    ExecSQL;
    end;
    finally
    my_query.Free;
    end;
    end;
    这里是不是也要
    coinitialize(nil); 
    couninitialize; 
    ?
      

  23.   

    这里是不是也要 
    coinitialize(nil); 
    couninitialize; 
    ? 这两句是什么意思呀
      

  24.   

    为什么不用TStringList这个呢,,,