Einzelnen Beitrag anzeigen

Benutzerbild von LoCrux
LoCrux

Registriert seit: 5. Mär 2007
Ort: Gwang-Yang-City
48 Beiträge
 
Delphi 2009 Enterprise
 
#11

Re: Variablen zwischen 2 Formularen übermitteln

  Alt 19. Mär 2008, 01:38
OK.. maybe not optimal but working.
Eine Loesungsmoeglichkeit ueber Events.

Deine "Main-FormA"

Delphi-Quellcode:
unit Unit_A;

interface

uses
  Unit_B,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type

  TForm_A = class(TForm)
    editA: TEdit;
    procedure editAChange(Sender: TObject);
  private
    { Private-Deklarationen }
    Form_B: TForm_B;
    Procedure GotNotifyFromB(text:String);
  public
    { Public-Deklarationen }
    constructor create(AOwner:TComponent); override;
    destructor destroy; override;
  end;

var
  Form_A: TForm_A;

implementation

{$R *.dfm}

constructor TForm_A.create(AOwner:TComponent);
begin
  inherited;
  Form_B := TForm_B.Create(Self);
  Form_B.DoNotifyA := GotNotifyFromB;
  Form_B.Constraints := Self.Constraints;
  Form_B.Top := Self.Top;
  Form_B.Left := Self.Left+Self.Width;
  Form_B.Show;
end;

destructor TForm_A.destroy;
begin
  if Assigned(Form_B) then Form_B.Free;
  inherited;
end;

Procedure TForm_A.GotNotifyFromB(text:String);
begin
  editA.Text := text;
end;

procedure TForm_A.editAChange(Sender: TObject);
begin
  if Assigned(Form_B) then Form_B.editB.Text := editA.Text;
end;

end.
Deine "FormB"

Delphi-Quellcode:
unit Unit_B;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TEditNotify = Procedure(text:String) of object;

  TForm_B = class(TForm)
    editB: TEdit;
    procedure editBChange(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    { Private-Deklarationen }
    FDoNotifyA : TEditNotify;
  public
    { Public-Deklarationen }
    property DoNotifyA:TEditNotify read FDoNotifyA write FDoNotifyA;
  end;


implementation

{$R *.dfm}

procedure TForm_B.editBChange(Sender: TObject);
begin
  if Assigned(FDoNotifyA) then FDoNotifyA(editB.Text);
end;

procedure TForm_B.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  CanClose := False;
end;

end.
Angehängte Dateien
Dateityp: 7z 2forms_177.7z (154,1 KB, 0x aufgerufen)
“C++ is an insult to the human brain.” [Niklaus Wirth]

2B OR NOT 2B (.. THAT IS FF)
  Mit Zitat antworten Zitat