Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Call procedure (https://www.delphipraxis.net/176306-call-procedure.html)

question 26. Aug 2013 14:25

Call procedure
 
Code:
Unit1 
public
procedure Add(Sender: Tobject)
......
Procedure TFrom1.ADD(Sender:Tobject);
begin
....
end;


Unit2
Procedure Done(Sender:Tobject);

uses
  unit1;

var
 TTest : TForm1;

Procedure TFrom2.Done(Sender:Tobject);
begin
TTest.Add(Sender);
end;
i get the error "Zugriffsverletzung bei Adresse 00C683D7 in Modul 'test.exe'. Lesen von Adresse 00000028."
i have also tried with TTest,create(nil); but i always get this error message, how can i overcome it?

Der schöne Günther 26. Aug 2013 14:33

AW: Call procedure
 
You're not getting runtime errors out of nowhere. What did you do? What happens first? Which lines causes the error? You can find it out all yourself by using the built-in debugger.

However, the "Access violation when trying to read 00000028" sounds pretty much like calling an objects method without creating it first. The reference you're using simply does not point to an existing object.

baumina 26. Aug 2013 14:35

AW: Call procedure
 
Create a form like
Delphi-Quellcode:
TTest := TForm1.Create(Application);
or
Delphi-Quellcode:
TTest := TForm1.Create(Nil);


and dont forget to free the Form after using
Delphi-Quellcode:
TTest.Free;

DeddyH 26. Aug 2013 15:16

AW: Call procedure
 
There is no need to free a TComponent if you specified an owner on its creation.

question 26. Aug 2013 15:40

AW: Call procedure
 
I have one class

Type
TCar = class(Tobject)

i would like to add another class TMen inside TCar class, how can i add another class inside a Class?

DeddyH 26. Aug 2013 15:44

AW: Call procedure
 
Delphi-Quellcode:
type
  TMyOtherClass = class
    (* Fields, Methods, Properties *)
  end;

  TMyClass = class
  private
    FMyOtherClass: TMyOtherClass;
    (* More Fields, Methods, Properties *)
  end;
Depending on your intention you have to create the "FMyOtherClass"-instance somewhere (e.g. within the constructor of TMyClass) and free it within the destructor to avoid memoryleaks.


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