• webservices传文件


    有两种方法,一种是把二进制对象转成base64码,返回字符串,应该是最简单的方法,另外一种就是返回二进制数组TByteArray
    服务器:
    function TFileSoap.getPic(out size:integer): TByteArray;
    var
    buf:TMemoryStream;
    begin
    try
        if not FileExists('c:\1.bmp') then
          raise Exception.Create('file not found.');

        buf:=TMemoryStream.create;
        buf.LoadFromFile('c:\1.bmp');
        size:=buf.Size;
        setlength(result,size);
        move(buf.Memory^,result[0],size);
    finally
        buf.free;
    end;
    end;
    客户端
    procedure TForm1.Button1Click(Sender: TObject);
    var
    size:integer;
    buf:TMemoryStream;
    ary:TByteArray;
    begin
    buf:=TMemoryStream.create;
    try
        ary:=GetIFileSoap.getPic(size);
        buf.SetSize(size);
        move(ary[0],buf.memory^,size);
        Image1.Picture.Bitmap.LoadFromStream(buf);
    finally
        buf.free;
    end;
    end;

  • 相关阅读:
    HDU 5319 Painter
    HDU 5328 Problem Killer
    HDU 5327 Olympiad
    HDU 5339 Untitled
    HDU 5335 Walk Out
    HDU 5317 RGCDQ
    HDU 5326 Work
    CF GYM 100703A Tea-drinking
    CF GYM 100703B Energy Saving
    CF GYM 100703F Game of words
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2743197.html
Copyright © 2020-2023  润新知