我们公司以前用DCOM实现图片存取的,图片存在了个目录里面不是在数据库里面。<br> IPICCOM = interface(IAppServer)<br> ['{2C0AAA4A-9662-4031-B780-972B0A54C1AB}']<br> procedure comannd(const strCode: WideString; const strCommamd: WideString; out nflag: OleVariant); safecall;<br> procedure savetoserver(const bstrFileName: WideString; aVariant: OleVariant;<br> out nFlag: OleVariant); safecall;<br> procedure getpicture(const bstrFileName: WideString; out aVanriant: OleVariant;<br> out nflag: OleVariant); safecall;<br> procedure deletepicture(const picfilename: WideString; out nflag: OleVariant); safecall;<br> end;<br><br>。。。<br><br><br>unit Unit1;<br><br>interface<br>uses<br> windows,Messages,classes,jpeg,dcomjepg_TLB,syncobjs,Sysutils,Variants;<br><br>type<br> TPic = class<br> private<br> PicCOM : IPicCOM;<br> procedure VariantToStream (const v : olevariant; Stream : TMemoryStream);<br> procedure StreamToVariant (Stream : TMemoryStream; var v : OleVariant);<br> procedure JPEGToVariant(aJPEG : TJPEGImage; var aVariant:OleVariant);<br> procedure VariantToJPEG(aValue : OleVariant;var aJPEG:TJPEGImage);<br> private<br> <br> sr : TSearchRec;<br> strDir : string;<br> strname : String;<br> rpcDir : string;<br> JPEGImage : TJPEGImage;<br><br> public<br> remoteworkdir : string;<br> localworkdir : string;<br> picserver : string;<br> public<br> Constructor Create;<br> destructor Destroy; override;<br> function ConnectPicSever(serverAddr : string): boolean;<br> function PicToSever(LocalPicFileName : string;RemotePicFileName : string): boolean;<br> function GetPicFromServer(PicFileName : string;var aJPEG : TJPEGImage): boolean;<br> function DelPicFromServer(PicFileName : string): boolean;<br> function ExeCommand(scode : string;spara : string): boolean;<br> function StartFtp : boolean ;<br> end;<br><br>implementation<br><br>Constructor TPic.Create;<br>begin<br> JPEGImage := TJPEGImage.create;<br>end;<br><br>destructor TPic.Destroy;<br>begin<br> JPEGImage.Free;<br>end;<br>function TPic.StartFtp : boolean;<br><br>begin<br> strDir := localworkdir;<br> strname :='';<br> result := True;<br> if FindFirst (strDir + '/*.*', faAnyFile, sr) = 0 then<br> while(true) do<br> begin<br> if (sr.Name <> '.') and (sr.Name <> '..') then begin<br> if length(strname) <> 0 then deletefile(strname);<br> strname := strDir + '/' + sr.Name;<br> rpcDir := remoteworkdir + '/' +copy(sr.Name,1,8);<br> if not PicToSever(strname,rpcDir+'/'+sr.Name) then begin<br> strname := '';<br> result := false;<br> end;<br> Sleep(100);<br> end;<br> if findnext(sr) <> 0 then begin<br> if length(strname) <> 0 then deletefile(strname);<br> break;<br> end;<br> end;<br>end;<br><br>function TPic.ConnectPicSever(serverAddr : string): boolean;<br>begin<br> Result:= False;<br> try<br> PicCOM := CoNetComm.CreateRemote (serverAddr);<br> Result:= true;<br> except<br> end;<br> PicServer := serverAddr;<br>end;<br><br>function TPic.PicToSever(LocalPicFileName : string;RemotePicFileName : string): boolean;<br>var<br> bFlag : boolean;<br> aVariant : OleVariant;<br> JPEGImage : TJPEGImage;<br> aFlag : OleVariant;<br>begin<br> aFlag := 0;<br> JPEGImage := TJPEGImage.Create ;<br> try<br> bFlag := True;<br> JPEGImage.LoadFromFile(LocalPicFileName);<br> JPEGToVariant(JPEGImage,aVariant);<br> except<br> bFlag := false;<br> end;<br> if bFlag then<br> begin<br> try<br> PicCOM.savetoserver (pchar(RemotePicFileName),aVariant,aFlag);<br> except<br> try<br> PicCOM := CoNetComm.CreateRemote(PicServer);<br> except<br> end;<br> bFlag := false;<br> end;<br> end;<br> JPEGImage.free;<br> try<br> if aFlag = 1 then<br> Result := bFlag<br> else Result := false;<br> except<br> Result := false;<br> end;<br>end;<br>function TPic.GetPicFromServer(PicFileName : string;var aJPEG : TJPEGImage): boolean;<br>var<br> bFlag : boolean;<br> aVariant : OleVariant;<br> aFlag : OleVariant;<br>begin<br> aFlag := 0;<br> try<br> PicCOM.getpicture (pchar(PicFileName),aVariant,aFlag 
;<br> VariantToJPEG(aVariant,aJPEG);<br> bFlag := true;<br> except<br> try<br> PicCOM := CoNetComm.CreateRemote(PicServer);<br> except<br> end;<br> bFlag := false;<br> end;<br> try<br> if aFlag = 1 then<br> Result := bFlag<br> else Result := false;<br> except<br> Result := false;<br> end;<br>end;<br>function TPic.DelPicFromServer(PicFileName : string): boolean;<br>var<br> bFlag : boolean;<br> aFlag : OleVariant;<br>begin<br> aFlag := 0;<br> try<br> PicCOM.deletepicture (pchar(PicFileName),aFlag);<br> bFlag := true;<br> except<br> try<br> PicCOM := CoNetComm.CreateRemote(PicServer);<br> except<br> end;<br> bFlag := false;<br> end;<br> try<br> if aFlag = 1 then<br> Result := bFlag<br> else Result := false;<br> except<br> Result := false;<br> end;<br>end;<br>function TPic.ExeCommand(scode : string;spara : string): boolean;<br>var<br> bFlag : boolean;<br> aFlag : OleVariant;<br>begin<br> try<br> PicCOM.comannd (pchar(scode),pchar(spara 
,aFlag);<br> bFlag := true;<br> except<br> try<br> PicCOM := CoNetComm.CreateRemote(PicServer);<br> except<br> end;<br> bFlag := false;<br> end;<br> try<br> if aFlag = 1 then<br> Result := bFlag<br> else Result := false;<br> except<br> Result := false;<br> end;<br>end;<br>procedure TPic.VariantToStream (const v : olevariant; Stream : TMemoryStream);<br>var <br> p : pointer;<br>begin<br> Stream.Position := 0;<br> Stream.Size := VarArrayHighBound (v, 1) - VarArrayLowBound (v, 1) + 1;<br> p := VarArrayLock (v); <br> Stream.Write (p^, Stream.Size); <br> VarArrayUnlock (v); <br> Stream.Position := 0; <br>end; <br><br>procedure TPic.StreamToVariant (Stream : TMemoryStream; var v : OleVariant);<br>var <br> p : pointer; <br>begin <br> v := VarArrayCreate ([0, Stream.Size - 1], varByte); <br> p := VarArrayLock (v); <br> Stream.Position := 0; <br> Stream.Read (p^, Stream.Size); <br> VarArrayUnlock (v); <br>end; <br><br>procedure TPic.JPEGToVariant(aJPEG : TJPEGImage; var aVariant:OleVariant);<br>var <br> Stream : TMemoryStream; <br>begin <br> try <br> Stream := TMemoryStream.Create; <br> aJPEG.SaveToStream(Stream);<br> StreamToVariant(Stream, aVariant); <br> finally <br> Stream.Free; <br> end; <br>end; <br><br><br>procedure TPic.VariantToJPEG(aValue : OleVariant;var aJPEG:TJPEGImage);<br>var <br> Stream : TMemoryStream; <br>begin<br>try<br> Stream := TMemoryStream.Create;<br> VariantToStream (aValue,Stream);<br> aJPEG.LoadfromStream(Stream);<br><br>finally <br> Stream.free;<br>end;<br>end;<br><br>end.