Registriert seit: 3. Mär 2006
Ort: Waldbronn
4.303 Beiträge
Delphi 2009 Professional
|
Re: Probleme mit TStrings/TStringlist beim Freigeben
7. Sep 2006, 16:19
Hier ist die Unit:
Delphi-Quellcode:
type
TfrmOp = class(TForm)
{...}
private
{...}
Files : TStrings;
{...}
public
{...}
end;
var
frmOp : TfrmOp;
{...}
implementation
{$R *.dfm}
{...}
function TfrmOp.Execute : Boolean;
var i : Integer;
begin
{...}
try
// Show form
ShowModal;
if Files <> nil then
Files.Free;
Files := TStringList.Create;
// Return Files
if not Abort then begin
for i := FoundDirs.Count - 1 to DataView.Items.Count - 1 do begin
if DataView.Items[i].Selected then
Files.Add(FolderShellTreeView.Path + '\' + DataView.Items[i].Caption);
end;
end;
finally
{...}
end;
end;
function TfrmOp.GetFiles : TStrings;
begin
if Files <> nil then
Result := Files;
end;
procedure TfrmOp.FolderShellTreeViewChange(Sender: TObject;
Node: TTreeNode);
var
sr : TSearchRec;
Ext : string;
begin
DataView.Clear;
if (FoundFiles <> nil) and (FoundDirs <> nil) then begin
FoundFiles.Clear;
FoundDirs.Clear;
if FindFirst(FolderShellTreeView.Path + '\*.*',faAnyFile,sr) = 0 then
try
repeat
if ((sr.Attr and faDirectory) = faDirectory) then begin
if not((sr.Name = '.') or (sr.Name = '..')) then begin
Application.ProcessMessages;
with DataView.Items.Add do begin
ImageIndex := 0;
Caption := sr.Name;
end;
FoundDirs.Add(sr.Name);
end;
end;
until FindNext(sr) <> 0;
finally
FindClose(sr);
end;
if FindFirst(FolderShellTreeView.Path + '\*.*',faAnyFile,sr) = 0 then
try
repeat
if ((sr.Attr and faDirectory) <> faDirectory) then begin
Application.ProcessMessages;
Ext := LowerCase(ExtractFileExt(sr.Name));
// if (Ext = '.mp3') or (Ext = '.wav') then begin
// with DataView.Items.Add do begin
// ImageIndex := 1;
// Caption := sr.Name;
// end;
// FoundFiles.Add(sr.Name);
// end;
if cbFilter.ItemIndex = 0 then
begin
if (Ext = '.mp3') or (Ext = '.wav') or (Ext = '.wma')
or (Ext = '.aiff') or (Ext = '.ogg') or (Ext = '.mpeg')
or (Ext = '.mpg') or (Ext = '.wmv') or (Ext = '.avi') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 1 then
begin
if (Ext = '.mp3') or (Ext = '.wav') or (Ext = '.wma')
or (Ext = '.aiff') or (Ext = '.ogg') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 2 then
begin
if (Ext = '.mpeg') or (Ext = '.mpg') or (Ext = '.wmv')
or (Ext = '.avi') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 3 then
begin
if (Ext = '.mp3') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 4 then
begin
if (Ext = '.wav') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 5 then
begin
if (Ext = '.ogg') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 6 then
begin
if (Ext = '.wma') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 7 then
begin
if (Ext = '.aiff') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 8 then
begin
if (Ext = '.mpeg') or (Ext = '.mpg') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 9 then
begin
if (Ext = '.wmv') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 10 then
begin
if (Ext = '.avi') then
begin
with DataView.Items.Add do
begin
ImageIndex := 1;
Caption := sr.Name;
end;
FoundFiles.Add(sr.Name);
end;
end else
if cbFilter.ItemIndex = 11 then
begin
if (Ext = '.mp3') or (Ext = '.wav') or (Ext = '.wma') or (Ext = '.aiff') or (Ext = '.ogg') then begin
with DataView.Items.Add do begin
ImageIndex := 1;
Caption := sr.Name;
end;
end else if (Ext = '.mpeg') or (Ext = '.mpg') or (Ext = '.wmv') or (Ext = '.avi') then begin
with DataView.Items.Add do begin
ImageIndex := 2;
Caption := sr.Name;
end;
end else begin
with DataView.Items.Add do begin
ImageIndex := 3;
Caption := sr.Name;
end;
end;
FoundFiles.Add(sr.Name);
end;
end;
until FindNext(sr) <> 0;
finally
FindClose(sr);
end;
end;
end;
procedure TfrmOp.DataViewDblClick(Sender: TObject);
var
i : Integer;
Path : string;
begin
if DataView.Selected <> nil then begin
for i := 0 to DataView.Items.Count do begin
if DataView.Items[i].Selected then begin
// Is Directory
if i < FoundDirs.Count then begin
Path := FolderShellTreeView.Path;
if FolderShellTreeView.Path[Length(FolderShellTreeView.Path)] <> '\' then
Path := Path + '\';
FolderShellTreeView.Path := Path + FoundDirs[i];
end;
end;
end;
end;
end;
procedure TfrmOp.DataViewSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
var
i : Integer;
Path : string;
begin
xiOpen.Enabled := false;
if DataView.Selected <> nil then begin
for i := 0 to DataView.Items.Count do begin
if DataView.Items[i].Selected then begin
xiOpen.Enabled := true;
end;
end;
end;
end;
end.
Fabian Eigentlich hat MS Windows ab Vista den Hang zur Selbstzerstörung abgewöhnt – mkinzler
|
|
Zitat
|