Board index » delphi » Copy or Reference of an Object

Copy or Reference of an Object

Hello, I have a application with more forms. In the main form i have a
database-connection-object, which i will use in form 2.

What should i do, make a reference or a copy, and how can i do this.
In this time i copy all necessary propertys to the object in form 2, but i
can't believe that this is the easiest way.

Thank you for answering (sorry for my bad english)

Mani

 

Re:Copy or Reference of an Object


Quote
Manfred Kral wrote in message ...
>Hello, I have a application with more forms. In the main form i have a
>database-connection-object, which i will use in form 2.

>What should i do, make a reference or a copy, and how can i do this.
>In this time i copy all necessary propertys to the object in form 2, but i
>can't believe that this is the easiest way.

You're right, it's not. It might be possible to fill in
"TMainForm.database-connection-object" for the relevant
objects' Connection in form #2. I've observed this happening
even without trying for the Images property of a TTreeView.

You should definitely use a reference. You can make your
second form depend on your main form and add a property
that simply mimics the equivalent field in the other form.

Groetjes,
Maarten Wiltink

Re:Copy or Reference of an Object


I hope i understand this, because my bad english.

When i do this, i can't open form2 with form1. is this right?

"Maarten Wiltink" <maar...@kittensandcats.net> schrieb im Newsbeitrag
news:3e462d09$0$49117$e4fe514c@news.xs4all.nl...

Quote
> Manfred Kral wrote in message ...
> >Hello, I have a application with more forms. In the main form i have a
> >database-connection-object, which i will use in form 2.

> >What should i do, make a reference or a copy, and how can i do this.
> >In this time i copy all necessary propertys to the object in form 2, but
i
> >can't believe that this is the easiest way.

> You're right, it's not. It might be possible to fill in
> "TMainForm.database-connection-object" for the relevant
> objects' Connection in form #2. I've observed this happening
> even without trying for the Images property of a TTreeView.

> You should definitely use a reference. You can make your
> second form depend on your main form and add a property
> that simply mimics the equivalent field in the other form.

> Groetjes,
> Maarten Wiltink

Re:Copy or Reference of an Object


Quote
Manfred Kral wrote in message ...
>I hope i understand this, because my bad english.

>When i do this, i can't open form2 with form1. is this right?

No, that's not right. What does that mean, "open"?

unit UForm2;

interface

type
  TForm2 = class(TForm)
  protected
    function  GetValue: TType;
    procedure SetValue(const Value: TType);

    property  Value: TType read GetValue write SetValue;
  end;

implementation

uses
  UMainForm;

function  TForm2.GetValue: TType;
begin
  Result:=UMainForm.MainForm.Value;
end;

procedure TForm2.SetValue(const Value: TType);
begin
  if not (Self.Value=Value)
  then UMainForm.MainForm.Value:=Value;
end;

This is just the skeleton. It introduces a property that works
by redirecting any access to a different property, in a different
form. The remainder is left as an exercise to the reader.

Groetjes,
Maarten Wiltink

Other Threads