怎么把一张图片通过Midas的方法传到中间层 ( 积分: 300 )

  • 主题发起人 主题发起人 sungirl1126
  • 开始时间 开始时间
S

sungirl1126

Unregistered / Unconfirmed
GUEST, unregistred user!
如何把TPicturel转成IPicture
怎么把一张图片通过Midas的方法传到中间层
 
如何把TPicturel转成IPicture
怎么把一张图片通过Midas的方法传到中间层
 
参考这个:
http://delphibbs.com/delphibbs/dispq.asp?lid=2943924
 
能否具体指点一下
 
type
TIntfPicture=class(ITPicture,IInterface)
 
麻烦再具体点
 
或者,看一下这个帮助
When defining a class that supports one or more interfaces, it is convenient to use TInterfacedObject as a base class because it implements the methods of IInterface.
TInterfacedObject class is declared in the System unit as follows:

type
TInterfacedObject = class(TObject, IInterface)
protected
FRefCount: Integer;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
public
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
class function NewInstance: TObject; override;

property RefCount: Integer read FRefCount;
end;

Deriving directly from TInterfacedObject is straightforward. In the following example declaration, TDerived is a direct descendant of TInterfacedObject and implements a hypothetical IPaint interface.

type
TDerived = class(TInterfacedObject, IPaint)
...
end;

Because it implements the methods of IInterface, TInterfacedObject automatically handles reference counting and memory management of interfaced objects. For more information, see Memory management of interface objects, which also discusses writing your own classes that implement interfaces but that do not follow the reference-counting mechanism inherent in TInterfacedObject.
 
你就写一下把一张图片存到IPicture,再用IPicture的SavetoFile保存为图片,给我后散分
 
我曾经作过把图片载入一个stream然后转换成variant通过midas在客户端和服务器间传递
但是和IPicture没关系,不知适不适合你
 
我只要结果,把你的方法的代码贴出来好吗?
 
这里有两个三层中传递图片的帖子,Midas中调试通过(用内存流)。
有代码,供参考。

http://www.delphibbs.com/delphibbs/dispq.asp?lid=2414129
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2117291
 
不是使用接口技术,我以前的贴子:
再问的话,你别干这行了

unit TransComponent;
{本工具供Com/DCom间传递组件(从TComponent继承的所有对象)
调用 VariantToComponent 时会出现 "Class <TClassName> not Found "提示 多次 ,
在调用单元的initialization段加以下语句:
RegisterClass(<ClassName>),如
RegisterClass(TClientDataSet);
RegisterClass(TStringField);
VariantToComponent 的参数 Component 必须声明为TComponent,然后使用强制类型转换使用它
如:TClientDataSet(Component)
}
interface
uses SysUtils,Classes;

procedure ComponentToVariant(const Component:TComponent;out vData:OleVariant);
procedure VariantToComponent(out Component:TComponent; vData:OleVariant);

implementation
procedure UnloadVariantArray(
var VData: OleVariant; PData: Pointer;
NumBytes: Integer);
var
PVData: PByteArray;
begin
{ Lock the variant array, copy the data to the array, and
unlock the variant array. }
PVData := VarArrayLock(VData);
try
{ Move the data in memory that PVData points to (the
variant array data), to the location in memory that
PData points to (the integer array). }
Move(PVData^, PData^, NumBytes);
finally
VarArrayUnlock(VData);
end; // try
end;

procedure LoadVariantArray(PData: Pointer;
NumBytes: Integer; var VData: OleVariant);
var
PVData: PByteArray;
begin
{ Create the variant array of bytes. Set the upper bound
to the size of the array, minus one, because the array
is zero-based. }
VData := VarArrayCreate([0, NumBytes - 1], varByte);
{ Lock the variant array for faster access. Then copy the
array to the variant array, and unlock the variant
array. }
PVData := VarArrayLock(Vdata);
try
{ Move the bytes at the location in memory that PData
points to into the location in memory that PVData
points to. PData points to the integer array and
PVData points to the variant array of bytes. }
Move(PData^, PVData^, NumBytes);
finally
VarArrayUnlock(VData);
end; // try
end ;
procedure ComponentToVariant(const Component:TComponent;out vData:OleVariant);
var
CompBuffer:TByteArray;
pCompBuffer:pointer;
begin
with TMemoryStream.Create do
try
WriteComponent(Component);
Seek(0, soFromBeginning);
ReadBuffer(CompBuffer,Size);
LoadVariantArray(@CompBuffer,Size,vData);
finally
free;
end;
end;
procedure VariantToComponent(out Component:TComponent; vData:OleVariant);
var
CompBuffer:TByteArray;
pCompBuffer:pointer;
begin
with TMemoryStream.Create do
try
UnLoadVariantArray(vData,@CompBuffer,VarArrayHighBound(vData,1)+1);
WriteBuffer(CompBuffer,VarArrayHighBound(vData,1)+1);
Seek(0, soFromBeginning);
Component:=ReadComponent(nil);
//-the Component is AutoCreated
finally
free;
end;
end;

end.
 
把OleVariant 转成流
var
ms: TStream; p: Pointer;
begin
ms := TMemoryStream.Create;
ms.Position := 0;
p := VarArrayLock(UserPhoto);
ms.Write(p^, VarArrayHighBound(UserPhoto, 1)); //這句可否改進?
VarArrayUnlock(UserPhoto);
ms.Position := 0;
MainFrm.ImageEx1.Picture.LoadFromStream(ms);
ms.Free;

把流转成OleVariant
function TfrmLogin.GetOleVariant(FileName : String): OleVariant;
var
AStream: TStream;
MyBuffer: Pointer;
begin
try
AStream := TFileStream.Create(FileName, fmOpenRead);
Result := VarArrayCreate([0, AStream.Size - 1], varByte);
MyBuffer := VarArrayLock(Result);
AStream.ReadBuffer(MyBuffer^, AStream.Size);
VarArrayUnlock(Result);
finally
//AStream.Free;
end;
end;

 
TO:张鸿林
我是新手,能不能给你QQ或MSN之类的,如果可以请Email到raisingrain@hotmail.com
 
如果你一定要使用接口,看看这里我的相关回答
http://delphibbs.com/delphibbs/dispq.asp?lid=2956362
看了你的其他相关贴子,水平并不低,才有上面的言论。
by the way,不好意思,没有任何现在通讯手段。以前有个bb机,装上电池后不知
能不能用^-^ 号码是什么来着?有点想不起来了
 
to 张鸿林
多谢,现在才想起来撒分,不好意思,手头有一个大项目要做,但没有经验,想外包,不知你有没有兴趣?如有兴趣请发Email:rtcli@yahoo.com.cn
 
后退
顶部