AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Access variable from one form to another
Thema durchsuchen
Ansicht
Themen-Optionen

Access variable from one form to another

Ein Thema von question · begonnen am 20. Aug 2013 · letzter Beitrag vom 26. Aug 2013
Antwort Antwort
Seite 2 von 2     12   
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: Access variable from one form to another

  Alt 21. Aug 2013, 09:22
I think we need the code of the "Person1"-method. Maybe you want to do a call by reference but actually do a call by value?
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
  Mit Zitat antworten Zitat
Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.429 Beiträge
 
Delphi 10.4 Sydney
 
#12

AW: Access variable from one form to another

  Alt 21. Aug 2013, 13:21
The PersonID can alternatively be determined from a query:
Delphi-Quellcode:
unit unit1;

interface

type
  TForm1 = class(TForm)
    {...}
  private // <- for use self
    function GetMyPersonID: Integer;
    procedure SetMyPersonID(AValue: Integer);
  public // <- for use to other
    property MyPersonID: Integer read GetMyPersonID write SetPersonID;
  end;

var
  Form1: TForm1; // <- Instance of TForm1

implementation

procedure TForm1.SetMyPersonID(AValue: Integer);
begin
  FQuery.FieldByName('MyPersonID').AsInteger := AValue;
end;

procedure TForm1.GetMyPersonID: Integer;
begin
  Result := FQuery.FieldByName('MyPersonID').AsInteger;
end;
  Mit Zitat antworten Zitat
question

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

AW: Access variable from one form to another

  Alt 26. Aug 2013, 17:33
Hi,
i have followed what you have suggested but i still got the value '0' .
Now, i wanna do the work in same Unit mot from another
Code:
Procedure TForm1.AddDateTime(Sender:Tobject; AEvent: TcxSchedulerEvent);
begin

Query.Close();
    QueryKalender.SQL.Text:= 'INSERT INTO Table'
      '(Name`, `NEWID` ..) ' +
    'VALUES ( ' :Name, :NEWID);';

Query.ParamByName('NEWID').AsInteger:= AEventID;
    Query.ExecSQL();
    Query.Close();

  end;

Procedure TForm1.OnDragDrop(Sender, Source: TObject; X,
  Y: Integer);

begin
//here i would like to use the value of AEventID;
//i cannnot call the procedure AddDateTime(Sender,TcxSchedulerEvent);
//becasue the parameter is different, how can i overcome it ?
end;

Geändert von question (26. Aug 2013 um 17:50 Uhr)
  Mit Zitat antworten Zitat
question

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

AW: Access variable from one form to another

  Alt 26. Aug 2013, 22:19
Hi, now its working fine i have written the follwoing
Code:
procedure TForm1.SetMyPersonID(AValue: Integer);
begin
  FQuery.FieldByName('MyPersonID').AsInteger := AValue;
end;

procedure TForm1.GetMyPersonID: Integer;
begin
  Result := FQuery.FieldByName('MyPersonID').AsInteger;
end;
is that ok to write like this, i mean normally in sql query need to query.sql.add/query.sql.open/close... but in this case it is working fine should i need to write the whole query or is that also okay just to write only
Code:
Result := FQuery.FieldByName('MyPersonID').AsInteger;
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


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 01:29 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz