![]() |
AW: ein objekt von mehreren forms benutzen..
Liste der Anhänge anzeigen (Anzahl: 1)
This is the same problem, but a completely different question and situation than yesterday. It is quite hard to post a solution if you don' t know what the problem is. I wrote a short example in Delphi 7. It is not good at all because both units reference each other (you should avoid this if possible), but it works in this simple case.
Unit1:
Delphi-Quellcode:
Unit2:
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TCalculation = class(TForm) btnSetValue: TButton; btnShowAccounts: TButton; procedure btnSetValueClick(Sender: TObject); procedure btnShowAccountsClick(Sender: TObject); private { Private-Deklarationen } FValue: integer; function GetValue: integer; procedure SetValue(const NewValue: integer); public { Public-Deklarationen } property Value: integer read GetValue write SetValue; end; var Calculation: TCalculation; implementation {$R *.dfm} uses Unit2; //Added Unit2 { TCalculation } function TCalculation.GetValue: integer; begin Result := FValue; end; procedure TCalculation.SetValue(const NewValue: integer); begin FValue := NewValue; end; procedure TCalculation.btnSetValueClick(Sender: TObject); begin Value := Value + 1; end; procedure TCalculation.btnShowAccountsClick(Sender: TObject); var Accounts: TAccounts; //locale variable, I deleted the global one in Unit2 begin Accounts := TAccounts.Create(nil); try Accounts.ShowModal; finally Accounts.Free; end; end; end.
Delphi-Quellcode:
The prefix "btn" stands for TButton, "edt" for TEdit.
unit Unit2;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Unit1; //Added Unit1 type TAccounts = class(TForm) btnGetValue: TButton; edtValue: TEdit; procedure btnGetValueClick(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; implementation {$R *.dfm} procedure TAccounts.btnGetValueClick(Sender: TObject); begin edtValue.Text := IntToStr(Calculation.Value); end; end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:58 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz