[Delphi] TStringlist를 OleVariant로 변환하기

  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;