Autor Beitrag
HelgeLange
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 735
Erhaltene Danke: 6

Windows 7
Delphi7 - Delphi XE
BeitragVerfasst: Sa 07.04.07 00:59 
Auch mal 'ne Frage seit langer Zeit wieder...
ich habe ein Set, welches wie folgt deklariert ist :
ausblenden Delphi-Quelltext
1:
2:
     THookAccessOption  = (haoAlwaysStandardEvent, haoAllowMultipleEvents, haoReplaceEvent);
     THookAccessOptions = Set Of THookAccessOption;


nun schliessen sich haoAllowMultipleEvents und haoReplaceEvent gegenseitig aus (aus logischen Gründen), aber all meine Versuche, das in einer Set-Methode hinzubekommen, schlugen fehl...
Ich weiss, dass man mit
ausblenden Delphi-Quelltext
1:
2:
if haoReplaceEvent in FHookAccessOptions Then
  ...

testen kann, ob eine Option im Set enthalten ist und mit
ausblenden Delphi-Quelltext
1:
  FHookAccessOptions := FHookAccessOptions - [haoAllowMultipleEvents];					

kann man eine andere dann rausnehmen.. eigentlich...

Ideen ?

_________________
"Ich bin bekannt für meine Ironie. Aber auf den Gedanken, im Hafen von New York eine Freiheitsstatue zu errichten, wäre selbst ich nicht gekommen." - George Bernhard Shaw
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 07.04.07 12:42 
Es gibt auch die Methoden Include und Exclude für Sets. Probier es mal mit denen ...

Ansonsten stell deine Frage mal noch etwas genauer oder gib mal einen etwas größeren Source-Block.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
HelgeLange Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 735
Erhaltene Danke: 6

Windows 7
Delphi7 - Delphi XE
BeitragVerfasst: Sa 07.04.07 14:53 
uhm.. hatte ich ja eigentlich schon alles dazu geschrieben...
aber bitte schön :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TERPHookAccessContainer.__SetHookAccessOptions(const Value: THookAccessOptions);
begin
  If haoReplaceEvent in Value then
    Exclude(FHookAccessOptions, haoAllowMultipleEvents);
  If haoAllowMultipleEvents in Value Then
    Exclude(FHookAccessOptions, haoReplaceEvent);
  FHookAccessOptions := Value;
end;


Das Problem scheint zu nicht das Setzen zu sein (ich kenne Include/Exclude auch), sondern rauszubekommen, ob im originalen Wert etwas schon enthalten, was mit dem neuen Wert zusammen nicht da sein darf.

_________________
"Ich bin bekannt für meine Ironie. Aber auf den Gedanken, im Hafen von New York eine Freiheitsstatue zu errichten, wäre selbst ich nicht gekommen." - George Bernhard Shaw
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 07.04.07 15:55 
hmmm, Dein Source wirft mindestens 2 Warnungen (oder sollte es) ... Alle vom Typ: Auf FHookAccessOptions zugewiesener Wert wird niemals benutzt.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TERPHookAccessContainer.__SetHookAccessOptions(const Value: THookAccessOptions);
begin
  If haoReplaceEvent in Value then
    Exclude(FHookAccessOptions, haoAllowMultipleEvents); //<--
  If haoAllowMultipleEvents in Value Then
    Exclude(FHookAccessOptions, haoReplaceEvent); //<--
  FHookAccessOptions := Value;
end;


Der aktuelle Source ändert zwar Zwischenzeitlich deinen Wert, Du ersetzt diesen aber in der letzten Zeile durch den neuen Wert (unabhängig von deinen Änderungen (die also im besten Fall wegoptimiert werden.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TERPHookAccessContainer.__SetHookAccessOptions(const Value: THookAccessOptions);
begin
  If (haoReplaceEvent in Value) and (haoAllowMultipleEvents in Value) then
  Begin
    //Widerspruch: Nutzen wir doch einfach den bisherigen Wert:
    Value := Value - [haoAllowMultipleEvents, haoReplaceEvent];
    If haoReplaceEvent in FHookAccessOptions then
      Include(Value, haoAllowMultipleEvents);
    If haoAllowMultipleEvents in FHookAccessOptions Then
      Include(Value, haoReplaceEvent);
  end;
  FHookAccessOptions := Value;
end;

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
HelgeLange Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 735
Erhaltene Danke: 6

Windows 7
Delphi7 - Delphi XE
BeitragVerfasst: Sa 07.04.07 16:23 
man kann auf Value nichts zuweisen, da es ein konstanter Wert ist, Habe es in eine temp-variable geschoben und mit der gearbeitet, jetzt geht es, danke BenBE :)

hier noch der Source, welcher funktioniert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TERPHookAccessContainer.__SetHookAccessOptions(const Value: THookAccessOptions);
var tempValue: THookAccessOptions;
begin
  tempValue := Value;
  If (haoReplaceEvent in Value) And (haoAllowMultipleEvents in Value) Then begin
    tempValue := tempValue - [haoAllowMultipleEvents, haoReplaceEvent];
    If haoReplaceEvent in FHookAccessOptions then
      Include(tempValue, haoAllowMultipleEvents);
    If haoAllowMultipleEvents in FHookAccessOptions Then
      Include(tempValue, haoReplaceEvent);
  end;
  FHookAccessOptions := tempValue;
end; // __SetHookAccessOptions

_________________
"Ich bin bekannt für meine Ironie. Aber auf den Gedanken, im Hafen von New York eine Freiheitsstatue zu errichten, wäre selbst ich nicht gekommen." - George Bernhard Shaw
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 07.04.07 18:16 
Const ist auch nur Ansichtssache ;-) Hatt ich mit user profile iconNarses schon stundenlange Diskussionen darüber, ob es Konstanten gibt, zumal Delphi Property-Setter IIRC auch annimmt, wenn man Const nicht für die Parameterliste spezifiziert.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.