Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   access value by Property (https://www.delphipraxis.net/176263-access-value-property.html)

question 22. Aug 2013 16:31

access value by Property
 
I have two procedures in a fine with different parameters, i want to access the parameter from one procedure to another

procedure TForm1.Person (ID : Integer);
//here ID=20

procedure TForm1.btnOkClick(Sender: TObject);

from btnOkClick, i want to call the Form1.Person (ID);

but since the ID is not listed as a parameter in TForm1.btnOkClick(Sender: TObject); therefore i cannot access the ID with appropriate value
how can i do that

i have tried with property such as
Pivate
FNewID: Integer;
procedure Person(ID:Integer);
public
property NewID: Integer readFNewID write FNewID;

and in the procedure TForm1.Person (ID : Integer);

i have did

procedure TForm1.Person (ID : Integer);
FNewID := ID
but unfortunaltely it gives the following relsut

ID = 20;
FNewID = 0;
but i expected
ID= 20;
FNewID = 20;
could you please explain me how to do that

Der schöne Günther 22. Aug 2013 16:56

AW: access value by Property
 
Dude, please use those fancy (DELHPI)(/DELPHI)-tags to surround your code blocks.

It's the helmet button between the document with angle brackets and the google button. I'm either really tired or it's pretty difficult to tell where your code starts, where it ends end where it's just english words.

question 22. Aug 2013 17:19

AW: access value by Property
 
Here is the sample code please

Code:
unit Unit1;
{

interface

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

type
  TForm1 = class(TForm)
   
  private
    FNewID : Integer;  
  public
    property NewID : Integer read FNewID;
    Person (ID : Integer);
  end;

var
  Form1: TForm1;
 
implementation


{$R *.DFM}
{$R common.res}

procedure TForm1.Person (ID : Integer);
begin
//here i get the value of ID after query from Database
//for example I have got ID=20;
end;

procedure TForm1.btnOkClick(Sender: TObject);
begin
if True then //after check the condition, i wanna call
Form1.Person (ID); // here how can i initialize ID so that i get the value 20
end;

end.

DeddyH 22. Aug 2013 17:25

AW: access value by Property
 
You can use a function instead of a procedure, or you can pass the parameter by reference.
Delphi-Quellcode:
function TForm1.Person: integer;
begin
  Result := <ID retrieved by query>;
end;

procedure TForm1.Person(out ID: integer);
begin
  ID := <ID retrieved by query>;
end;
If you want to access the parameter inside the procedure, use "var" instead of "out".

question 22. Aug 2013 18:54

AW: access value by Property
 
Thanks for suggestion

but how can i initialize the ID:Integer in event handler, becasue in event handler i cannot add any parameter, for example

Code:
procedure TForm1.Button1click(Sender: Tobject);// i cannot set anyother parameter,then delphi compiler automatic delete the adding parameter
begin
 //here i need the value of ID,which is for example 20, if i declare var ID: Integer here then it give me the value 0
end;
end.

DeddyH 22. Aug 2013 19:03

AW: access value by Property
 
Delphi-Quellcode:
procedure TForm1.Button1click(Sender: Tobject);
var
  ID: integer;
begin
  Person(ID); //Now ID should have the value which is retrieved by your query
end;

question 22. Aug 2013 19:41

AW: access value by Property
 
I have tried it but then i found the value of id

Code:
Procedure TForm1.Person(ID : Integer);
begin
//here the query excuted with a value of ID which comes from another procedure
//therefore to use the function its a lot more change in whole code
// i think in my situation pass parameter by reference will be best way
end;

it would be kind of you, if you give me a small example concerning my situation in order to pass the parameter by refrence from Procedure TForm1.Person(ID : Integer); to Procedure TForm1.Button1Click(Sender: TObject);

DeddyH 23. Aug 2013 07:16

AW: access value by Property
 
The OnClick-Event is a TNotifyEvent, you cannot change this. I still don' t know what you want to do exactly, maybe a little explanation could be helpful.


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:08 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