AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Delphi ein objekt von mehreren forms benutzen..
Thema durchsuchen
Ansicht
Themen-Optionen

ein objekt von mehreren forms benutzen..

Ein Thema von napstar · begonnen am 26. Mär 2013 · letzter Beitrag vom 25. Aug 2013
Antwort Antwort
question

Registriert seit: 17. Apr 2013
97 Beiträge
 
#1

AW: ein objekt von mehreren forms benutzen..

  Alt 24. Aug 2013, 22:23
Dear All,

I have two class, TCalculation and TAccounts, i would like to access one object from one class to another,I have informed that AssignTo would be the appropriate to use, could you please pointing me from the following example, how to use AssignTo in this case

Code:
//Unit1
Unit Unit1
type TCalculation = class(TForm)
  private
  protected
   FNewvalue: Boolean;
  public
   property Newvalue: Boolean read FNewvalue;
   
  end;

//Unit2
Unit Unit2
type Taccounts = class(TForm)

 interface

uses
  Unit1
   
  private
  protected
  public
    procedure Checkvalue(Sender: TObject);
  end;

implementation

procedure Taccounts .Checkvalue(Sender: TObject);
begin
//here i want to acces the Boolean (FNewvalue) from Unit1
// i would like to mention that, i need the varable with its value
End;
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.666 Beiträge
 
Delphi 12 Athens
 
#2

AW: ein objekt von mehreren forms benutzen..

  Alt 25. Aug 2013, 09:30
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:
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.
Unit2:
Delphi-Quellcode:
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.
The prefix "btn" stands for TButton, "edt" for TEdit.
Angehängte Dateien
Dateityp: zip Example.zip (2,0 KB, 2x aufgerufen)
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen

Geändert von DeddyH (25. Aug 2013 um 09:34 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort


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 20:23 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