Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   problem with accessing value (https://www.delphipraxis.net/176290-problem-accessing-value.html)

question 24. Aug 2013 10:25

problem with accessing value
 
Dear All,
I have two units, Unit1 and Unit2 , i would like to access a boolean from Unit1 to Unit2 , i have tried it in the following way, but i have got the error "Zugriffsverletzung bei Adresse 023C4B58 in Modul 'Test.exe'. Lesen von Adresse 0000"

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);
var
  f : TCalculation ; // i have created an instance of TCalculation    
begin
if f.Newvalue = True then // i have called the boolean
//check the condition
End;
could you please tell me ,how can i make it works?

Furtbichler 24. Aug 2013 10:51

AW: problem with accessing value
 
Zitat:

Zitat von question (Beitrag 1226069)
Code:
...procedure Taccounts .Checkvalue(Sender: TObject);
var
  f : TCalculation ; // i have created an instance of TCalculation    
begin
if f.Newvalue = True then // i have called the boolean
End;

... but you are not accessing the instance your have created. Instead, you access 'f', which is undefined at this point.

Where is your created instance of 'TCalculation'?

question 24. Aug 2013 11:06

AW: problem with accessing value
 
Could you please tell me ,how can i create the instance of 'TCalculation'? i am reading some tutorial,but i am not so clear, could you please give me an example ?

Uwe Raabe 24. Aug 2013 11:25

AW: problem with accessing value
 
Zitat:

Zitat von question (Beitrag 1226072)
Could you please tell me ,how can i create the instance of 'TCalculation'? i am reading some tutorial,but i am not so clear, could you please give me an example ?

Delphi-Quellcode:
var
  f: TCalculation; // declaration
begin
  f := TCalculation.Create; // create instance
  ...

question 24. Aug 2013 11:35

AW: problem with accessing value
 
Hi , i got the error " Nicht genünged wirklich parameter"
Code:
var
  f: TCalculation;
begin
  f := TCalculation.Create; // Here pointing the error("Nicht genünged wirklich parameter")
  ...

DeddyH 24. Aug 2013 11:37

AW: problem with accessing value
 
TCalculation is of kind TForm, whose constructor expects an Owner-parameter. If you don' t want to set an owner, simply pass nil.
Delphi-Quellcode:
f := TCalculation.Create(nil);
I think you should read some basics-tutorial, e.g. here.

question 24. Aug 2013 12:24

AW: problem with accessing value
 
Thanks for the link, i am following this tutorial,but i have another question, i have done the progem, now there is no error,but i am not getting the expected value of Modified(its a Boolean var)
Code:
var
  f: TCalculation;
begin
  f := TCalculation.Create(nil);
  if f.FNewvalue = True then // the FNewvalue is always zero, which is unexpected
  //this will hapen
  else
    //this
end;

DeddyH 24. Aug 2013 12:29

AW: problem with accessing value
 
This is not unexpected, you create a new instance, therefore its properties are set to default unless something happens which changes them.

[edit] BTW: You should never compare to true or false, this can lead to unexpected results.
Delphi-Quellcode:
if var = true then
-->
Delphi-Quellcode:
if var then
[/edit]

question 24. Aug 2013 15:37

AW: problem with accessing value
 
Is it also possible to create a class exactly as it is(not as a new instance), i mean i want to create a class of TCalculation so that i can access any of its variable with the exact value from class of TAccounts

i even dont know whether its possible or not, i was looking in tutorial but dont get any idea yet, can you please help me ?

DeddyH 24. Aug 2013 15:48

AW: problem with accessing value
 
You have 2 different classes derived from TPersistent with similar properties? In that case you can override the "Assign" or even better the "AssignTo"-Method. This should do exactly what you want. There should be examples for both methods in this forum: Hier im Forum suchenAssign, Hier im Forum suchenAssignTo.

question 24. Aug 2013 15:56

AW: problem with accessing value
 
Thanks, i am looking on it.

By the way, Can you please suggest me, any Book/online learning material to learn Delphi with MYSQL(from beginner to expert), even it need to buy ,i will buy it,but i am looking for it, i have a book but it is in German language, a learning material in English would be easily understable in my situation.


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