Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#13

AW: XE7: Frame soll Aktion im Hauptformular auslösen

  Alt 16. Mai 2015, 20:02
Nein ich lasse die Frames nicht dumm, aber dieser Frame war nicht der Kandidat für mehr Intelligenz.

Du möchtest mehr Intelligenz im Frame, na denn:
Delphi-Quellcode:
unit Form.Main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls, Frame.Sub;

type
  TMainForm = class( TForm )
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Memo1: TMemo;
    TabSheet2: TTabSheet;
    SubFrame1: TSubFrame;
  private
  protected
    procedure DoShow; override;
  public

  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.DoShow;
begin
  inherited;
  SubFrame1.Control := Memo1;
end;

end.
und der Frame:
Delphi-Quellcode:
unit Frame.Sub;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TSubFrame = class( TFrame )
    CheckBox1: TCheckBox;
    procedure CheckBox1Click( Sender: TObject );
  private
    FControl: TControl;
    procedure SetControl( const Value: TControl );
  protected
    procedure Notification( AComponent: TComponent; Operation: TOperation ); override;
  public
    property Control: TControl read FControl write SetControl;
  end;

implementation

{$R *.dfm}
{ TSubFrame }

procedure TSubFrame.CheckBox1Click( Sender: TObject );
begin
  FControl.Enabled := CheckBox1.Checked;
end;

procedure TSubFrame.Notification( AComponent: TComponent; Operation: TOperation );
begin
  inherited;
  if ( Operation = opRemove ) and ( AComponent = FControl ) then
    SetControl( nil );
end;

procedure TSubFrame.SetControl( const Value: TControl );
begin
  if Assigned( FControl ) then
    FControl.RemoveFreeNotification( Self );

  FControl := Value;

  if Assigned( FControl ) then
  begin
    FControl.FreeNotification( Self );
    CheckBox1.Checked := FControl.Enabled;
  end;

  CheckBox1.Enabled := Assigned( FControl );

end;

end.
Ach ja, macht im Übrigen immer noch das Gleiche allerdings mit einer Spezialisierung (Frame für Controls um die Enabled Eigenschaft zu bearbeiten)
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat