Hallo liebe Delphi Gemeinde,
ich hoffe ihr könnt mir weiter helfen, da ich mir daraus keinen Reim machen kann.
folgende Klasse ist gegeben:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78:
| unit UTWndowsFunctions;
interface
type TStatus = (StandBy, LockWindowsXPStation);
type THotKeyFunctionsWindws = class public constructor Create(saction : TStatus); destructor Destroy; procedure doit(); procedure setFunction(saction : TStatus); function getFunctionName() : String; private procedure goStandBy(); procedure plockWindowsXPStation(); end;
implementation
uses HotKeyManager, ComCtrls, Windows, Forms, Messages, Dialogs;
var sfunctionName : String; action : TStatus;
const waitingms = 100; constructor THotKeyFunctionsWindws.Create(saction : TStatus); begin Inherited Create;
setFunction(saction); end;
destructor THotKeyFunctionsWindws.Destroy; begin inherited Destroy; end;
procedure THotKeyFunctionsWindws.setFunction(saction : TStatus); begin case action of StandBy : begin action:=saction; sfunctionName:= 'StandBy'; end; LockWindowsXPStation : begin action:=saction; sfunctionName:= 'LockStation'; end; end; end;
function THotKeyFunctionsWindws.getFunctionName: string; begin result:=sfunctionName; end;
procedure THotKeyFunctionsWindws.doit; begin if action = StandBy then begin goStandBy() ; Exit; end; if action = LockWindowsXPStation then begin plockWindowsXPStation() ; Exit; end; end;
procedure THotKeyFunctionsWindws.goStandBy; begin SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 1); Sleep(waitingms); end;
procedure THotKeyFunctionsWindws.plockWindowsXPStation; begin LockWorkStation; Sleep(waitingms); end;
end. |
Jetzt füge ich in meinem Hauptformular einer listbox, Objekte der oben genannten Klasse hinzu.
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
| procedure TMainForm.FormCreate(Sender: TObject); var hotKeyFunction : THotKeyFunctionsWindws; begin
listbox3.Items.AddObject('Object1 ',THotKeyFunctionsWindws.Create(StandBy)); listbox3.Items.AddObject('Object2 ',THotKeyFunctionsWindws.Create(LockWindowsXPStation));
hotKeyFunction:=THotKeyFunctionsWindws(listbox3.Items.Objects[0]); Showmessage('Object1 ' + hotKeyFunction.getFunctionName);
hotKeyFunction:=THotKeyFunctionsWindws(listbox3.Items.Objects[1]); Showmessage('Object2 ' + hotKeyFunction.getFunctionName); end; |
Leider zeigt er mir:
Object1 StandBy
Object2 StandBy
aber es müsste so heissen:
Object1 StandBy
Object2 LockWindowsXPStation
das heisst doch, dass er dasselbe Objekt hinzugefügt hat? Warum er das?
Hoffe ich konnte mein Problem verständlich machen. Für jede Antwort wäre ich wirklich dankbar.
Moderiert von
Gausi: Code- durch Delphi-Tags ersetzt