What wrong with this (Subproperty with TPersistent)?

soapsiam
soapsiam used Ask the Experts™
on
I want to define property Range on my component with 2 subproperty; StartRange and EndRange, thus I defined it using the TPersistent descendant.....

unit MyUnit;

interface

uses
  Windows, Messages, SysUtils, Classes, WinInet;
  TpgHttpRange = class(TPersistent)
  private
    FStartRange: integer;
    FEndRange: integer;
  public
    procedure Assign(Source: TPersistent); override;
  published
    property StartRange : integer read FStartRange write FStartRange default 0;
    property EndRange : integer read FEndRange write FEndRange default 0;
  end;

TpgHttpDownLoad = class(TComponent)
  private
     //---others----....
     FRange : TpgHttpRange;
     // ---others-----
  published
     property Range: TpgHttpRange read FRange write
FRange;
     //------others-----
  end;

Implementation

procedure TpgHTTPRange.Assign(Source: TPersistent);
begin
    if Source is TpgHttpRange then
        with Source as TpgHttpRange do
        begin
            StartRange := Self.FStartRange;
            EndRange := Self.FEndRange;
        end
    else
        inherited Assign(Source);
end;

//---others------
end.

After registering, on object inspector when I click on
[+] before the Range (which it should expanded and dislayed subproperties), the exception 'Unable to expand'
was shown. What wrong with this implementation.....
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004
Commented:
seems you've forgotten to create it in the object you will use it

just place a constructor there

TpgHttpDownLoad = class(TComponent)
 private
    //---others----....
    FRange : TpgHttpRange;
    // ---others-----
 public
   constructor create()
 published
    property Range: TpgHttpRange read FRange write
FRange;
    //------others-----
 end

constructor TpgHttpDownLoad.create(AOwner : TComponent);
begin
  inherited create(AOwner);
  FRange := TpgHttpRange.Create;
end;

don't forget the destructor to free it

hope thats it

meikl ;-)

Author

Commented:
Oh! How can I make a simle mistake like this!

Thanks, soap
Top Expert 2004

Commented:
:-)) this happens sometimes to me too,
just forgot something and the searching, searching, ...

well, glad to helped you,
thanks for the points :-)

good luck again

meikl ;-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial