unit SimpleFileView;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls;
type
TSimpleFileView = class(TCustomListView)
private
{ Private-Deklarationen }
fPath: String;
procedure SetPath(Path: String);
procedure ListDirectory(Dir: String);
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
constructor Create(aOwner: TComponent); override;
published
{ Published-Deklarationen }
property Path: String read fPath write SetPath;
property Align;
property BorderStyle;
property Color;
property Ctl3D;
property ColumnClick default False;
property Columns;
property Cursor;
property Dragmode;
property DragCursor;
property Enabled;
property Font;
property Height;
property HideSelection default False;
property Hint;
property IconOptions;
property Items;
property Left;
property MultiSelect default False;
property Name;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly default False;
property ShowColumnHeaders default True;
property ShowHint;
property TabOrder;
property TabStop;
property Tag;
property Top;
property ViewStyle default vsReport;
property Visible;
property Width;
property OnChange;
property OnChanging;
property OnClick;
property OnColumnClick;
property OnCompare;
property OnDblClick;
property OnDeletion;
property OnDragDrop;
property OnDragOver;
property OnEdited;
property OnEditing;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnInsert;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
{$IFDEF D3_OR_HIGHER}
property HotTrack;
property RowSelect default False;
{$ENDIF}
{$IFDEF D4_OR_HIGHER}
property Anchors;
property BiDiMode;
property Constraints;
property HotTrackStyles;
{$ENDIF}
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('CR-Soft', [TSimpleFileView]);
end;
constructor TSimpleFileView.Create(aOwner: TComponent);
var Column: TListColumn;
begin
inherited Create(aOwner);
ViewStyle := vsReport;
RowSelect := True;
ReadOnly := True;
Column := Columns.Add;
Column.Caption := 'Dateiname';
Column.Width := Width - 30;
IconOptions.WrapText := True;
ColumnClick := False;
If not (csDesigning in ComponentState) then
ListDirectory(fPath);
end;
procedure TSimpleFileView.ListDirectory(Dir: String);
var
Search: TSearchRec;
Item: TListItem;
begin
Items.Clear;
If Dir[Length(Dir)] <> '\' then Dir := Dir + '\';
if FindFirst(Dir + '*.*', faDirectory, Search) = 0 then
begin
repeat
If ((Search.Attr AND faDirectory) = faDirectory) AND (Search.Name <> '.') then
begin
Item := Items.Add;
// if fBrackets then
Item.Caption := '['+Search.Name+']'
// else
// Item.Caption := Search.Name;
end;
until FindNext(Search) <> 0;
FindClose(Search);
end;
if FindFirst(Dir + '*.*', $23, Search) = 0 then
begin
repeat
If (Search.Attr <> faDirectory) then
begin
Item := Items.Add;
Item.Caption := Search.Name
// Item.Caption := Copy(ExtractFileName(Search.Name), 1, Length(ExtractFileName(Search.Name)) - 4);
end;
until FindNext(Search) <> 0;
FindClose(Search);
end;
end;
procedure TSimpleFileView.SetPath(Path: String);
begin
if fPath <> Path then fPath := Path;
if not (csDesigning in ComponentState) then
ListDirectory(fPath);
end;
end.