Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Mehrere Flags mit SHFileOperation [Gelöst] (https://www.delphipraxis.net/89937-mehrere-flags-mit-shfileoperation-%5Bgeloest%5D.html)

Ardeo 8. Apr 2007 22:43


Mehrere Flags mit SHFileOperation [Gelöst]
 
Hallo,

Ich verwende diese Funktion aus der Code-Library:

Delphi-Quellcode:
function DoFileWork(aOperation: FILEOP_FLAGS; aFrom, aTo: AnsiString;
                    Flags    : FILEOP_FLAGS): Integer;
var
  FromPath, ToPath: AnsiString;
  SHFileOpStruct: TSHFileOpStruct;
begin
  FromPath := aFrom + #0#0;
  ToPath := aTo + #0#0;
  with SHFileOpStruct do
  begin
    Wnd := 0;
    wFunc := aOperation;
    pFrom := PAnsiChar(FromPath);
    if ToPath <> '' then
    begin
      pTo := PAnsiChar(ToPath)
    end else begin // target available
      pTo := nil;
    end; // target not available
    fFlags := Flags;
  end; // structure
  Result := SHFileOperationA(SHFileOpStruct);
end;
Und da ich nicht viel von WinApi verstehe und auch die Suche keine Erfolge brachte, wollte ich frage, wie es möglich ist, mehr als nur eine Flag zu verwenden. Ich würde nämlich gerne die 2 Flags 'FOF_SILENT' und 'FOF_NOCONFIRMATION'

bitsetter 8. Apr 2007 23:27

Re: Mehrere Flags mit SHFileOperation
 
Hi,
versuche es mal so:
Delphi-Quellcode:
fFlags := fof_Silent or fof_NoConfirmation;

Ardeo 9. Apr 2007 00:05

Re: Mehrere Flags mit SHFileOperation
 
Dankeschön, das funktioniert.
Frohe Ostern :)

Dezipaitor 9. Apr 2007 08:39

Re: Mehrere Flags mit SHFileOperation [Gelöst]
 
Wen es interessiert :

Mit der Verknüpfung von OR werden 2 Bits in 2 Zahlen zusammengebracht:

Nehmen wir an:
Delphi-Quellcode:
fof_Silent          = 1 = 00001
fof_NoConfirmation  = 4 = 00100
Dann sind die Flags mit OR verknüpft:
Delphi-Quellcode:
fof_Silent          = 1 = 00001
fof_NoConfirmation  = 4 = 00100
--------------------------------
MyOR                = 5 = 00101
Man kann dann mit einer and Verküpfung herausfinden, ob ein bestimmte Bit gesetzt ist :

Delphi-Quellcode:
if MyOr and fof_Silent = fof_Silent then...
Delphi-Quellcode:
MyOr 00101
and 00001 = fof_Silent
-------------
     00001 == fof_Silent
Der AND Operator ergibt nur 1, wenn an beiden Stellen jeweils eine 1 steht.
Alle Bits werden gelöscht, wenn man mit 0 verundet.

Mit dem XOR Operator kann man dann noch ein Bit löschen

Delphi-Quellcode:
MyOR       00101
XOR
fof_Silent 00001
----------------------
            00100
XOR ergibt nur dann 1, wenn von zwei Bits nur EIN Bit gesetzt ist.


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:39 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