求教:如何让FileListBox1显示的文件不带扩展名?(60分)

  • 主题发起人 主题发起人 ric
  • 开始时间 开始时间
R

ric

Unregistered / Unconfirmed
GUEST, unregistred user!
求教:如何让FileListBox1显示的文件不带扩展名?

我曾尝试用删除字符串的方法,语句如下:

〔假定FileListBox1的显示的内容为sdfd.txt、dhjk.txt、sjdj.txt〕

procedure TForm1.FileListBox1Change(Sender: TObject);

var
s:string;
i,z:integer;
begin
for i := 0 to FileListBox1.Items.Count - 1 do
s:=FileListBox1.Items;
z:=pos('.txt',s); //得到.txt的位置
delete(s,z,4); //删除.txt
FileListBox1.Refresh;
end;

结果是没任何变化,初学Delphi,请高手赐教,
我只有200多分,想多问几个问题,别怪我给分太少。
 
试一试这个控件吧。

unit JFileList;

interface

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

type
TJFileList = class(TFileListBox)
private
{ Private declarations }
protected
{ Protected declarations }
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
public
{ Public declarations }
published
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Test', [TJFileList]);
end;

procedure TJFileList.DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState);
var
Bitmap: TBitmap;
offset: Integer;
begin
with Canvas do
begin
FillRect(Rect);
offset := 2;
if ShowGlyphs then
begin
Bitmap := TBitmap(Items.Objects[Index]);
if Assigned(Bitmap) then
begin
BrushCopy(Bounds(Rect.Left + 2,
(Rect.Top + Rect.Bottom - Bitmap.Height) div 2,
Bitmap.Width, Bitmap.Height),
Bitmap, Bounds(0, 0, Bitmap.Width, Bitmap.Height),
Bitmap.Canvas.Pixels[0, Bitmap.Height - 1]);
offset := Bitmap.width + 6;
end;
end;
TextOut(Rect.Left + offset, Rect.Top,
ChangeFileExt(Items[Index], ''))
end;
end;

end.
 
哈哈,ric 真可爱
 
用ChangeFileExt函数

var
s:string;
i:integer;
begin
for i := 0 to FileListBox1.Items.Count - 1 do
begin
s:=FileListBox1.Items;
FileListBox1.Items := ChangeFileExt(FileListBox1.Items, '');
end;

别忘了给分。。:-)
 
接受答案了.
 
后退
顶部