Solved

Compound component and properties

Posted on 2000-04-11
19
289 Views
Last Modified: 2013-11-23
I created a component assembled from different other components.
Where some components have again childcomponents.
Now my problem is: How can I stream all properties from those components and subcomponents to a *.dfm .
0
Comment
Question by:gipa
  • 10
  • 8
19 Comments
 
LVL 1

Expert Comment

by:DonBartholomew
ID: 2703367
If you want to tell Luc about EE, he already knows.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2703588
Hi gipa,

all published properties and classes are automatically saved into the DFM file. If you have classes which are only public then you need to override DefineProperties in the particular container and stream out explicitely the classes in question.

Ciao, Mike
0
 

Author Comment

by:gipa
ID: 2703713
Mike,

If I understand you well, I should stream out every property from a class I use.
But can’t I stream the whole subcomponent out, I don’t want to write a Read and a write for each property.

Patrick.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2703759
No no, you don't need to stream all properties of all subcomponents. Depending on what you want to have saved you can either make the particular property/class published or you save them yourself. Can you give us a snippet of the container class with some of the properties to be saved? Then we can discuss this on the "living" example...

Ciao, Mike
0
 

Author Comment

by:gipa
ID: 2703862
Mike,

Type
 MyBrowser = class(TCustomPanel)
 private
   FOutBar: TDCOutBar;
   FGrid: TDbGrid;
 public
    property OutLookBar: TDCOutBar
      read   GetOutLookBar
      write SetOutLookBar;
 published
 end;


 One of the props of FOutBar is
 FOutBar.Groups[i] //(TDCOutBarGroup)  

//   this could be
// DCOutBarGroup.Caption
// DCOutBarGroup.Align and ……

So I want to stream every Group from FOutbar.
If there are 5 groups then I want per group all the props in the *.dfm.
Is this possible?

// Dream OutBar
// This is Something like a Outlookbar and has subcomponents like Groups, Listviews and ...
// http://www.dream- com.com

Patrick.
0
 

Author Comment

by:gipa
ID: 2703864
Mike,

Type
 MyBrowser = class(TCustomPanel)
 private
   FOutBar: TDCOutBar;
   FGrid: TDbGrid;
 public
    property OutLookBar: TDCOutBar
      read   GetOutLookBar
      write SetOutLookBar;
 published
 end;


 One of the props of FOutBar is
 FOutBar.Groups[i] //(TDCOutBarGroup)  

//   this could be
// DCOutBarGroup.Caption
// DCOutBarGroup.Align and ……

So I want to stream every Group from FOutbar.
If there are 5 groups then I want per group all the props in the *.dfm.
Is this possible?

// Dream OutBar
// This is Something like a Outlookbar and has subcomponents like Groups, Listviews and ...
// http://www.dream- com.com

Patrick.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2703934
Patrick,

well, I don't see why this should not be possible. You have not published the Outlookbar class. Is there a reason why you want to have it only public? I ask because this way you cannot modify it at design time. If you publish it then all problems should be gone, because it's published properties are automatically saved.

Ciao, Mike
0
 

Author Comment

by:gipa
ID: 2704269
Mike,

I Edit the properties with a ComponentEditor at design-time.
If I publish this component all what I can see in the object Inspector is the name of the component.

So if you can tell me how to stream this component, that would be very nice.

Patrick.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2706966
Patrick, for non-standard components published as properties of other components you need to write a property editor (for the property being a component) and override the GetAttributes method. There you need to return the flag paSubProperties (among others if appropriate). This is the way to make it working in the object inspector saving you work to stream your component.

The other way is to override DefineProperties in your container component.

  TMyBrowser = class(TCustomPanel)
  protected
    procedure DefineProperties(Filer: TFiler); override;
  end;


procedure TMyBrowser.DefineProperties(Filer: TFiler);

  function DoWrite: Boolean;
  begin
    Result := determine somehow whether there is to write something or not;
  end;

begin
  Filer.DefineProperty('OutlookBar', ReadData, WriteData, DoWrite);
end;

This method will be called by the streaming system of the VCL when loading or storing your browser component. There's a good example in the online help which shows all you need. Look in the index for DefineProperties. The first entry in the sublist is the example.

Ciao, Mike
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:gipa
ID: 2707109
Mike,

Something is written to the dfm file.
But it is unreadable, and i got a stream read error.

// this is the code i used

procedure TBrowser32.LoadCompProperty(Reader: TReader);
begin
  if Reader.ReadBoolean then
    FOutBar:= TDCOutBar(Reader.ReadComponent(nil));
end;

procedure TBrowser32.StoreCompProperty(Writer: TWriter);

begin
  Writer.WriteBoolean(FOutBar <> nil);
  if FOutBar <> nil then
    Writer.WriteComponent(FOutBar);
end;

procedure TBrowser32.DefineProperties(Filer: TFiler);

  function DoWrite: Boolean;
  begin
    if Filer.Ancestor <> nil then { check Ancestor for an inherited value }
    begin
      if TBrowser32(Filer.Ancestor).FOutBar = nil then
        Result := FOutBar <> nil
      else if (FOutBar = nil) or
         (TBrowser32(Filer.Ancestor).FOutBar.Name <> FOutBar.Name) then
        Result := True

      else Result := False;
    end
    else { no inherited value -- check for default (nil) value }
      Result := FOutBar <> nil;
  end;
begin
  inherited; { allow base classes to define properties }
  Filer.DefineProperty('MyCompProperty', LoadCompProperty, StoreCompProperty, DoWrite);
end;
0
 

Author Comment

by:gipa
ID: 2707118
Adjusted points from 200 to 500
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2707259
Mmmh, strange. Your code looks ok. Are you using D5? I ask because with D5 you have to possibility to save a DFM in text form, not only binary. From what I can see in Classes.pas all TWriter methods write binary data only. Perhaps this is your problem? See, if your form is saved as text DFM and switch it if so...

Ciao, Mike
0
 

Author Comment

by:gipa
ID: 2707272
Mike,

Yes it is saved as Text.

Patrick.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2707293
Aha, then switch the flag so that the DFM is saved in binary form (right click, switch off "text DFM"). Then change something in the form and save it. Does this work?

Ciao, Mike
0
 

Author Comment

by:gipa
ID: 2707358
Mike,

Yes it works partly.
But now there is an other problem my outlookbar changed is parent, the component isn’t the parent anymore but the form is.

Patrick.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2707484
Well, I would change the read procedure so:

procedure TBrowser32.LoadCompProperty(Reader: TReader);
begin
  if Reader.ReadBoolean then
  begin
    FOutBar:= TDCOutBar(Reader.ReadComponent(nil));
    FOutBar.Parent := Self;
  end;
end;

Ciao, Mike
0
 

Author Comment

by:gipa
ID: 2707501
Mike,

I tried that already, bot its not solving the whole problem because now then outlookbar lay’s on top of the component and I can delete it from my component.

Patrick.
0
 
LVL 10

Accepted Solution

by:
Lischke earned 500 total points
ID: 2707560
I'm a bit confused now. When you create the bar in the browser then you set its parent property also being the browser, don't you? Why should this be different to the Parent assignment above?

Btw: You can avoid that the VCL creates the component for you. I assume you create the bar in the browser's constructor. There you can set all needed properties (Owner, Parent). Then pass this component reference so:

  FOutBar:= Reader.ReadComponent(FOutBar);

Perhaps this solves the other problem too.

Ciao, Mike
0
 

Author Comment

by:gipa
ID: 2707606
Thanks for helping me sorting this problem out.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now