AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Ordnerauswahl-Dialog

Ein Thema von Willie1 · begonnen am 17. Dez 2011 · letzter Beitrag vom 20. Dez 2011
Antwort Antwort
Seite 1 von 2  1 2      
Willie1

Registriert seit: 28. Mai 2008
618 Beiträge
 
Delphi 10.1 Berlin Starter
 
#1

Ordnerauswahl-Dialog

  Alt 17. Dez 2011, 18:25
Hallo Leute,
ich will einen Ordnerauswahl-Dialog bauen, bei dem der Ok-Button disabled wird, wenn der/die Anwender/in einen leeren Ordner auswählen will.
Dazu benutze ich die Komponente PathDialog von Florian Bömers. Diese funktioniert ansonsten gut wie SelectDirectory hat aber zusätzlich die Funktion setOkButton(enabled: Boolean)

Delphi-Quellcode:
function TPathDialog.setOKButton(enabled:Boolean):Boolean;
begin
 result:=false;
 if (FHandle<>0) then
 begin
  result:=true;
  if enabled then
   SendMessage(FHandle,BFFM_ENABLEOK,1,0)
  else
   SendMessage(FHandle,BFFM_ENABLEOK,0,0);
 end;
end;
Ausgelöst wird diese Routine im Event OnSelect - ein Ordner wird angeklickt.

Ich muss aber feststellen, sobald ich setOkButton einbaue, ist der Ok-Button immer disabled.

Gruß Willie

Dann noch ein Hinweis, ich hatte es früher hier schonmal erwähnt. Durch einen Augenerkrankung kann ich nur mit einen Lupensoftware programmieren. Ich bitte um Nachsicht und Rücksicht. Danke.
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: Ordnerauswahl-Dialog

  Alt 17. Dez 2011, 19:10
Du hast die Parameter verwechselt. Wie ist es so?
Delphi-Quellcode:
function TPathDialog.setOKButton(enabled:Boolean):Boolean;
begin
  Result := FHandle <> 0;
  if Result then
    SendMessage(FHandle, BFFM_ENABLEOK, 0, lParam(enabled));
end;
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Willie1

Registriert seit: 28. Mai 2008
618 Beiträge
 
Delphi 10.1 Berlin Starter
 
#3

AW: Ordnerauswahl-Dialog

  Alt 19. Dez 2011, 09:43
ich habs probiert, es klappt nicht. Der OkButton ist immer disabled, sobald ich die Funktion verwende. Result ist true.
Soll ich den Source der Komponente posten?

Willie
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Ordnerauswahl-Dialog

  Alt 19. Dez 2011, 09:44
Wenn es Dir nichts ausmacht, gern, dann muss man nicht lange suchen.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Willie1

Registriert seit: 28. Mai 2008
618 Beiträge
 
Delphi 10.1 Berlin Starter
 
#5

AW: Ordnerauswahl-Dialog

  Alt 19. Dez 2011, 09:55
Delphi-Quellcode:
unit PathDialog;

{ The TPathDialog Component, V1.02

  MOST IMPORTANT :)
  =================
  This is Freeware: However, it's also PostcardWare. When you use
  this component or think it's useful, send me a post-card
  to: Florian Bömers, Colmarer Str.11, D - 28211 Bremen, Germany
  See legal.txt for more details.

  And of course, I am very interested in any application
  that uses this component (or any other application you wrote).
  If so, mail me (not the program, just an URL or similar) !
  (mail address below)


  OVERVIEW
  ========
  TPathDialog is handled like a CommonDialog. Call Execute  and it shows
  the standard-Win95 Dialog for choosing a  directory.


  COMPATIBILITY
  =============
  Delphi 2,3,4
  Windows 95, 98, NT4, NT2000 (Beta3)


  INSTALLATION
  ============
  1. Copy the File PathDialog.pas and PathDialog.dcr to the
    directory where you store your components
    (or let it where it is)
  2. In Delphi, select Component|Install Component. In the
    following dialog, enter the path and filename of
    PathDialog.pas and hit OK.
  3. Now the TPathDialog Component is available in the
    Component palette under Bome.


  HOW TO USE IT
  =============
  It's as easy as the other CommonDialogs: Drop the icon
  on your form. Then a call to Execute shows the Path Dialog.
  If Execute returned true, the directory property contains
  the selected path. When you assigned a directory prior to
  calling Execute, it is selected when showing.


  ADVANCED FUNCTIONALITY
  ======================
  - property Title: This text is shown at the top of the
    PathDialog. It is normally a line like: 'Select the installation
    folder'

  - property ShowStatus and StatusText: if ShowStatus is true, an
    extra line is inserted above the tree. There the StatusText is
    displayed. You might set StatusText in the Event-Handler of
    OnSelect.

  - Event OnShow: Is called when the Dialog is appearing

  - Event OnSelect: Is called each time, when the user changes
    the selected item in the tree. The Path parameter is
    the currently selected directory. It is '' when the user
    selected a non-directory item like Control Panel, etc.

  - function setOKButton: When the Dialog is visible, you
    can enable or disable the OK Button with this function.
    This may be handy when you want to limit the possible
    directories the user can select. You should call this only
    in one of the event handler procedures.

  - property visible: is true when the Dialog is showing.

  - property Handle: Window Handle of the Dialog. Should not be
    necessary to use it.

  - property RootItem: Defines the root of the displayed tree.


  CONTACT, NEW VERSIONS
  =====================
  Send any comments, proposals, enhancements etc. to
  delphi@bome.com
  The latest version of this component can be found on
  http://www.bome.com/


  COPYRIGHT
  =========
  (c) 1997-1999 by Florian Bömers


  VERSION HISTORY
  ===============
  V1.02 changed conditional compiling for Delphi 4 (10 May 99)
  V1.01 changed mail address, added conditional compiling for Delphi2
        added RootItem property
  V1.00 initial release

}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  {$IFDEF VER90} OLE2,{$ELSE} ActiveX, {$ENDIF}  ShlObj;

