◇[DELPHI]TNMUUProcessor的使用 var inStream,outStream:TFileStream; begin inStream:=TFileStream.create(infile.txt,fmOpenRead); outStream:=TFileStream(outfile.txt,fmCreate); NMUUE.Method:=uuCode;{UUEncode/Decode} //NMUUE.Method:=uuMIME;{MIME} NMUUE.InputStream:=InStream; NMUUE.OutputStream:=OutStream; NMUUE.Encode;{编码处理} //NMUUE.Decode;{解码处理} inStream.free; outStream.free; end;
◇[DELPHI]TFileStream的操作 //从文件流当前位置读count字节到缓冲区BUFFER function read(var buffer;count:longint):longint;override; //将缓冲区BUFFER读到文件流中 function write(const buffer;count:longint):longint;override; //设置文件流当前读写指针为OFFSET function seek(offset:longint;origin:word):longint;override; origin={soFromBeginning,soFromCurrent,soFromEnd} //从另一文件流中当前位置复制COUNT到当前文件流当前位置 function copyfrom(source:TStream;count:longint):longint; //读指定文件到文件流 var myFStream:TFileStream; begin myFStream:=TFileStream.create(OpenDialog1.filename,fmOpenRead); end;
[JavaScript]检测是否安装IE插件Shockwave&Quicktime <script LANGUAGE="JavaScript"> var myPlugin = navigator.plugins["Shockwave"]; if (myPlugin) document.writeln("你已经安装了 Shockwave!") else document.writeln("你尚未安装 Shockwave!") </script><br> <script LANGUAGE="JavaScript"> var myPlugin = navigator.plugins["Quicktime"]; if (myPlugin) document.writeln("你已经安装了Quicktime!") else document.writeln("你尚未安装 Quicktime!") </script>
◇[DELPHI]WebBrowser控件技巧 1。实现打印功能 var vaIn, vaOut: OleVariant; WebBrowser.ControlInterface.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, vaIn, vaOut); 2。WebBrowser从流中读取页面 function TForm1.LoadFromStream(const AStream: TStream): HRESULT; begin AStream.seek(0, 0); Result := (WebBrowser1.Document as IPersistStreamInit).Load(TStreamAdapter.Create(AStream)); end; 3。"about:" protocol will let you Navigate to an HTML string: procedure TForm1.LoadHTMLString(sHTML: String); var Flags, TargetFrameName, PostData, Headers: OleVariant; WebBrowser1.Navigate(''''about:'''' + sHTML, Flags, TargetFrameName, PostData, Headers) 4。"res:" protocol will let you Navigate to an HTML file stored as a resource. More informations is available from the Microsoft site: procedure TForm1.LoadHTMLResource; var Flags, TargetFrameName, PostData, Headers: OleVariant; WebBrowser1.Navigate(''''res://'''' + Application.ExeName + ''''/myhtml'''', Flags, TargetFrameName, PostData, Headers) 使用brcc32.exe建立资源文件 (*.rc) MYHTML 23 ".\html\myhtml.htm" MOREHTML 23 ".\html\morehtml.htm" {$R HTML.RES} //html.rc被编译成html.res 5。保存完整的HTML文件 var HTMLDocument: IHTMLDocument2; PersistFile: IPersistFile; begin HTMLDocument := WebBrowser1.Document as IHTMLDocument2; PersistFile := HTMLDocument as IPersistFile; PersistFile.Save(StringToOleStr(''''test.htm''''), True); while HTMLDocument.readyState <> ''''complete'''' do Application.ProcessMessages; end;
◇[DELPHI]安装WebBrowser控件(内嵌IE控件) 你必须先确定系统已安装Internet Explorer4或以后版本,DELPHI菜单--Component- - Import ActiveX Contro,列表中选择Microsoft Internet Controls"并ADD到一个已存在的包文件中,WebBrowser控件将显示在ActiveX控件面板。
◇[DELPHI]实现windows2000半透明窗体 function SetLayeredWindowAttributes(hwnd:HWND; crKey:Longint; bAlpha:byte; dwFlags:longint ):longint; stdcall; external user32;//函数声明 procedure TForm1.FormCreate(Sender: TObject); var l:longint; begin l:=getWindowLong(Handle, GWL_EXSTYLE); l := l Or $80000; SetWindowLong (handle, GWL_EXSTYLE, l); SetLayeredWindowAttributes(handle, 0, 180, 2); end;
◇[DELPHI]程序显示广告WebBrowser加载图片 var Flag, frame, pData, Header: OLEVariant; begin WebBrowser1.Navigate(''''http://www.chineseall.com/images/logo.jpg'''', flag, frame,pData, Header) end;
◇[DELPHI]计算一个目录的大小 function GetDirectorySize(const ADirectory: string): Integer; var Dir: TSearchRec; Ret: integer; Path: string; begin Result := 0; Path := ExtractFilePath(ADirectory); Ret := Sysutils.FindFirst(ADirectory, faAnyFile, Dir); if Ret <> NO_ERROR then exit; try while ret=NO_ERROR do begin inc(Result, Dir.Size); //如果是目录,且不是''''.''''或''''..''''则进行递归调用 if (Dir.Attr in [faDirectory]) and (Dir.Name[1] <> ''''.'''') then Inc(Result, GetDirectorySize(Path + Dir.Name + ''''\*.*'''')); Ret := Sysutils.FindNext(Dir); end; finally Sysutils.FindClose(Dir); end; end;
◇[DELPHI]清空一个目录 function EmptyDirectory(TheDirectory :String ; Recursive : Boolean) : Boolean; var SearchRec : TSearchRec; Res : Integer; begin Result := False; TheDirectory := NormalDir(TheDirectory); Res := FindFirst(TheDirectory + ''''*.*'''', faAnyFile, SearchRec); try while Res = 0 do begin if (SearchRec.Name <> ''''.'''') and (SearchRec.Name <> ''''..'''') then begin if ((SearchRec.Attr and faDirectory) > 0) and Recursive then begin EmptyDirectory(TheDirectory + SearchRec.Name, True); RemoveDirectory(PChar(TheDirectory + SearchRec.Name)); end else begin DeleteFile(PChar(TheDirectory + SearchRec.Name)) end; end; Res := FindNext(SearchRec); end; Result := True; finally FindClose(SearchRec.FindHandle); end; end;
◇[DELPHI]发布ADO程序之安装ADO 运行一次 MDac_typ.exe ,这个文件在微软的 Windows、IE、Office、Visual Studio 中都有。 安装程序所安装后的目录与程序中设置的目录路径一样,C:\Program Files\Common Files\System\ado文件夹中有没有ADO组件,装ACCESS2000就有ADO2.1,没有则安装MS OFfice2000,编译要去掉project->Option->Packages对话框中的Build With RunTime Library的勾。