Recent

Author Topic: Copying a pointer --> error  (Read 4687 times)

lutz_r

  • Newbie
  • Posts: 2
Copying a pointer --> error
« on: May 14, 2005, 03:02:16 pm »
hi
at school we use delphi6pe but at home i use lazarus because kylix is outdated. at the moment we try to program a traffic simulator.
now there is a thing which i dont understand why it doesn't work.
i have created a pointer with an element:
Code: [Select]

type Talz = ^Tale;
     Tale = record
                  auto: Tauto;
                  naechstes: Talz;
                  end;

in the class TStrasse i use a private variable:
Code: [Select]
autoliste: Talz;
in the create method of TStrasse i do:
Code: [Select]

constructor TStrasse.create;
begin
     inherited create;
     new(autoliste);
     autoliste^.naechstes:= nil;
end;

which works fine
but when i try to copy autoliste to another it gives me just an error message "Acces Violation".
the code for copying is this:
Code: [Select]

procedure TStrasse.autoerzeugen(b,vmax:single);
var backup, nA: Talz;
begin
     new(backup);
     backup:= autoliste;
...
...
end;

the problem is, that i do this in uFachklassen and not in the formunit, where it works, but i need it in ufachklassen.
i do not understand why it doesn't work maybe one of you could help me.

matthijs

  • Hero Member
  • *****
  • Posts: 537
Copying a pointer --> error
« Reply #1 on: May 14, 2005, 04:32:12 pm »
Maybe you could explain were the error is and what the error is. Remember if you define a class in a seperate unit, private and protected members (methods and properties) can not be accessed directly. (Although it should not give an AV)
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

lutz_r

  • Newbie
  • Posts: 2
Copying a pointer --> error
« Reply #2 on: May 14, 2005, 05:40:58 pm »
the error is caused by
Code: [Select]
backup:= autoliste; and says "Acces Violation". There is nothing more in the popup than this.
both, backup and autoliste, are from the type Talz.

matthijs

  • Hero Member
  • *****
  • Posts: 537
Copying a pointer --> error
« Reply #3 on: May 14, 2005, 06:34:04 pm »
Well first of all: remember you wont make a backup, you only have a second pointer to the same memory location. But maybe it works when you use the "@".
Code: [Select]

@backup := @autoliste;
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

Anonymous

  • Guest
Copying a pointer --> error
« Reply #4 on: May 15, 2005, 05:51:41 pm »
*domp*
i forgot to do a strasse:=TStrasse.create; in the formcreate method...
because without the create method there was no pointer which i could copy

i do a backup/copy of the pointer because i would lose all the data which hangs on it in this procedure if i don't copy

thx and what does the @ do?

 

TinyPortal © 2005-2018