关于TDirectoryListBox与TFileListBox相连,但是当文件名较长时,TFileListBox不能显示其文件名!!
通过看VCL,发现TDirectoryListBox的Change里有一个TFileListBox类型的ReadFileNames函数,函数定义如下:procedure TFileListBox.ReadFileNames;
var
AttrIndex: TFileAttr;
I: Integer;
FileExt: string;
MaskPtr: PChar;
Ptr: PChar;
AttrWord: Word;
FileInfo: TSearchRec;
SaveCursor: TCursor;
Glyph: TBitmap;
const
Attributes: array[TFileAttr] of Word = (faReadOnly, faHidden, faSysFile,
faVolumeID, faDirectory, faArchive, 0);
begin
{ if no handle allocated yet, this call will force
one to be allocated incorrectly (i.e. at the wrong time.
In due time, one will be allocated appropriately. }
AttrWord := DDL_READWRITE;
if HandleAllocated then
begin
{ Set attribute flags based on values in FileType }
for AttrIndex := ftReadOnly to ftArchive do
if AttrIndex in FileType then
AttrWord := AttrWord or Attributes[AttrIndex]; ChDir(FDirectory); { go to the directory we want }
Clear; { clear the list } I := 0;
SaveCursor := Screen.Cursor;
try
MaskPtr := PChar(FMask);
while MaskPtr <> nil do
begin
Ptr := StrScan (MaskPtr, ';');
if Ptr <> nil then
Ptr^ := #0;
if FindFirst(MaskPtr, AttrWord, FileInfo) = 0 then
begin
repeat { exclude normal files if ftNormal not set }
if (ftNormal in FileType) or (FileInfo.Attr and AttrWord <> 0) then
if FileInfo.Attr and faDirectory <> 0 then
begin
I := Items.Add(Format('[%s]',[FileInfo.Name]));
if ShowGlyphs then
Items.Objects[I] := DirBMP;
end
else
begin
FileExt := AnsiLowerCase(ExtractFileExt(FileInfo.Name));
Glyph := UnknownBMP;
if (FileExt = '.exe') or (FileExt = '.com') or
(FileExt = '.bat') or (FileExt = '.pif') then
Glyph := ExeBMP;
I := Items.AddObject(FileInfo.Name, Glyph);
end;
if I = 100 then
Screen.Cursor := crHourGlass;
until FindNext(FileInfo) <> 0;
FindClose(FileInfo);
end;
if Ptr <> nil then
begin
Ptr^ := ';';
Inc (Ptr);
end;
MaskPtr := Ptr;
end;
finally
Screen.Cursor := SaveCursor;
end;
Change;
end;
end;
是FindFirst问题,做一测试函数,同样出现此问题,不知道大家以前有没有遇到此问题,该如何解决(有第三方控件也可,如果要换其他类型的控件需要改很多地方,急)!!!!
通过看VCL,发现TDirectoryListBox的Change里有一个TFileListBox类型的ReadFileNames函数,函数定义如下:procedure TFileListBox.ReadFileNames;
var
AttrIndex: TFileAttr;
I: Integer;
FileExt: string;
MaskPtr: PChar;
Ptr: PChar;
AttrWord: Word;
FileInfo: TSearchRec;
SaveCursor: TCursor;
Glyph: TBitmap;
const
Attributes: array[TFileAttr] of Word = (faReadOnly, faHidden, faSysFile,
faVolumeID, faDirectory, faArchive, 0);
begin
{ if no handle allocated yet, this call will force
one to be allocated incorrectly (i.e. at the wrong time.
In due time, one will be allocated appropriately. }
AttrWord := DDL_READWRITE;
if HandleAllocated then
begin
{ Set attribute flags based on values in FileType }
for AttrIndex := ftReadOnly to ftArchive do
if AttrIndex in FileType then
AttrWord := AttrWord or Attributes[AttrIndex]; ChDir(FDirectory); { go to the directory we want }
Clear; { clear the list } I := 0;
SaveCursor := Screen.Cursor;
try
MaskPtr := PChar(FMask);
while MaskPtr <> nil do
begin
Ptr := StrScan (MaskPtr, ';');
if Ptr <> nil then
Ptr^ := #0;
if FindFirst(MaskPtr, AttrWord, FileInfo) = 0 then
begin
repeat { exclude normal files if ftNormal not set }
if (ftNormal in FileType) or (FileInfo.Attr and AttrWord <> 0) then
if FileInfo.Attr and faDirectory <> 0 then
begin
I := Items.Add(Format('[%s]',[FileInfo.Name]));
if ShowGlyphs then
Items.Objects[I] := DirBMP;
end
else
begin
FileExt := AnsiLowerCase(ExtractFileExt(FileInfo.Name));
Glyph := UnknownBMP;
if (FileExt = '.exe') or (FileExt = '.com') or
(FileExt = '.bat') or (FileExt = '.pif') then
Glyph := ExeBMP;
I := Items.AddObject(FileInfo.Name, Glyph);
end;
if I = 100 then
Screen.Cursor := crHourGlass;
until FindNext(FileInfo) <> 0;
FindClose(FileInfo);
end;
if Ptr <> nil then
begin
Ptr^ := ';';
Inc (Ptr);
end;
MaskPtr := Ptr;
end;
finally
Screen.Cursor := SaveCursor;
end;
Change;
end;
end;
是FindFirst问题,做一测试函数,同样出现此问题,不知道大家以前有没有遇到此问题,该如何解决(有第三方控件也可,如果要换其他类型的控件需要改很多地方,急)!!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货