====================================
File-management routines 档案管理常式
====================================
--------------------------------------------------------
ChangeFileExt 变更档案的副档名
--------------------------------------------------------
Unit SysUtils
函数原型 function ChangeFileExt(const FileName, Extension: string):
string;
范例 procedure TForm1.Button1Click(Sender: TObject);
var
S: String;
P1:String;
P2:String;
begin
P1:='abc.txt';
P2:='.ini';
S := ChangeFileExt(P1,P2);
Label1.Caption:=S;
end;
结果 S== 'abc.ini'
P1:='abc'
P2:='.ini'
S== 'abc.ini'
P1:='c:\windows\abc.txt'
P2:='.ini'
S=='c:\windows\abc.ini'
P1:='abc.txt'
P2:='ini'
S=='abcini'
**注意:P2的第一位元必须有一点'.ini'
范例
procedure TForm1.ConvertIcon2BitmapClick(Sender: TObject);
var
s : string;
Icon: TIcon;
begin
OpenDialog1.DefaultExt := '.ICO';
OpenDialog1.Filter := 'icons (*.ico)|*.ICO';
OpenDialog1.Options := [ofOverwritePrompt, ofFileMustExist, ofHideReadOnly ];
if OpenDialog1.Execute then
begin
Icon := TIcon.Create;
try
Icon.Loadfromfile(OpenDialog1.FileName);
s:= ChangeFileExt(OpenDialog1.FileName,'.BMP');
Image1.Width := Icon.Width;
Image1.Height := Icon.Height;
Image1.Canvas.Draw(0,0,Icon);
Image1.Picture.SaveToFile(s);
ShowMessage(OpenDialog1.FileName + ' Saved to ' + s);
finally
Icon.Free;
end;
end;
end;
# SaveToFile, Create, Height, Width, Canvas, ChangeFileExt example
File-management routines 档案管理常式
====================================
--------------------------------------------------------
ChangeFileExt 变更档案的副档名
--------------------------------------------------------
Unit SysUtils
函数原型 function ChangeFileExt(const FileName, Extension: string):
string;
范例 procedure TForm1.Button1Click(Sender: TObject);
var
S: String;
P1:String;
P2:String;
begin
P1:='abc.txt';
P2:='.ini';
S := ChangeFileExt(P1,P2);
Label1.Caption:=S;
end;
结果 S== 'abc.ini'
P1:='abc'
P2:='.ini'
S== 'abc.ini'
P1:='c:\windows\abc.txt'
P2:='.ini'
S=='c:\windows\abc.ini'
P1:='abc.txt'
P2:='ini'
S=='abcini'
**注意:P2的第一位元必须有一点'.ini'
范例
procedure TForm1.ConvertIcon2BitmapClick(Sender: TObject);
var
s : string;
Icon: TIcon;
begin
OpenDialog1.DefaultExt := '.ICO';
OpenDialog1.Filter := 'icons (*.ico)|*.ICO';
OpenDialog1.Options := [ofOverwritePrompt, ofFileMustExist, ofHideReadOnly ];
if OpenDialog1.Execute then
begin
Icon := TIcon.Create;
try
Icon.Loadfromfile(OpenDialog1.FileName);
s:= ChangeFileExt(OpenDialog1.FileName,'.BMP');
Image1.Width := Icon.Width;
Image1.Height := Icon.Height;
Image1.Canvas.Draw(0,0,Icon);
Image1.Picture.SaveToFile(s);
ShowMessage(OpenDialog1.FileName + ' Saved to ' + s);
finally
Icon.Free;
end;
end;
end;
# SaveToFile, Create, Height, Width, Canvas, ChangeFileExt example
情人太累,小姐太贵,友谊交往最实惠 ,没事开开“同学会”,拆散一对算一对!