Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Problem bei Komponentenerstellung... (Property -> TStrings) (https://www.delphipraxis.net/9755-problem-bei-komponentenerstellung-property-tstrings.html)

FriFra 3. Okt 2003 11:34


Problem bei Komponentenerstellung... (Property -> TString
 
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.

SirThornberry 3. Okt 2003 12:01

Re: Problem bei Komponentenerstellung... (Property -> TSt
 
Zitat:

Zitat von FriFra
...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...

Du musst die Werte im Constructor setzen. Das die Werte auf False stehen liegt daran das sie einfach nicht gesetzt sind (keine ahnung wozu dann das "default" da ist wenns nicht funktioniert) und somit der wert im speicher zufällig auf false steht.

Zitat:

Zitat von FriFra
...besonders wo erzeuge ich die TString und wo gebe ich sie wieder frei?

Im Constructor und Destructor (alten Constructor and Destructor überschreiben) deiner Komponente (fehlt ja derzeit noch).

FriFra 3. Okt 2003 12:08

Re: Problem bei Komponentenerstellung... (Property -> TSt
 
Und wie überschreibe ich den Constructor und Destructor meiner Komponente?

Mirilin 3. Okt 2003 12:11

Re: Problem bei Komponentenerstellung... (Property -> TSt
 
:hi:
Ich darf Sakura zitieren:

Zitat:

Noch was zum Thema default. Der Wert der dort angeben wird, wird durch Delphi nicht automatisch initialisiert. Das gibt der IDE lediglich an, daß, wenn dieser Wert im OI eingetragen wird, daß dieser nicht gespeichert/geladen werden muss, da die Komponente dieses automatisch so tut

Edit ::
KLICK MICH

SirThornberry 3. Okt 2003 12:19

Re: Problem bei Komponentenerstellung... (Property -> TSt
 
Delphi-Quellcode:
[...]
type
  TGetLocalMail = class(TComponent)
  public
    constructor create(AOwner: TComponent); override;
    destructor destroy; override;
[...]
Delphi-Quellcode:
constructor TGetLocalMail.create(AOwner: TComponent);
begin
  inherited create(AOwner);
  mystrings := TStrings.create;
end;

destructor TGetLocalMail.destroy;
begin
  mystrings.free;
  inherited destroy;
end;

Christian Seehase 3. Okt 2003 12:28

Re: Problem bei Komponentenerstellung... (Property -> TSt
 
Moin SirThornberry,

wenn Du jetzt noch aus den TStrings eine TStringList machst ist's perfekt ;-)


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:36 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz