AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

access value by Property

Ein Thema von question · begonnen am 22. Aug 2013 · letzter Beitrag vom 23. Aug 2013
Antwort Antwort
question

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

access value by Property

  Alt 22. Aug 2013, 16:31
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
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: access value by Property

  Alt 22. Aug 2013, 16:56
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.
  Mit Zitat antworten Zitat
question

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

AW: access value by Property

  Alt 22. Aug 2013, 17:19
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.

Geändert von question (22. Aug 2013 um 17:21 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

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

AW: access value by Property

  Alt 22. Aug 2013, 17:25
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".
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
question

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

AW: access value by Property

  Alt 22. Aug 2013, 18:54
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.
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

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

AW: access value by Property

  Alt 22. Aug 2013, 19:03
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;
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
question

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

AW: access value by Property

  Alt 22. Aug 2013, 19:41
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);
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

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

AW: access value by Property

  Alt 23. Aug 2013, 07:16
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.
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
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 22:31 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