![]() |
PasswortEdit Unicode fähig machen
ich hab folgendes problem ich versuche folgende komponente unicode fähig zu machen.
Delphi-Quellcode:
das hab ich so versucht.
unit PasswordEdit;
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TPasswordEdit = class(TCustomEdit) private FXorKey : Integer; Procedure SetXorKey(XorKey:Integer); Procedure SetText(NewText:String); Function GetRealText : String; protected procedure EvKeyPress(Var M : tMessage); message WM_CHAR; public constructor create(AOwner:TComponent);override; destructor destroy;override; published property PasswordChar; property Visible; property Font; property CharCase; property AutoSelect; property AutoSize; property OEMConvert; property Hint; property ShowHint; property Tag; property Text; property Password : String read GetRealText write SetText; { Set default pass, and read from this property } property Width; property Height; property XorKey : Integer read FxorKey Write SetXorKey; end; procedure Register; implementation Procedure BurnString(St:String); var count:integer; Begin for count:=1 to length(st) do st[count]:=' '; End; Constructor TPasswordEdit.create(AOwner:TComponent); Begin inherited Create(AOwner); PasswordChar:='*'; Password:=''; Text:=''; XorKey:=16; End; Destructor TPasswordEdit.destroy; Begin inherited destroy; End; Procedure TPasswordEdit.SetXorKey(XorKey:Integer); var I:Integer; Str:String; Begin if XorKey<>FXorKey then Begin Str:=Text; For I:= 1 to Length(Str) do Str[I]:=Chr(Ord(Str[I]) Xor FXorKey); FXorKey:=XorKey; For I:= 1 to Length(Str) do Str[I]:=Chr(Ord(Str[I]) Xor FXorKey); End; End; Procedure TPasswordEdit.SetText(NewText:String); var I:Integer; Str:String; Begin Str:=NewText; For I:= 1 to Length(Str) do Str[I]:=Chr(Ord(Str[I]) Xor FXorKey); Text:=Str; End; procedure TPasswordEdit.EvKeyPress(Var M : tMessage); Begin if not( m.Wparam in [$08,$0D,$0A,$1B,$09]) then m.Wparam:=m.Wparam xor FXorKey; Inherited; End; Function TPasswordEdit.GetRealText:string; var I:Integer; Str:String; Begin Str:=Text; For I:= 1 to Length(Str) do Str[I]:=Chr(Ord(Str[I]) Xor FXorKey); Result:=Str; BurnString(str); End; End.
Delphi-Quellcode:
wie man sieht benutze ich die tnt componenten. leider funzt das so nicht, sieht jemand den/die fehler und kann mir weiter helfen?
unit PasswordEdit;
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, TntStdCtrls; type TPasswordEdit = class(TTntCustomEdit) private FXorKey: Integer; procedure SetXorKey(XorKey: Integer); procedure SetText(NewText: WideString); function GetRealText: WideString; protected procedure EvKeyPress(var M: tMessage); message WM_CHAR; public constructor create(AOwner: TComponent); override; destructor destroy; override; published property PasswordChar; property Visible; property Font; property CharCase; property AutoSelect; property AutoSize; property OEMConvert; property Hint; property ShowHint; property Tag; property Text; property Password: WideString read GetRealText write SetText; { Set default pass, and read from this property } property Width; property Height; property XorKey: Integer read FxorKey write SetXorKey; end; procedure Register; implementation procedure BurnString(St: string); var count: integer; begin for count := 1 to length(st) do st[count] := ' '; end; constructor TPasswordEdit.create(AOwner: TComponent); begin inherited Create(AOwner); PasswordChar := #8226; Password := ''; Text := ''; XorKey := 16; end; destructor TPasswordEdit.destroy; begin inherited destroy; end; procedure TPasswordEdit.SetXorKey(XorKey: Integer); var I: Integer; Str: WideString; begin if XorKey <> FXorKey then begin Str := Text; for I := 1 to Length(Str) do Str[I] := WideChar(Ord(Str[I]) xor FXorKey); FXorKey := XorKey; for I := 1 to Length(Str) do Str[I] := WideChar(Ord(Str[I]) xor FXorKey); end; end; procedure TPasswordEdit.SetText(NewText: WideString); var I: Integer; Str: WideString; begin Str := NewText; for I := 1 to Length(Str) do Str[I] := Widechar(Ord(Str[I]) xor FXorKey); Text := Str; end; procedure TPasswordEdit.EvKeyPress(var M: tMessage); begin if not (m.Wparam in [$08, $0D, $0A, $1B, $09]) then m.Wparam := m.Wparam xor FXorKey; inherited; end; function TPasswordEdit.GetRealText: Widestring; var I: Integer; Str: WideString; begin Str := Text; for I := 1 to Length(Str) do Str[I] := WideChar(Ord(Str[I]) xor FXorKey); Result := Str; BurnString(str); end; end. danke im voraus. MfG cookie |
Re: PasswortEdit Unicode fähig machen
Wenn du von Fehler sprichst, was passiert denn überhaupt? Was sollte passieren und tritt davon nicht ein?
|
Re: PasswortEdit Unicode fähig machen
der fehler ist, es werden alle zeichen nur als fragezeichen dargestellt. irgendwas geht bei der xor verschlüsselung schief.
|
Re: PasswortEdit Unicode fähig machen
... und aufhören string zu verwenden und statt dessen widestring nutzen...
|
Re: PasswortEdit Unicode fähig machen
Zwar nich zu deinem problem, aber dei funktion BurnString ist sinnlos!
Du erzeugst durch die übergabe einen neuen String und füllst diesen mit leerzeichen. Wenn schon dann mindestens var-Parameter verwenden. |
Re: PasswortEdit Unicode fähig machen
Was macht eigentlich BurnString? (nichts, so wie ich das seh) abgesehn davon, daß dieses String ist
Delphi-Quellcode:
PS: in m.Wparam sind nicht die Key,s so wie im String ... da sind die VK_...-Codes drin (siehe Virtual Key)
procedure TPasswordEdit.SetXorKey(XorKey: Integer);
var I: Integer; Str: WideString; begin if XorKey <> FXorKey then begin Str := Text; for I := 1 to Length(Str) do Str[I] := WideChar(Ord(Str[I]) xor FXorKey xor XorKey); FXorKey := XorKey; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:53 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz