送300分, 如何將一個窗體對象(tform)傳遞給com程序(類型olevariant)???急急!!請幫忙(300分)

  • 主题发起人 主题发起人 pdb
  • 开始时间 开始时间
P

pdb

Unregistered / Unconfirmed
GUEST, unregistred user!
送300分, 如何將一個窗體對象(tform)傳遞給com程序(類型olevariant)???急急!!請幫忙
 
给你一对转换方法:
窗体—》流—》olevariant
olevariant—》流—》窗体
function VariantToStream(const Data: OleVariant ):TStream;
var
p: Pointer;
Stream: TStream;
begin
p := VarArrayLock(Data);
try
Stream.Write(p^, VarArrayHighBound(Data,1) + 1);
finally
VarArrayUnlock(Data);
end;
Result:=Stream;
end;

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;

 
沙隆巴斯的主人,
請問怎麼將流轉成窗體啊?
 
传递窗口的handle吧
 
procedure TForm1.Button1Click(Sender: TObject);
var
aMemoryStream : TMemoryStream;
aForm : TForm;
begin
aMemoryStream := TMemoryStream.Create;
aForm := TForm2.Create(Application);
aMemoryStream.WriteComponent(aForm);
aMemoryStream.SaveToFile('c:/aForm.stm');
aMemoryStream.Free;
aForm.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
aMemoryStream : TMemoryStream;
aForm : TForm;
begin
aForm := TForm.Create(Application);
aMemoryStream := TMemoryStream.Create;
aMemoryStream.LoadFromFile('c:/aForm.stm');
aMemoryStream.ReadComponent(aForm);
aForm.ShowModal;
end;
 
后退
顶部