我需要用户能够从保存对话框中选择现有的只读文件。我认为您可以通过明智地选择TSaveDialog
选项来做到这一点,但我无法做到。如果我选择一个 R/O 文件,当我点击Save
按钮时,我会收到以下消息:
Read-only.txt
This file is set to read-only.
Try again with a different file name.
我想象选项位ofNoReadOnlyReturn
会控制这一点,但它似乎没有效果。
我错过了什么?
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
-
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
SaveDialog1: TSaveDialog;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
Windows.Beep (1000, 300) ;
end ;
end ;
end.
-
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 69
ClientWidth = 195
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 56
Top = 18
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object SaveDialog1: TSaveDialog
FileName = 'Read-only.txt'
InitialDir = 'C:\Users\Ross\Documents\RAD Studio\Projects'
Options = [ofHideReadOnly, ofNoReadOnlyReturn, ofEnableSizing]
Left = 16
Top = 16
end
end