先在ODBC 中设数据源,安装过SQL Server7.0 后,ODBC中有一项"系统DSN"应该有两项 数据源,一个是MQIS,一个是LocalSever,任选一个选后点击配置按钮,不知你的SQL7.0 是不是安装在本地机器上,如果是的话直接进行下一步,如果不是,在服务器一栏中填上 Server,然后进行下一步,填写登录ID 和密码(登录ID,和密码是在SQL7.0中的用户选项 中设的)。 第二步,配置BDE: 打开Delphi的BDE,然后点击MQIS 或 LocalServer,就会提示用户名和密码,这和 ODBC的用户名和密码是一样的,填上就行了。 第三步,配置程序: 如果用的是TTable,就在TTable的DatabaseName中选择MQIS 或LocalServer,然后在 TableName中选择Sale就行了,然后将Active改为True,Delphi弹出提示对话,填入用户 名和密码。 如果用的是TQuery,在TQuery上点击右键,再击"SQL Builder",这是以界面方式配置 SQL语句,或者在TQuery的SQL中填入SQL语句。最后,别忘了将Active改为True。 在运行也可能配置TQuery,具体见Delphi帮助。 □◇[DELPHI]得到图像上某一点的RGB值 procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var red,green,blue:byte ; i:integer; begin i:= image1.Canvas.Pixels[x,y]; Blue:= GetBValue(i); Green:= GetGValue(i): Red:= GetRValue(i); Label1.Caption:=inttostr(Red); Label2.Caption:=inttostr(Green); Label3.Caption:=inttostr(Blue); end; □◇[DELPHI]关于日期格式分解转换 var year,month,day:word;now2:Tdatatime; now2:=date(); decodedate(now2,year,month,day); lable1.Text :=inttostr(year)+''''年''''+inttostr(month)+''''月''''+inttostr(day)+''''日''''; ◇[DELPHI]如何判断当前网络连接方式 判断结果是MODEM、局域网或是代理服务器方式。 uses wininet; Function ConnectionKind :boolean; var flags: dword; begin Result := InternetGetConnectedState(@flags, 0); if Result then begin if (flags and INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM then begin showmessage(''''Modem''''); end; if (flags and INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN then begin showmessage(''''LAN''''); end; if (flags and INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY then begin showmessage(''''Proxy''''); end; if (flags and INTERNET_CONNECTION_MODEM_BUSY)=INTERNET_CONNECTION_MODEM_BUSY then begin showmessage(''''Modem Busy''''); end; end; end; ◇[DELPHI]如何判断字符串是否是有效EMAIL地址 function IsEMail(EMail: String): Boolean; var s: String;ETpos: Integer; begin ETpos:= pos(''''@'''', EMail); if ETpos > 1 then begin s:= copy(EMail,ETpos+1,Length(EMail)); if (pos(''''.'''', s) > 1) and (pos(''''.'''', s) < length(s)) then Result:= true else Result:= false; end else Result:= false; end; ◇[DELPHI]判断系统是否连接INTERNET 需要引入URL.DLL中的InetIsOffline函数。 函数申明为: function InetIsOffline(Flag: Integer): Boolean; stdcall; external ''''URL.DLL''''; 然后就可以调用函数判断系统是否连接到INTERNET if InetIsOffline(0) then ShowMessage(''''not connected!'''') else ShowMessage(''''connected!''''); 该函数返回TRUE如果本地系统没有连接到INTERNET。 附: 大多数装有IE或OFFICE97的系统都有此DLL可供调用。 InetIsOffline BOOL InetIsOffline( DWORD dwFlags, ); ◇[DELPHI]简单地播放和暂停WAV文件 uses mmsystem; function PlayWav(const FileName: string): Boolean; begin Result := PlaySound(PChar(FileName), 0, SND_ASYNC); end; procedure StopWav; var buffer: array[0..2] of char; begin buffer[0] := #0; PlaySound(Buffer, 0, SND_PURGE); end; ◇[DELPHI]取机器BIOS信息 with Memo1.Lines do begin Add(''''MainBoardBiosName:''''+^I+string(Pchar(Ptr($FE061)))); Add(''''MainBoardBiosCopyRight:''''+^I+string(Pchar(Ptr($FE091)))); Add(''''MainBoardBiosDate:''''+^I+string(Pchar(Ptr($FFFF5)))); Add(''''MainBoardBiosSerialNo:''''+^I+string(Pchar(Ptr($FEC71)))); end; ◇[DELPHI]网络下载文件 uses UrlMon; function DownloadFile(Source, Dest: string): Boolean; begin try Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0; except Result := False; end; end; if DownloadFile(''''http://www.borland.com/delphi6.zip, ''''c:\kylix.zip'''') then ShowMessage(''''Download succesful'''') else ShowMessage(''''Download unsuccesful'''') ◇[DELPHI]解析服务器IP地址 uses winsock function IPAddrToName(IPAddr : String): String; var SockAddrIn: TSockAddrIn; HostEnt: PHostEnt; WSAData: TWSAData; begin WSAStartup($101, WSAData); SockAddrIn.sin_addr.s_addr:= inet_addr(PChar(IPAddr)); HostEnt:= gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET); if HostEnt<>nil then result:=StrPas(Hostent^.h_name) else result:=''''''''; end; ◇[DELPHI]取得快捷方式中的连接 function ExeFromLink(const linkname: string): string; var FDir, FName, ExeName: PChar; z: integer; begin ExeName:= StrAlloc(MAX_PATH); FName:= StrAlloc(MAX_PATH); FDir:= StrAlloc(MAX_PATH); StrPCopy(FName, ExtractFileName(linkname)); StrPCopy(FDir, ExtractFilePath(linkname)); z:= FindExecutable(FName, FDir, ExeName); if z > 32 then Result:= StrPas(ExeName) else Result:= ''''''''; StrDispose(FDir); StrDispose(FName); StrDispose(ExeName); end; ◇[DELPHI]控制TCombobox的自动完成 {''''Sorted'''' property of the TCombobox to true } var lastKey: Word; //全局变量 //TCombobox的OnChange事件 procedure TForm1.AutoCompleteChange(Sender: TObject); var SearchStr: string; retVal: integer; begin SearchStr := (Sender as TCombobox).Text; if lastKey <> VK_BACK then // backspace: VK_BACK or $08 begin retVal := (Sender as TCombobox).Perform(CB_FINDSTRING, -1, LongInt(PChar(SearchStr))); if retVal > CB_Err then begin (Sender as TCombobox).ItemIndex := retVal; (Sender as TCombobox).SelStart := Length(SearchStr); (Sender as TCombobox).SelLength := (Length((Sender as TCombobox).Text) - Length(SearchStr)); end; // retVal > CB_Err end; // lastKey <> VK_BACK lastKey := 0; // reset lastKey end; //TCombobox的OnKeyDown事件 procedure TForm1.AutoCompleteKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin lastKey := Key; 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]如何计算一个目录的大小 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]安装程序如何添加到Uninstall列表 操作注册表,如下: 1.在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall键下建立一个主键,名称任意。 例HKEY_LOCAL_MACHINE\SOFTWAR