Einzelnen Beitrag anzeigen

Benutzerbild von jaenicke
jaenicke
Online

Registriert seit: 10. Jun 2003
Ort: Berlin
9.350 Beiträge
 
Delphi 11 Alexandria
 
#13

AW: Die alte Leier: Zirkulaere Referenzen, aber warum nicht so: ...?

  Alt 26. Jul 2017, 07:21
Ein minimales Beispiel:
Delphi-Quellcode:
// MyMain.pas
uses
  UnitX, MainInterface;

type
  TMyMain = class(TForm, IMainInterface)
    StatusEdit: TEdit;
  public
    procedure SetStatusMessage(const AValue: string);
  end;

[...]

procedure TMyMain.SetStatusMessage(const AValue: string);
begin
  StatusEdit.Text := AValue;
end;

// Aufruf:
PerformHCoreOperation(Self);
Delphi-Quellcode:
unit MainInterface;
...
type
  IMainInterface = interface
  ['{2A2A7B02-5612-44C4-8A76-D90C857C36C7}']
    procedure SetStatusMessage(const AValue: string);
  end;
Delphi-Quellcode:
unit UnitX;

uses
  MainInterface;

procedure PerformHCoreOperation(const AStatusInterface: IMainInterface);
begin
  AStatusInterface.SetStatusMessage('PowerMonger status ON!');
end;
Das ist nur ein minimales Beispiel und eine Trennung des Formulars von der Klasse, die IMainInterface implementiert wäre durchaus wünschenswert, aber für den Anfang reicht das so vollkommen aus.

Die GUID (im Interface, hier ['{2A2A7B02-5612-44C4-8A76-D90C857C36C7}']) dient dazu das Interface eindeutig zu identifizieren. Du kannst diese mit Strg + Shift + G in Delphi erzeugen.
Sebastian Jänicke
Alle eigenen Projekte sind eingestellt, ebenso meine Homepage, Downloadlinks usw. im Forum bleiben aktiv!
  Mit Zitat antworten Zitat