Einzelnen Beitrag anzeigen

Benutzerbild von FriFra
FriFra

Registriert seit: 19. Apr 2003
1.291 Beiträge
 
Delphi 2005 Professional
 
#1

Problem bei Komponentenerstellung... (Property -> TString

  Alt 3. Okt 2003, 11:34
Ich bin gerade dabei eine Komponente zu erstellen. Diese Komponente soll eine Property (read only) vom Typ TStrings haben.

Ich will den entspr. Wert automatisch beim verändern einzelner anderer Properties neu zuweisen.
Mein Problem ist nun, wie binde ich eine derartige Property richtig ein, besonders wo erzeuge ich die TString und wo gebe ich sie wieder frei?

Bisher habe ich nur ein paar boolean Properties (read write) und eine publisched function drin.

Ausserdem ist mir aufgefallen, dass die Defaultwerte der boolschen Properties zwar korrekt auf True stehen, aber nach Einfügen der Komponente jeweils noch False ausgewählt ist...

Delphi-Quellcode:
unit GetLocalMail;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
  Dialogs, StdCtrls, Registry, IniFiles, ActiveX, ShlObj, shellApi, XPMan,
  ComCtrls, ComObj;

type
  TGetLocalMail = class(TComponent)
  private
    { Private-Deklarationen }
    B_IFN: boolean;
    B_LN: boolean;
    B_OL: boolean;
    B_NS: boolean;
    B_OP: boolean;
    L_Mails:TStrings;
    procedure SetIFN(const Value: boolean);
    procedure SetLN(const Value: boolean);
    procedure SetOL(const Value: boolean);
    procedure SetNS(const Value: boolean);
    procedure SetOP(const Value: boolean);
  protected
    { Protected-Deklarationen }
    function GetNotesMail: string;
    function GetOutlookMail: string;
    function GetNetscapeMail: string;
    function GetOperaMail: string;
  public
    { Public-Deklarationen }
  published
    { Published-Deklarationen }
    property IncludeFullname: boolean read B_IFN write SetIFN default True;
    property LotusNotes: boolean read B_LN write SetLN default True;
    property Outlook: boolean read B_OL write SetOL default True;
    property Netscape: boolean read B_NS write SetNS default True;
    property Opera: Boolean read B_OP write SetOP default True;

    property MailAddresses: TStringList read L_Mails;

    function GetMail: string;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('FriFra', [TGetLocalMail]);
end;

procedure TGetLocalMail.SetIFN(const Value: boolean);
begin
  B_IFN := Value;
end;

procedure TGetLocalMail.SetLN(const Value: boolean);
begin
  B_LN := Value;
end;

procedure TGetLocalMail.SetOL(const Value: boolean);
begin
  B_OL := Value;
end;

procedure TGetLocalMail.SetNS(const Value: boolean);
begin
  B_NS := Value;
end;

procedure TGetLocalMail.SetOP(const Value: boolean);
begin
  B_OP := Value;
end;

{ B E G I N N - Lotus Notes }

function TGetLocalMail.GetNotesMail: string;
begin
  Result := 'dummy@dummy.com';
end;
{ E N D E - Lotus Notes }

{ B E G I N N - Outlook und Outlook Express }

function TGetLocalMail.GetOutlookMail: string;
begin
  Result := 'dummy@dummy.com';
end;
{ E N D E - Outlook und Outlook Express }

{ B E G I N N - Netscape }

function TGetLocalMail.GetNetscapeMail: string;
begin
  Result := 'dummy@dummy.com';
end;
{ E N D E - Netscape }

{ B E G I N N - Opera 5-7 }

function TGetLocalMail.GetOperaMail: string;
begin
  Result := 'dummy@dummy.com';
end;
{ E N D E - Opera 5-7 }

{ B E G I N N - Mailadressen ausgeben }

function TGetLocalMail.GetMail: string;
var
  Tmp, Tmp1: string;
begin
  Result:='';
  if B_LN = True then
    Result := GetNotesMail;
  end;
  if B_OL = True then
    Result := Result + ',' + GetOutlookMail;
  if B_NS = True then
    Result := Result + ',' + GetNetscapeMail;
  if B_OP = True then
    Result := Result + ',' + GetOperaMail;
  Result := StringReplace(Result, ',,', ',');
  if copy(Result, 1, 1) = ',then
    Result := copy(Result, 2, Length(Result));
  if copy(Result, Length(Result), 1) = ',then
    Result := copy(Result, 1, Length(Result) - 1);
end;
{ E N D E - Mailadressen ausgeben }

end.
Elektronische Bauelemente funktionieren mit Rauch. Kommt der Rauch raus, geht das Bauteil nicht mehr.
  Mit Zitat antworten Zitat