Board index » delphi » General Protection Fault

General Protection Fault

Why do I get a General Protection Fault after redeclaring a
variable as follows.

Original declaration:
Type
  TConf = Record
            A : Integer ;
            B : string ;
          End ;
Var
  Conf : TConf ;

Using the above works perfectly.

But after changing to:
Type
  TConf = Record
            A : Integer ;
            B : string ;
          End ;
  PConf = ^TConf ;
Var
  Conf : PConf ;

I keep getting a GPF as soon as I try to use the variables.

I have done the same thing(???) in another program which works fine.

Can anyone figure what I am doing wrong.

--
-----------------------------
Anders Johansson
Hadelko AB
Kronobr?nneriet
302 42  Halmstad
Sweden
Tel +46 (0)35 102550
Fax +46 (0)35 187515
email and...@hadelko.se
----------------------------

 

Re:General Protection Fault


Quote
In article <326128D9.7...@hadelko.se> Anders Johansson <and...@hadelko.se> writes:
>Why do I get a General Protection Fault after redeclaring a
>variable as follows.
>Original declaration:
>Type
>  TConf = Record
>            A : Integer ;
>            B : string ;
>          End ;
>Var
>  Conf : TConf ;
>Using the above works perfectly.
>But after changing to:
>Type
>  TConf = Record
>            A : Integer ;
>            B : string ;
>          End ;
>  PConf = ^TConf ;
>Var
>  Conf : PConf ;
>I keep getting a GPF as soon as I try to use the variables.

Sure... you changed the declaration so that "Conf" is no longer an instance of
the record, but an instance of a pointer to the record.  A pointer initially
contains an unpredictable value, and you must use "New()" and "Dispose()" (or
an equivalent procedure) to allocate the actual storage block at runtime.

Other Threads