AGB  ·  Datenschutz  ·  Impressum  







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

problem with accessing value

Ein Thema von question · begonnen am 24. Aug 2013 · letzter Beitrag vom 24. Aug 2013
Antwort Antwort
Seite 1 von 2  1 2      
question

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

problem with accessing value

  Alt 24. Aug 2013, 10:25
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?
  Mit Zitat antworten Zitat
Furtbichler
(Gast)

n/a Beiträge
 
#2

AW: problem with accessing value

  Alt 24. Aug 2013, 10:51
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'?
  Mit Zitat antworten Zitat
question

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

AW: problem with accessing value

  Alt 24. Aug 2013, 11:06
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 ?
  Mit Zitat antworten Zitat
Benutzerbild von Uwe Raabe
Uwe Raabe
Online

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.021 Beiträge
 
Delphi 12 Athens
 
#4

AW: problem with accessing value

  Alt 24. Aug 2013, 11:25
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
  ...
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat
question

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

AW: problem with accessing value

  Alt 24. Aug 2013, 11:35
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")
  ...
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

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

AW: problem with accessing value

  Alt 24. Aug 2013, 11:37
TCalculation is of kind TForm, whose constructor expects an Owner-parameter. If you don' t want to set an owner, simply pass nil.
f := TCalculation.Create(nil); I think you should read some basics-tutorial, e.g. here.
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: problem with accessing value

  Alt 24. Aug 2013, 12:24
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;
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

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

AW: problem with accessing value

  Alt 24. Aug 2013, 12:29
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.
if var = true then -->
if var then [/edit]
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
 
#9

AW: problem with accessing value

  Alt 24. Aug 2013, 15:37
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 ?
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

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

AW: problem with accessing value

  Alt 24. Aug 2013, 15:48
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.
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
Seite 1 von 2  1 2      


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 12:30 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