Jump to content


Photo

Recursive loop


  • Please log in to reply
8 replies to this topic

#1 adem0x

adem0x
  • Members
  • 5 posts
  • Gender:Male

Posted 16 January 2014 - 04:55 PM

I have a class which looks like this:

TNode = class(TPersistent)
private
FFirstChild: TNode;
FLastChild: TNode;
FPrevSibling: TNode;
FNextSibling: TNode;
public
published
property FirstChild: TNode read FFirstChild write FFirstChild;
property LastChild: TNode read FLastChild write FLastChild;
property PrevSibling: TNode read FPrevSibling write FPrevSibling;
property NextSibling: TNode read FNextSibling write FNextSibling;
end;


My problem is this:

NextInspector goes into a recursive loop and crashes my app.

There's no reason why it should go into that recursive loop, but it does.

Could you please get rid of this bug.

Thank you.

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 17 January 2014 - 03:15 PM

Hello,

Can you send me demo project which cause this bug, to I modify it and send it back to you.

Thank you.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 adem0x

adem0x
  • Members
  • 5 posts
  • Gender:Male

Posted 04 June 2014 - 07:22 PM

I never saw this reply of yours (was a notification of your reply sent to me?); and thought you were not interested.

As a result, I started using Inspex (it does not suffer from the same problem), but for other reasons I'd like to go back to NextInspector.

Here is the code that causes problems.

I hope you can solve the issue(s).

Thank you.

interface

uses
Types,
Classes;

type
TNode = class(TPersistent)
private
FCount: Integer;
FIsClearing: Boolean;
FParent: TNode;
FRoot: TNode;
FFirstChild: TNode;
FLastChild: TNode;
FNextSibling: TNode;
FPrevSibling: TNode;
procedure SetParent(AParent: TNode);
protected
procedure Attach(AParent: TNode); virtual;
procedure Detach; virtual;
public
constructor Create(AParent: TNode); virtual;
destructor Destroy; override;
function HasChild: Boolean;
procedure Clear; virtual;
published
property FirstChild: TNode read FFirstChild;
property LastChild: TNode read FLastChild;
property NextSibling: TNode read FNextSibling;
property Parent: TNode read FParent write SetParent;
property PrevSibling: TNode read FPrevSibling;
property Root: TNode read FRoot;
property Count: Integer read FCount;
end;

implementation

uses
SysUtils;

constructor TNode.Create(AParent: TNode);
begin
FRoot := nil;
FParent := nil;
FIsClearing := False;
FCount := 0;
FFirstChild := nil;
FLastChild := nil;
FPrevSibling := nil;
FNextSibling := nil;
Attach(AParent);
end;

destructor TNode.Destroy;
begin
if FCount > 0 then Clear;
if (FParent <> nil) and not FParent.FIsClearing then Detach;
end;

procedure TNode.Clear;
var
Node1: TNode;
Node2: TNode;
begin
try
FIsClearing := True;
if FCount > 0 then begin
Node1 := FFirstChild;
while Node1 <> nil do begin
Node2 := Node1;
Node1 := Node1.FNextSibling;
if Assigned(Node2) then begin
Node2.FIsClearing := True;
Node2.Free;
end;
end;
FCount := 0;
end;
finally
FFirstChild := nil;
FLastChild := nil;
FIsClearing := False;
end;
end;

procedure TNode.SetParent(AParent: TNode);
begin
if FParent <> nil then Detach;
if AParent <> nil then Attach(AParent);
end;

procedure TNode.Attach(AParent: TNode);
begin
if AParent <> nil then begin
if Assigned(AParent.FLastChild) then begin
AParent.FLastChild.FNextSibling := Self;
FPrevSibling := AParent.FLastChild;
AParent.FLastChild := Self;
end else begin
AParent.FFirstChild := Self;
AParent.FLastChild := Self;
FPrevSibling := nil;
end;
FNextSibling := nil;
if (AParent <> FParent) and (AParent <> nil) then Inc(AParent.FCount);
FParent := AParent;
end;
FIsClearing := False;
if FParent = nil then FRoot := Self
else FRoot := FParent.FRoot;
end;

procedure TNode.Detach;
begin
if FParent = nil then raise Exception.Create('?????');
Dec(FParent.FCount);

if Assigned(FPrevSibling) then FPrevSibling.FNextSibling := FNextSibling
else if FParent.FFirstChild = Self then FParent.FFirstChild := FNextSibling
else raise Exception.Create('??????');

if Assigned(FNextSibling) then FNextSibling.FPrevSibling := FPrevSibling
else if FParent.FLastChild = Self then FParent.FLastChild := FPrevSibling
else raise Exception.Create('?????');

FParent := nil;
FRoot := Self;
FPrevSibling := nil;
FNextSibling := nil;
end;

function TNode.HasChild: Boolean;
begin
Result := FFirstChild <> nil;
end;


#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 10 June 2014 - 03:34 AM

Hi,

Please sorry for delay. I will look now again in my mailbox to find your mail and fix it.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 adem0x

adem0x
  • Members
  • 5 posts
  • Gender:Male

Posted 10 June 2014 - 02:46 PM

Hi,

Please sorry for delay. I will look now again in my mailbox to find your mail and fix it.


I never sent you an email, so please dont waste time looking for it.

Please use the code above.

#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 10 June 2014 - 04:10 PM

Hi,

But can you please send me how you use this code with NextInspector? This will tell me where is a recursion.

Thank you.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#7 adem0x

adem0x
  • Members
  • 5 posts
  • Gender:Male

Posted 12 June 2014 - 02:53 AM

Boki,

It has been a long time and I have forgotten all that I might have learnt about NextInspector.

In fact, I don't remember a thing.

I can not even get it to display properties of anything (say a TButton named Button1) on the form.

Can you put together a simple demo that does this simple thing:

1) On a form put a TButton (named Button1) and a TCheckBox (named CheckBox1).

2) Add NextInspector (NextInspector1).

3) link CheckBox1 with NextInspector1 so that it shows the properties of CheckBox1 (in design time or run time).

I need that demo so that I can continue.

BTW, this forum does NOT send me a copy of replies. Can you please adjust whatever is necessary so that I get a copy of the replies by email to save me having to check this thread continiously (which I don't have time for).

Thank you.

#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 15 June 2014 - 08:33 PM

Hello,

1) I will build a demo for you. I hope that I will send it to you tomorrow.

2) I am not sure, but try to click on Follow this topic button on top of this page.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#9 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 29 June 2014 - 10:01 AM

All you need is to add 1 Button and place NextInspector with 1 item at least. Then call next code:

procedure TForm1.Button1Click(Sender: TObject);
begin
  NextInspector1.Associate := Button1;
  NextInspector1.LoadProperties(NextInspector1.Items[0]);
end;

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users