新手的问题,急

时间:2022-09-13 20:13:28
程序运行时可以输入几个参数,当程序第二次运行的时候怎么样把这几个参数在原来的地方显示出来?

7 个解决方案

#1


存到ini文件之中

#2


具体怎么做能讲的更详细吗?

#3


最好能给我代码。

#4


可以把这几个参数写在注册表中

#5


记录在文件中!格式随便!

#6


//就这么写,有问题delphiteam@eyou.com
unit FrmMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, ADODB,INIFiles, StdCtrls, Grids, DBGrids, DBCtrls, ComCtrls, ExtCtrls;

type
  TMainForm = class(TForm)
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    StatusBar1: TStatusBar;
    PrintDialog1: TPrintDialog;
    Button2: TButton;
    Panel1: TPanel;
    Label2: TLabel;
    frompicker: TDateTimePicker;
    Label3: TLabel;
    topicker: TDateTimePicker;
    WhereCombo: TDBComboBox;
    Label1: TLabel;
    SubmitBt: TButton;
    ClearBt: TButton;
    Button1: TButton;
    Label4: TLabel;
    Button3: TButton;
    procedure FormShow(Sender: TObject);
    procedure SubmitBtClick(Sender: TObject);
    procedure ClearBtClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    sConn:String;
    {Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

uses FrmSaleDetailRt, FrmSaleSum, FrmCardComplex;

{$R *.DFM}

procedure TMainForm.FormShow(Sender: TObject);
var
  connini:TINIFile;
  LocalDir:String;
  sServer:String;
  sBaseName:String;
  sUserID:String;
  sPassword:String;

begin
  GetDir(0,LocalDir);
  //打开初始化文件,取得连接串参数
  connini:=TINIFile.Create(LocalDir+'\shitangconn.ini');
  sServer:=connini.ReadString('LogConn','ServerName','Error');
  sBaseName:=connini.ReadString('LogConn','BaseName','Error');
  sUserID:=connini.ReadString('LogConn','UserID','Error');
  sPassword:=connini.ReadString('LogConn','Password','Error');
  sConn:='Provider=SQLOLEDB.1;Persist Security Info=False;'+'User ID='+sUserID+';Password='+sPassword+';Initial Catalog='+sBasename+';Data Source='+sServer+';';
  //连接串拼接完毕
  ADOConnection1.Close;
  ADOConnection1.ConnectionString:=sConn;
  ADOConnection1.Open;
  //使用查询取得部门名称,放入下拉列表中
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('SELECT distinct usewhere from paidrecord');
  ADOQuery1.Open;
  while not ADOQuery1.Eof do
    begin
    WhereCombo.Items.Add(ADOQuery1.FieldByName('usewhere').AsString);
    ADOQuery1.Next;
    end;
  //查询断开
  ADOQuery1.DisableControls;
  ADOQuery1.Close;
  DBGrid1.Enabled:=false;
  //日期控件初始值设置为当前时间
  Topicker.DateTime:=now;
  Frompicker.DateTime:=now;
end;

procedure TMainForm.SubmitBtClick(Sender: TObject);
begin
   ADOQuery1.EnableControls;
   if WhereCombo.Text='' then
     begin
       MessageDlg('请输入部门名称!',mtError,[mbYes],0);
     end;
   ADOQuery1.Close;
   ADOQuery1.SQL.Clear;
   ADOQuery1.SQL.Add('SELECT * From paidrecord');
   ADOQuery1.SQL.Add('WHERE usewhere=:paidwhere');
   ADOQuery1.SQL.Add('and usedate<:todate and usedate>:fromdate');
   ADOQuery1.Parameters.ParamValues['paidwhere']:=WhereCombo.Text;
   ADOQuery1.Parameters.ParamValues['todate']:=FormatDateTime('YYYY-M-D',topicker.date);
   ADOQuery1.Parameters.ParamValues['fromdate']:=FormatDateTime('YYYY-M-D',frompicker.date);
   ADOQuery1.Open;
   StatusBar1.Panels[0].Text:='共找到'+IntToStr(ADOQuery1.RecordCount)+'条记录';
   DBGrid1.Enabled:=true;
   SubmitBt.Enabled:=false;
   ClearBt.Enabled:=true;
   button1.Enabled:=true;
end;

procedure TMainForm.ClearBtClick(Sender: TObject);
begin
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  StatusBar1.Panels[0].Text:='请输入查询条件';
  SubmitBt.Enabled:=true;
  ClearBt.Enabled:=false;
  button1.Enabled:=false;
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
  FrmSaleDetailQR.QuickRep1.Preview;
  
end;

procedure TMainForm.Button2Click(Sender: TObject);
begin
  SaleSumForm.Show;
end;

procedure TMainForm.Button3Click(Sender: TObject);
begin
  CardComplex.Show;
end;

end.

#7


//这里是最关键的
uses INIFiles;
procedure TMainForm.FormShow(Sender: TObject);
var
  connini:TINIFile;
  LocalDir:String;
  sServer:String;
  sBaseName:String;
  sUserID:String;
  sPassword:String;

begin
  GetDir(0,LocalDir);
  //打开初始化文件,取得连接串参数
  connini:=TINIFile.Create(LocalDir+'\shitangconn.ini');
  sServer:=connini.ReadString('LogConn','ServerName','Error');
  sBaseName:=connini.ReadString('LogConn','BaseName','Error');
  sUserID:=connini.ReadString('LogConn','UserID','Error');
  sPassword:=connini.ReadString('LogConn','Password','Error');
  sConn:='Provider=SQLOLEDB.1;Persist Security Info=False;'+'User ID='+sUserID+';Password='+sPassword+';Initial Catalog='+sBasename+';Data Source='+sServer+';';
  //连接串拼接完毕
  ADOConnection1.Close;
  ADOConnection1.ConnectionString:=sConn;
  ADOConnection1.Open;
  //使用查询取得部门名称,放入下拉列表中
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('SELECT distinct usewhere from paidrecord');
  ADOQuery1.Open;
  while not ADOQuery1.Eof do
    begin
    WhereCombo.Items.Add(ADOQuery1.FieldByName('usewhere').AsString);
    ADOQuery1.Next;
    end;
  //查询断开
  ADOQuery1.DisableControls;
  ADOQuery1.Close;
  DBGrid1.Enabled:=false;
  //日期控件初始值设置为当前时间
  Topicker.DateTime:=now;
  Frompicker.DateTime:=now;
end;

#1


存到ini文件之中

#2


具体怎么做能讲的更详细吗?

#3


最好能给我代码。

#4


可以把这几个参数写在注册表中

#5


记录在文件中!格式随便!

#6


//就这么写,有问题delphiteam@eyou.com
unit FrmMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, ADODB,INIFiles, StdCtrls, Grids, DBGrids, DBCtrls, ComCtrls, ExtCtrls;

type
  TMainForm = class(TForm)
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    StatusBar1: TStatusBar;
    PrintDialog1: TPrintDialog;
    Button2: TButton;
    Panel1: TPanel;
    Label2: TLabel;
    frompicker: TDateTimePicker;
    Label3: TLabel;
    topicker: TDateTimePicker;
    WhereCombo: TDBComboBox;
    Label1: TLabel;
    SubmitBt: TButton;
    ClearBt: TButton;
    Button1: TButton;
    Label4: TLabel;
    Button3: TButton;
    procedure FormShow(Sender: TObject);
    procedure SubmitBtClick(Sender: TObject);
    procedure ClearBtClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    sConn:String;
    {Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

uses FrmSaleDetailRt, FrmSaleSum, FrmCardComplex;

{$R *.DFM}

procedure TMainForm.FormShow(Sender: TObject);
var
  connini:TINIFile;
  LocalDir:String;
  sServer:String;
  sBaseName:String;
  sUserID:String;
  sPassword:String;

begin
  GetDir(0,LocalDir);
  //打开初始化文件,取得连接串参数
  connini:=TINIFile.Create(LocalDir+'\shitangconn.ini');
  sServer:=connini.ReadString('LogConn','ServerName','Error');
  sBaseName:=connini.ReadString('LogConn','BaseName','Error');
  sUserID:=connini.ReadString('LogConn','UserID','Error');
  sPassword:=connini.ReadString('LogConn','Password','Error');
  sConn:='Provider=SQLOLEDB.1;Persist Security Info=False;'+'User ID='+sUserID+';Password='+sPassword+';Initial Catalog='+sBasename+';Data Source='+sServer+';';
  //连接串拼接完毕
  ADOConnection1.Close;
  ADOConnection1.ConnectionString:=sConn;
  ADOConnection1.Open;
  //使用查询取得部门名称,放入下拉列表中
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('SELECT distinct usewhere from paidrecord');
  ADOQuery1.Open;
  while not ADOQuery1.Eof do
    begin
    WhereCombo.Items.Add(ADOQuery1.FieldByName('usewhere').AsString);
    ADOQuery1.Next;
    end;
  //查询断开
  ADOQuery1.DisableControls;
  ADOQuery1.Close;
  DBGrid1.Enabled:=false;
  //日期控件初始值设置为当前时间
  Topicker.DateTime:=now;
  Frompicker.DateTime:=now;
end;

procedure TMainForm.SubmitBtClick(Sender: TObject);
begin
   ADOQuery1.EnableControls;
   if WhereCombo.Text='' then
     begin
       MessageDlg('请输入部门名称!',mtError,[mbYes],0);
     end;
   ADOQuery1.Close;
   ADOQuery1.SQL.Clear;
   ADOQuery1.SQL.Add('SELECT * From paidrecord');
   ADOQuery1.SQL.Add('WHERE usewhere=:paidwhere');
   ADOQuery1.SQL.Add('and usedate<:todate and usedate>:fromdate');
   ADOQuery1.Parameters.ParamValues['paidwhere']:=WhereCombo.Text;
   ADOQuery1.Parameters.ParamValues['todate']:=FormatDateTime('YYYY-M-D',topicker.date);
   ADOQuery1.Parameters.ParamValues['fromdate']:=FormatDateTime('YYYY-M-D',frompicker.date);
   ADOQuery1.Open;
   StatusBar1.Panels[0].Text:='共找到'+IntToStr(ADOQuery1.RecordCount)+'条记录';
   DBGrid1.Enabled:=true;
   SubmitBt.Enabled:=false;
   ClearBt.Enabled:=true;
   button1.Enabled:=true;
end;

procedure TMainForm.ClearBtClick(Sender: TObject);
begin
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  StatusBar1.Panels[0].Text:='请输入查询条件';
  SubmitBt.Enabled:=true;
  ClearBt.Enabled:=false;
  button1.Enabled:=false;
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
  FrmSaleDetailQR.QuickRep1.Preview;
  
end;

procedure TMainForm.Button2Click(Sender: TObject);
begin
  SaleSumForm.Show;
end;

procedure TMainForm.Button3Click(Sender: TObject);
begin
  CardComplex.Show;
end;

end.

#7


//这里是最关键的
uses INIFiles;
procedure TMainForm.FormShow(Sender: TObject);
var
  connini:TINIFile;
  LocalDir:String;
  sServer:String;
  sBaseName:String;
  sUserID:String;
  sPassword:String;

begin
  GetDir(0,LocalDir);
  //打开初始化文件,取得连接串参数
  connini:=TINIFile.Create(LocalDir+'\shitangconn.ini');
  sServer:=connini.ReadString('LogConn','ServerName','Error');
  sBaseName:=connini.ReadString('LogConn','BaseName','Error');
  sUserID:=connini.ReadString('LogConn','UserID','Error');
  sPassword:=connini.ReadString('LogConn','Password','Error');
  sConn:='Provider=SQLOLEDB.1;Persist Security Info=False;'+'User ID='+sUserID+';Password='+sPassword+';Initial Catalog='+sBasename+';Data Source='+sServer+';';
  //连接串拼接完毕
  ADOConnection1.Close;
  ADOConnection1.ConnectionString:=sConn;
  ADOConnection1.Open;
  //使用查询取得部门名称,放入下拉列表中
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('SELECT distinct usewhere from paidrecord');
  ADOQuery1.Open;
  while not ADOQuery1.Eof do
    begin
    WhereCombo.Items.Add(ADOQuery1.FieldByName('usewhere').AsString);
    ADOQuery1.Next;
    end;
  //查询断开
  ADOQuery1.DisableControls;
  ADOQuery1.Close;
  DBGrid1.Enabled:=false;
  //日期控件初始值设置为当前时间
  Topicker.DateTime:=now;
  Frompicker.DateTime:=now;
end;