我用openpictureDialog 打开一幅图片后.(图片不在工程根目录).当再数据库连接时就会出错---path not found 或 invalid directory
我用的是paradox数据库

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DB, DBTables, Grids, DBGrids, ExtDlgs, ExtCtrls, StdCtrls,
      Buttons;type
      TForm1 = class(TForm)
        Image1: TImage;
        OpenPictureDialog1: TOpenPictureDialog;
        Query1: TQuery;
        BitBtn1: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
        procedure Image1Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
    query1.DatabaseName:='data\';
    query1.Close;
    query1.SQL.Clear;
    query1.SQL.Add('select * from reader');
    query1.Open;end;
    procedure TForm1.Image1Click(Sender: TObject);
    begin
    if openpicturedialog1.Execute then
    image1.Picture.LoadFromFile(openpicturedialog1.FileName);
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
    Action:=caFree;
    end;end.
      

  2.   

    query1.DatabaseName:='data\';
    应该直接使用绝对路径,或者取得应用程序路径加上相对路径后使用。因为你的openpicturedialog已经把当前路径给修改成你选择的路径了,所以打开adoquery的时候会报路径不对的错误
      

  3.   

    因为使用了openpicturedialog,整个工程的数据库连接都会出错.有什么办法不用修改数据库连接路径.