본문 바로가기
삽질/Delphi

[Delphi] TStringlist를 OleVariant로 변환하기

by 푸딩s 2019. 6. 14.
728x90
반응형

  function StreamToVariant(Stream: TStream): OleVariant;
  var
    p: Pointer;
  begin
    Result := VarArrayCreate([0, Stream.Size - 1], varByte);
    p := VarArrayLock(Result);
    try
      Stream.Position := 0;
      Stream.Read(p^, Stream.Size);
    finally
      VarArrayUnlock(Result);
    end;
  end;


  function StringlistToVariant(aStrlist: TStrings): OleVariant;
  var
    hStream: TStream;
  begin
    hStream := TMemoryStream.Create;
    try
      aStrlist.SaveToStream(hStream);
      hStream.Seek(0, soFromBeginning);
      Result := StreamToVariant(hStream);
    finally
      hStream.Free;
    end;
  end;

 


var
  PostList: TStringList;
  Post:  OleVariant;
begin

  PostList := TStringList.Create; 

  PostList.Add('url=' + EncodeURL(url));

  PostList.Add('&body=' + HTTPEncode(UTF8Encode(Html)));
  Post := StringlistToVariant(PostList);

end;

 

728x90
반응형

댓글