🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.delphi
Article #347175

Re: callChain

#347175
From: apl
Date: Fri, 26 Jun 2020 19:18
85 lines
3770 bytes
> 
> Program, który wkleiłeś nie zadziała jak opisałeś, sprawdź.
> 
> -- 
> pozdrawiam
> Roman Tyczka

Dziekuję za zainteresowanie moim pomysłem.
Być może Twoje oczekiwania są inne, a być może patrzę i czegoś nie widzę (tę wersję upraszczałem korzystając z Notatnika)

Na wszelki wypadek wklejam jednak wersję skopiowaną wprost z edytora Delphi. Jest ona minimalnie bogatsza, a mianowicie w proc. sub0 jest instrukcja
 if n=0 then callChain:=callChain+'>sub0';
zamiast poprzedniej
 callChain:=callChain+'>sub0';
Warunek if n=0 zapobiega powtarzaniu się nazwy '>sub0' w wołaniach rekurencyjnych aby skrócić łańcuch odnotowujący te wołania w sytuacji, gdy mamy licznik takich wołań. Zamieszczam tu pełne treści obu modułów składających się na program testowy.
W efekcie np. wykonania 1. kroku otrzymasz komunikat:

Error occured in call chain ">TForm1.Button1Click>sub0>sub1>sub2". Iteration step=0. Recursion step=0

czyli informację, że błąd powstał w procedurze sub2 wołanej z procedury sub1, która była wołana z procedury sub0, a ta z kolei ze zdarzenia OnClick  przycisku button1. 

Pozdrawiam,
apl

unit Unit1;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
uses unit2;
procedure TForm1.Button1Click(Sender: TObject);
begin
 sub0('>TForm1.Button1Click',0);
end;

end.


unit Unit2;

interface
 procedure sub0(callChain:string;n:word);
implementation
 uses dialogs,SysUtils;

 procedure sub2(callChain:string;i,n:word);
  var   r:real;
 begin
  callChain:=callChain+'>sub2';
  r:=0;
   try      //enclosure of a critical fragment
   r:=r/r;
   except
    showMessage('Error occured in call chain "'+callChain+'". Iteration step='+intToStr(i)+'. Recursion step='+intToStr(n))
   end;
 end;{sub2}

 procedure sub1(callChain:string;i,n:word);
 begin
  callChain:=callChain+'>sub1';
  sub2(callChain,i,n);
 end;{sub1}

procedure sub0(callChain:string;n:word);
 var   i:shortInt;
 begin
  if n=0 then callChain:=callChain+'>sub0';
  for i:=0 to 5 do sub1(callChain,i,n);
  if n<3 then sub0(callChain,n+1);  //recursion
 end;{sub0}
end.
Technical Details
Message-ID: <42404755-6e80-4417-b83f-16e59f486a0bo@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!3.eu.feeder.erje.net!feeder.erje.net!usenet.goja.nl.eu.org!weretis.net!feeder7.news.weretis.net!news.uzoreto.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
References: <81b9653c-e77c-444e-9e47-38872c9e3853o@googlegroups.com> <11s1yocj1ipmk.dlg@tyczka.com>

Show Full Headers
Complete Article Headers
X-Received: by 2002:a05:6214:13c6:: with SMTP id cg6mr4754248qvb.160.1593199110701;        Fri, 26 Jun 2020 12:18:30 -0700 (PDT)
X-Received: by 2002:a9d:378a:: with SMTP id x10mr3666426otb.117.1593199110460; Fri, 26 Jun 2020 12:18:30 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!3.eu.feeder.erje.net!feeder.erje.net!usenet.goja.nl.eu.org!weretis.net!feeder7.news.weretis.net!news.uzoreto.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.delphi
Date: Fri, 26 Jun 2020 12:18:30 -0700 (PDT)
In-Reply-To: <11s1yocj1ipmk.dlg@tyczka.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=109.173.147.252; posting-account=ukiAYgoAAADpsCfFgVYs3wM73JlzLYyB
NNTP-Posting-Host: 109.173.147.252
References: <81b9653c-e77c-444e-9e47-38872c9e3853o@googlegroups.com> <11s1yocj1ipmk.dlg@tyczka.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <42404755-6e80-4417-b83f-16e59f486a0bo@googlegroups.com>
Subject: Re: callChain
From: apl <apl@icpnet.pl>
Injection-Date: Fri, 26 Jun 2020 19:18:30 +0000
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit