打开图片不是用dlgOpenPic1空间吗,打开数据文件或者文本文件不是用OpenDialog1空间吗,我现在用了2个按钮来打开这两种不同的文件,程序分别如下:
打开图片的:
procedure TMainForm.OpenImageActionExecute(Sender: TObject);
begin
    if dlgOpenPic1.Execute then
    begin
      PicFileName := dlgOpenPic1.FileName;
      cht1.BackImage.LoadFromFile(PicFileName);
      stat1.Panels[0].Text := PicFileName;
    end;
end;
打开DAT文件的:
procedure TMainForm.Action1Execute(Sender: TObject);
var
  f:TextFile;
begin
  if OpenDialog1.Execute then
  Assignfile(f,OpenDialog1.FileName);
  Reset(f);
  try
    while not Eof(f) do
    begin
      Readln(f,Rx,Ry );
      PointsA.AddXY(Rx, Ry);
    end;
  finally
    closefile(f);
  end;
end;
现在我想把2个按钮合成一个按钮,可以吗,请问程序怎么编,dlgOpenPic1可以打开数据文件吗(dat),filter需要怎么设置?
谢谢!

解决方案 »

  1.   

     opendialog1.Filter:='dat文件(*.dat)|*.dat|bmp文件(*.bmp)|*.bmp';
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      str:string;
    begin
      opendialog1.Filter:='dat文件(*.dat)|*.dat|bmp文件(*.bmp)|*.bmp';
      opendialog1.Execute;
      str:=copy(opendialog1.FileName,length(opendialog1.FileName)-2,3);
      if str='dat' then
      begin
        ...
      end;
      if str='bmp' then
      begin
        ...
      end;
    end;
      

  3.   

    opendialog1.Filter:='dat文件(*.dat) ¦*.dat ¦bmp文件(*.bmp) ¦*.bmp';
      

  4.   

    谢谢你,我运行了以后只能打开BMP文件,但是找不到DAT文件啊,怎么回事呢?代码如下:
    procedure TMainForm.Action1Execute(Sender: TObject);var
      f:TextFile;
      str:string;
    begin
      opendialog1.Filter:='datÎļþ(*.dat) |*.dat |bmpÎļþ(*.bmp) |*.bmp';
      opendialog1.Execute;
      str:=copy(opendialog1.FileName,length(opendialog1.FileName)-2,3);
      if str='dat' then
      begin 
        //if OpenDialog1.Execute then
        Assignfile(f,OpenDialog1.FileName);
        Reset(f);
        try
          while not Eof(f) do
          begin
            Readln(f,Rx,Ry );
            PointsA.AddXY(Rx, Ry);
          end;
        finally
          closefile(f);
        end;
      end;
      if str='bmp' then
      begin
        //if opendialog1.Execute then
        begin
          PicFileName := opendialog1.FileName;
          cht1.BackImage.LoadFromFile(PicFileName);
          stat1.Panels[0].Text := PicFileName;
        end;
      end;
    end;
      

  5.   

    你好,我还想请教下面2句话是什么意思呢?
    opendialog1.Filter:='dat文件(*.dat) ¦*.dat ¦bmp文件(*.bmp) ¦*.bmp'; 
    str:=copy(opendialog1.FileName,length(opendialog1.FileName)-2,3); 
    我感觉是不是第二句出的毛病啊,这句话需要考虑什么路径吗?