zoukankan      html  css  js  c++  java
  • SQL Server连接界面的设计(文件操作实现)

    ExtractFilePath

    Returns the drive and directory portions of a file name.

    The resulting string is the leftmost characters of FileName, up to and including the colon or backslash that separates the path information from the name and extension. The resulting string is empty if FileName contains no drive and directory parts.

    This function works for multi-byte character systems (MBCS).

    ParamStr returns the parameter from the command line that corresponds to Index, or an empty string if Index is greater than ParamCount. For example, an Index value of 2 returns the second command-line parameter.

    Note:  On Windows, ParamStr(0) returns the path and file name of the executing program (for example, C:\TEST\MYPROG.EXE).
    Note:  On Linux and Macintosh, ParamStr(0) returns the command used to execute the program, without parameters (for example, ./myprogram). This behavior is dependent on information returned by the shell program and may not be consistent among all shells.

    Note:  Use double quotation marks to wrap multiple words as one parameter (such as long file names containing spaces).

    unit UnitDataBaseLink;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;

    type
    TfrmlinkSQL
    = class(TForm)
    edtPassword: TEdit;
    cbbName: TComboBox;
    cbbIP: TComboBox;
    lblName: TLabel;
    lblPassword: TLabel;
    lblIP: TLabel;
    btnSure: TButton;
    btnCancel: TButton;
    procedure btnSureClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }

    end;

    var
    frmlinkSQL: TfrmlinkSQL;

    implementation

    uses UnitDM, UnitLogin, IniFiles;

    {$R *.dfm}
    var
    filename:
    string;
    iniFile: TIniFile;
    S: TStrings;

    procedure TfrmlinkSQL.btnSureClick(Sender: TObject);
    var
    // result: Boolean;
    i: Integer;
    begin
    DM.ADOConnection1.Close;
    DM.ADOConnection1.ConnectionString :
    = 'Provider=SQLOLEDB.1;Password='
    + QuotedStr(edtPassword.Text) + ';Persist Security Info=True;User ID='
    + QuotedStr(cbbName.Text) + ';Initial Catalog=Depot;Data Source=' +
    QuotedStr(cbbIP.Text);
    try
    DM.ADOConnection1.Open;
    iniFile.WriteString(
    'User','UserName',cbbName.Text);
    iniFile.WriteString(
    'User','IP',cbbIP.Text);
    iniFile.Free;
    except
    Application.MessageBox(pchar(
    '连接出错'),'警告',MB_OK+MB_ICONWARNING);
    iniFile.Free;
    exit;
    end;
    with frmLogin.ADOQuery1 do
    begin
    close;
    sql.Clear;
    sql.Add(
    'select Username from Admin');
    open;
    end;
    for i:=1 to frmLogin.Adoquery1.RecordCount do
    begin
    frmLogin.cbbUserName.Items.Add(frmLogin.adoquery1.Fields[
    0].asstring);
    frmLogin.Adoquery1.Next;
    end;
    frmLogin.cbbUserName.ItemIndex:
    =0;
    Application.MessageBox(pchar(
    '连接成功'),'',MB_OK);


    end;



    procedure TfrmlinkSQL.btnCancelClick(Sender: TObject);
    begin
    frmlinkSQL.Close;
    end;

    procedure TfrmlinkSQL.FormCreate(Sender: TObject);
    var
    i: Integer;
    begin
    s :
    = TStringList.Create;
    Filename :
    = ExtractFilePath(ParamStr(0))+'data.ini';
    IniFile :
    = TIniFile.Create(Filename);
    try
    iniFile.ReadSectionValues(
    'User', s);
    for i := 0 to s.Count-1 do
    begin
    if s.Names[i]='UserName' then
    cbbName.Items.Add(s.Values[s.Names[i]])
    else
    cbbIP .Items.Add(s.Values[s.Names[
    1]]);
    end;
    cbbName.Text :
    = cbbName.Items[0];
    cbbIP.Text :
    = cbbIP.Items[0];
    finally
    s.Free;
    end;

    end;

    end.
  • 相关阅读:
    Eclipse 代码提示功能设置。
    eclipse android 查看源文件 出错的解决办法
    Android 中自定义控件和属性(attr.xml,declarestyleable,TypedArray)的方法和使用
    android屏幕尺寸 sp,px,dp,density,in介绍
    用C#实现的条形码和二维码编码解码器 之转载
    在Eclipse下如何导入jar安装包
    C# 获取往控件中拖进的文件或文件夹的信息(转)
    c#中Dictionary、ArrayList、Hashtable和数组的区别是什么?[转]
    C#中的枚举
    C#结构体特性
  • 原文地址:https://www.cnblogs.com/ljjphysics/p/2052304.html
Copyright © 2011-2022 走看看