Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Access variable from one form to another (https://www.delphipraxis.net/176222-access-variable-one-form-another.html)

DeddyH 21. Aug 2013 09:22

AW: Access variable from one form to another
 
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?

Blup 21. Aug 2013 13:21

AW: Access variable from one form to another
 
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;

question 26. Aug 2013 17:33

AW: Access variable from one form to another
 
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;

question 26. Aug 2013 22:19

AW: Access variable from one form to another
 
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;


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:58 Uhr.
Seite 2 von 2     12   

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