AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Interface erstellen und rückgabe

Ein Thema von EWeiss · begonnen am 2. Sep 2012 · letzter Beitrag vom 5. Sep 2012
Antwort Antwort
Seite 2 von 2     12   
EWeiss
(Gast)

n/a Beiträge
 
#11

AW: Interface erstellen und rückgabe

  Alt 5. Sep 2012, 16:10
Dann musst du in der SetWidth-Methode überprüfen, ob sie schonmal aufgerufen wurde.
Mach ich mehr oder weniger ja auch..

Delphi-Quellcode:
procedure TSkinPanel.SetWidth(const Width: Integer);
begin

  FWidth := Width;
end;
Ich behandle nachfolgende veränderungen der Weite einfach nicht.
Aber mein problem hinsichtlich der möglichen Eingabe lößt das nicht.

Eine behandlung sähe dann so aus

Delphi-Quellcode:
procedure TSkinPanel.SetWidth(const Width: Integer);
begin
  MoveWindow(bla.. bala..

  FWidth := Width;
end;

gruss
  Mit Zitat antworten Zitat
Benutzerbild von geskill
geskill

Registriert seit: 17. Feb 2007
Ort: NRW
420 Beiträge
 
Delphi 2010 Professional
 
#12

AW: Interface erstellen und rückgabe

  Alt 5. Sep 2012, 16:58
Hallo,
wegen der unerwünschten Eingaben. Du könntest ja 2 Interfaces bauen:
Delphi-Quellcode:
type
  ISimpleButton = interface
    ['{B7281ABB-ED9A-4018-B651-41DFBFAE730A}']

    function GetText: WideString;
    procedure SetText(Value: WideString);

    property Text: WideString read GetText write SetText;
  end;

  IAdvancedButton = interface(ISimpleButton)
    ['{6C10BCC7-87BE-45B1-9613-44EF840DE4AA}']

    function GetWidth: Integer;
    procedure SetWidth(Value: Integer);

    function GetSimpleButton: ISimpleButton;

    property Width: Integer read GetWidth write SetWidth;
  end;
Dann könntest du von einem TAdvancedButton Objekt dir intern das IAdvancedButton speichern, extern aber nur ISimpleButton zur Verfügung stellen.

Delphi-Quellcode:
type
  TSimpleButton = class(TInterfacedObject, ISimpleButton)
  private
    FText: WideString;
  protected
    function GetText: WideString;
    procedure SetText(Value: WideString);

  public
    constructor Create;

    property Text: WideString read GetText write SetText;
  end;

  TAdvancedButton = class(TSimpleButton, IAdvancedButton)
  private
    FWidth: Integer;
  protected
    function GetWidth: Integer;
    procedure SetWidth(Value: Integer);

  public
    constructor Create;

    function GetSimpleButton: ISimpleButton;

    property Width: Integer read GetWidth write SetWidth;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TSimpleButton }

constructor TSimpleButton.Create;
begin
  inherited Create;
end;

function TSimpleButton.GetText: WideString;
begin
  Result := FText;
end;

procedure TSimpleButton.SetText(Value: WideString);
begin
  FText := Value;
end;

{ TAdvancedButton }

constructor TAdvancedButton.Create;
begin
  inherited Create;
end;

function TAdvancedButton.GetSimpleButton: ISimpleButton;
begin
  Result := Self;
end;

function TAdvancedButton.GetWidth: Integer;
begin
  Result := FWidth;
end;

procedure TAdvancedButton.SetWidth(Value: Integer);
begin
  FWidth := Value;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  AdvancedButton: IAdvancedButton;

  SimpleButton: ISimpleButton;
begin
  AdvancedButton := TAdvancedButton.Create;

  AdvancedButton.Width := 126;
  AdvancedButton.Text := 'lalala';

  ShowMessage(IntToStr(AdvancedButton.Width) + ' ' + AdvancedButton.Text);

  SimpleButton := AdvancedButton.GetSimpleButton;

  ShowMessage(SimpleButton.Text);

  SimpleButton.Text := 'blubblub';

  ShowMessage(IntToStr(AdvancedButton.Width) + ' ' + AdvancedButton.Text);
end;
Grüße
Sebastian
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#13

AW: Interface erstellen und rückgabe

  Alt 5. Sep 2012, 17:10
Danke
Werde mir das gleich mal anschauen ob etwas in der art mein problem beseitigt.

EDIT:
So wie das aussieht ist das ein mehr an schreibarbeit aber letztendlich ist Width trotzdem public.
Muss das wohl innerhalb der function Width selbst händeln.
Die Weite ignorieren wenn sie schon gesetzt ist.

gruss

Geändert von EWeiss ( 5. Sep 2012 um 17:30 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:04 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