objektoriented panik

## Originalempfaenger: /comp/lang/pascal/borland
## Originalempfaenger: /maus/lang/tpascal

Moin, Moin, Martin !

I Hate quoting myself, but sorry for using the wrong language in this  
group.

Moin, Moin, alltogether !

I'm programming in TPX 7.0 since a few month.
Since now, I got running everything I want.
But now, I have a real problem, which may be difficult to solve.
I want to produce a few "buttons" on the default textscreen.
I defined an object "TButton" and a pointer on it, called "PButton"
I also defined a poinet on a byte, "PByte", as you can see:

Quote
>-------------------------------Snip------------------------------------
>Type
>        PByte: ^Byte;
>        PButton: ^TButton;

>        TButton=object
>                    {Variablen zuerst}
>                         x,y,z ... usw. ;
>                         savescr: PByte;

>                    constructor init(Parameter);
>                    destructor done;

>                        [Andere Public-Funktionen]

>               Private

>                    {Variablen zuerst}
>                        x,y,z ... usw. ;

>               end;

>-------------------------------Snip------------------------------------

Here are most of the procedures:
(No, I won't write all of them down)

- Show quoted text -

Quote
>-------------------------------Snip------------------------------------

>constructor TButton.init(Parameter);
>var
>begin

>    getmem(savescr, $100);
>    Savearea(savescr);

>end;

>destructor TButton.done;
>begin
>    restorearea(savescr);
>    freemem(savescr,$100);
>end;

>-------------------------------Snip------------------------------------

The procedures "Savearea" and "Restorearea" should save an area of the  
screen at the adress specified by the pointer to restore the former screen  
later. The real size of the area needed is calculated in reality, I just  
put in 100hex as an example.
I wrote all of the code down here af far as I can remember it, the real  
code is beeing compiled without errors and it is logically correct as  
three friends of mine told me. So far, there is no error.

I am interested in the getmem inside the "constructor".
I initialize the object "But1" using new, like this:

- Show quoted text -

Quote
>-------------------------------Snip------------------------------------
>{Mainprogram}
>var But1, But2: PButton;

>begin

>new(But1 , init(Parameter));
>new(But2 , init(Parameter));

>[Code]

>dispose(But2, done);
>dispose(But1, done);

>end;
>-------------------------------Snip------------------------------------

The object "But1" should be existent now, and I may use it.

But now, the bug happens:

As soon as "But2" executes "getmem" inside the "constructor", some  
variables of "But1" start changing around. Quite bad, no?

How does that happen ? Is it maybe not allowed to use "getmem" inside a  
constructor" ?

In reality, the bug is a little bit different:
The former version of "object-buttons" without the "save- / restorearea"  
runs without bugs.
But in the described version, with the "getmem" inside the "constructor"  
(used for storing some graphics-data), some simple commands like

Quote
>-------------------------------Snip------------------------------------
>var savetext,text: string;

>[Code]
>       savetext:=text;
>[Code]

>-------------------------------Snip------------------------------------

change the lokal variables of the previous object, if they are executed  
after the "getmem" Why that ?

For me this bug is really troublemaking, but I will explain it a bit more  
detailed if anybody likes to help me.

I will be grateful for any kind of *help*.

Thak you in advance

Sorry for my bad English.
Sorry for the wrong language in the previous message.

Waiting for answer,

        Martin Sfke

PS: Help me, please !

--