RICHEDIT保存成文件的扩展名的问题?

jjaacc 2002-10-05 04:52:34
我把扩展名设置成只有TXT和RTF,要是在保存时直接写入文件名,没写扩展名就保存成没有扩展名的文件了,如果知道现在用户想要保存的是TXT还是RTF?
...全文
37 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoxiaobai 2002-10-05
  • 打赏
  • 举报
回复
改一下

procedure TForm1.Button1Click(Sender: TObject);
var
fname : String;
begin
if SaveDialog1.Execute then
begin

if ExtractFileExt(SaveDialog1.FileName)<>'' then
fname := SaveDialog1.FileName
else
case SaveDialog1.FilterIndex of
1: fname := SaveDialog1.FileName + '.rtf';
2: fname := SaveDialog1.FileName + '.txt';
end;

// 加入对 fname 的处理
end;

end
xiaoxiaobai 2002-10-05
  • 打赏
  • 举报
回复
Form 的内容
==================================================================
object Form1: TForm1
Left = -2
Top = 103
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object RichEdit1: TRichEdit
Left = 80
Top = 72
Width = 105
Height = 137
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Lines.Strings = (
'RichEdit1')
ParentFont = False
TabOrder = 0
end
object Button1: TButton
Left = 320
Top = 160
Width = 81
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object SaveDialog1: TSaveDialog
Filter = 'RTF(*.rtf)|*.rtf|TXT(*.txt)|*.txt'
Left = 328
Top = 80
end
end


代码
===================================================================
unit Unit1;

interface

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

type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
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);
var
fname : String;
begin
if SaveDialog1.Execute then
begin
case SaveDialog1.FilterIndex of
1: fname := SaveDialog1.FileName + '.rtf';
2: fname := SaveDialog1.FileName + '.txt';
end;
// 加入对 fname 的处理
end;

end;

end.

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