Einzelnen Beitrag anzeigen

Benutzerbild von cookie22
cookie22

Registriert seit: 28. Jun 2006
Ort: Düsseldorf
936 Beiträge
 
Delphi XE2 Professional
 
#1

PasswortEdit Unicode fähig machen

  Alt 8. Mär 2009, 21:55
ich hab folgendes problem ich versuche folgende komponente unicode fähig zu machen.
Delphi-Quellcode:
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.
das hab ich so versucht.
Delphi-Quellcode:
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.
wie man sieht benutze ich die tnt componenten. leider funzt das so nicht, sieht jemand den/die fehler und kann mir weiter helfen?

danke im voraus.

MfG
cookie
  Mit Zitat antworten Zitat