type
  TSelectEvent=procedure(Sender:TObject; Path:String) of object;
  TRootItem=(riMyComputer, riDesktop);

  TPathDialog = class(TComponent)
  private
    FHandle:THandle;
    FTitle:String;
    FDirectory:String;
    FShowStatus:Boolean;
    FStatusText:String;
    FRootItem:TRootItem;

    FOnShow:TNotifyEvent;
    FOnSelect:TSelectEvent;

    function getVisible:Boolean;
    procedure SetDirectory(Dir:String);
    procedure SetStatusText(Text:String);
  public
    { Shows the dialog. Returns false if the user clicked Cancel }
    { or if an error occurred }
    function Execute:Boolean;
    { Sets the status of the OK-Button to either enabled or disabled    }
    { This function should only be called in one of the 2 Eventhandlers }
    function setOKButton(enabled:Boolean):Boolean;
    { whether the dialog is visible }
    property visible:Boolean read getVisible;
    { Window Handle of the dialog is only valid when visible }
    { ...should not be used...}
    property Handle:THandle read FHandle;
  published
    { should be set before calling Execute }
    property Title:String read FTitle write FTitle;
    { is not valid while the Dialog is visible }
    property Directory:String read FDirectory write setDirectory;
    { must be set before executing the dialog }
    property ShowStatus:Boolean read FShowStatus write FShowStatus default false;
    { is only used if ShowStatus is true }
    property StatusText:String read FStatusText write SetStatusText;
    { where is the root of the tree }
    property RootItem:TRootItem read FRootItem write FRootItem default riMyComputer;

    property Tag;
    // Events
    property OnShow:TNotifyEvent read FOnShow write FOnShow;
    property OnSelect:TSelectEvent read FOnSelect write FOnSelect;
  end;

procedure Register;

implementation

function CallBack(Wnd: HWND; uMsg: UINT; lParam, lpData: LPARAM): Integer stdcall;
var dir:String;
begin
 try
  with TPathDialog(lpData) do
  case uMsg of
   BFFM_INITIALIZED:
    begin
     FHandle:=Wnd;
     SetDirectory(FDirectory);
     SetStatusText(FStatusText);
     try
      if assigned(FOnShow) then
       FOnShow(TPathDialog(lpData));
     except
      On e:Exception do
       ShowMessage(e.Message);
     end;
    end;
   BFFM_SELCHANGED: // lpParam is a pointer to the item identifier list for the newly selected folder.
    begin
     if assigned(FOnSelect) then
     try
      SetString(dir,nil,MAX_PATH);
      if SHGetPathFromIDList(PItemIDList(lParam),PChar(Dir)) then
       FOnSelect(TPathDialog(lpData),PChar(Dir))
      else
       FOnSelect(TPathDialog(lpData),'');
     except
      On e:Exception do
       ShowMessage(e.Message);
     end;
    end;
  end;
 except
 end;
 result:=0;
end;

function TPathDialog.Execute:Boolean;
const RootFlag:Array[TRootItem] of Integer=(CSIDL_DRIVES, CSIDL_DESKTOP);
var iList,Root:PItemIDList;
    bi:TBrowseInfo;
    DispName:String;
    malloc:IMalloc;
begin
 result:=false;
 if (Owner is TWinControl) then
  bi.hwndOwner:=TWinControl(Owner).Handle
 else bi.hwndOwner:=Application.Handle;
 if SHGetSpecialFolderLocation(Handle, RootFlag[FRootItem],Root)=NOERROR then
 try
  SHGetMalloc(malloc);
  SetString(DispName,nil,MAX_PATH);
  with bi do
  begin
   pidlRoot := root;
   pszDisplayName := PChar(DispName);
   lpszTitle := PChar(FTitle);
   ulFlags:=BIF_RETURNONLYFSDIRS;
   if FShowStatus then
    ulFlags:=ulFlags or BIF_STATUSTEXT;
   lpfn:=@CallBack;
   lParam:=Integer(self);
  end;
  iList:=SHBrowseForFolder(bi);
  FHandle:=0;
  if iList<>nil then
  try
   if SHGetPathFromIDList(iList,PChar(DispName)) then
   begin
    FDirectory:=PChar(DispName);
    result:=true;
   end;
  finally
   malloc.Free(iList);
  end;
 finally
  malloc.Free(root);
 end;
end;

function TPathDialog.setOKButton(enabled:Boolean):Boolean;
begin
 result:=false;
 if (FHandle<>0) then
 begin
  result:=true;
  if enabled then
   SendMessage(FHandle,BFFM_ENABLEOK,1,0)
  else
   SendMessage(FHandle,BFFM_ENABLEOK,0,0);
 end;
end;

function TPathDialog.getVisible:Boolean;
begin
 result:=FHandle<>0;
end;

procedure TPathDialog.SetDirectory(Dir:String);
begin
 if (Dir<>'') and (Dir[length(Dir)]='\') then
  FDirectory:=copy(Dir,1,length(Dir)-1)
 else
 if Dir='then
  FDirectory:=GetCurrentDir
 else
  FDirectory:=Dir;
 if (FHandle<>0) and (FDirectory<>'') then
  SendMessage(FHandle,BFFM_SETSELECTION,Integer(LongBool(true)),Integer(PChar(FDirectory)));
end;

procedure TPathDialog.SetStatusText(Text:String);
begin
 FStatusText:=Text;
 if (FHandle<>0) and FShowStatus then
  SendMessage(FHandle,BFFM_SETSTATUSTEXT,0,Integer(PChar(FStatusText)));
end;

procedure Register;
begin
  RegisterComponents('Beispiele', [TPathDialog]);
end;

end.
Der Autor hat früher gerne geantwortet, hat aber jetzt keine Zeit mehr.
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#6

AW: Ordnerauswahl-Dialog

  Alt 19. Dez 2011, 10:14
Ich habe das jetzt unter Delphi 2007 ausprobiert, mit meiner Änderung funktioniert es wie gedacht. Wann rufst Du die Methode denn auf?

[edit] Hier noch mein Testcode:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  PD: TPathDialog;
begin
  PD := TPathDialog.Create(nil);
  try
    PD.OnSelect := DoOnSelect;
    PD.Execute;
  finally
    PD.Free;
  end;
end;

procedure TForm1.DoOnSelect(Sender: TObject; Path: String);
begin
  if Path <> 'then
    (Sender as TPathDialog).setOKButton(AnsiLowerCase(Path[1]) <> 'c');
end;
Der Button wird enabled, sobald ich ein Verzeichnis außerhalb von 'C:' auswähle.[/edit]
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen

Geändert von DeddyH (19. Dez 2011 um 10:45 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#7

AW: Ordnerauswahl-Dialog

  Alt 19. Dez 2011, 10:51
wparam und lparam sind vertauscht
Delphi-Quellcode:
function TPathDialog.setOKButton(enabled:Boolean):Boolean;
begin
 result:=false;
 if (FHandle<>0) then
 begin
  result:=true;
  if enabled then
   SendMessage(FHandle,BFFM_ENABLEOK,0,1)
  else
   SendMessage(FHandle,BFFM_ENABLEOK,0,0);
 end;
end;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#8

AW: Ordnerauswahl-Dialog

  Alt 19. Dez 2011, 10:52
Achwas
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#9

AW: Ordnerauswahl-Dialog

  Alt 19. Dez 2011, 10:55
@DeddyH

sorry, ich sollte doch öfters mal schauen was Du oben schon so alles gepostet hast ...
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#10

AW: Ordnerauswahl-Dialog

  Alt 19. Dez 2011, 10:57
Ego te absolvo
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:37 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz