From b19bb183df7e492b95f9e74ad32e9e7d9b330338 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 18 Dec 2017 16:21:25 +0100 Subject: matheunit.pas: tKnownValues aufgemöbelt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- matheunit.pas | 123 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 33 deletions(-) diff --git a/matheunit.pas b/matheunit.pas index 5247f68..d57fb03 100644 --- a/matheunit.pas +++ b/matheunit.pas @@ -16,21 +16,23 @@ type end; tKnownValues = class private - chef: tKnownValues; - knechte: array of tKnownValues; - kvs: array of tKnownValue; - function finde(nam: string): longint; inline; + chefs,knechte: array of tKnownValues; + kvs: array of tKnownValue; + function finde(nam: string): longint; inline; public - constructor create(chf: tKnownValues); + constructor create(chef: tKnownValues); constructor createFromOriginal(original: tKnownValues); destructor destroy; override; - procedure add(val: tKnownValue); inline; overload; - procedure add(nam: string; val: extended); overload; + procedure add(val: tKnownValue; ignoriereWennBereitsVorhanden: boolean = false); inline; overload; + procedure add(nam: string; val: extended; ignoriereWennBereitsVorhanden: boolean = false); overload; function rem(nam: string): boolean; function extract(nam: string; out val: extended): boolean; inline; - procedure dump(prot: tProtokollant; prefix: string); + procedure dump(prot: tProtokollant; prefix: string); overload; + procedure dump(prefix: string; out s: string); overload; procedure neuerKnecht(knecht: tKnownValues); + procedure neuerChef(chef: tKnownValues; ignoriereWennBereitsVorhanden: boolean = false); procedure entferneKnecht(knecht: tKnownValues); + procedure entferneChef(chef: tKnownValues); end; function plus(a,b: tExtPoint): tExtPoint; @@ -63,15 +65,15 @@ implementation // tKnownValueArray ************************************************************ -constructor tKnownValues.create(chf: tKnownValues); +constructor tKnownValues.create(chef: tKnownValues); begin inherited create; fillchar(kvs,sizeOf(kvs),#0); fillchar(knechte,sizeOf(knechte),#0); add('π',pi); - chef:=chf; + fillchar(chefs,sizeOf(chefs),#0); if assigned(chef) then - chef.neuerKnecht(self); + neuerChef(chef); setLength(knechte,0); end; @@ -84,26 +86,26 @@ begin fillchar(knechte,sizeOf(knechte),#0); for i:=0 to length(original.kvs)-1 do add(original.kvs[i]); - chef:=original.chef; - if assigned(chef) then - chef.neuerKnecht(self); + for i:=0 to length(original.chefs)-1 do + neuerChef(original.chefs[i]); end; destructor tKnownValues.destroy; var - i: longint; + i,j: longint; begin + for i:=0 to length(kvs)-1 do + for j:=0 to length(knechte)-1 do + knechte[j].add(kvs[i],true); setLength(kvs,0); - for i:=0 to length(knechte)-1 do begin - knechte[i].chef:=chef; - if assigned(chef) then - chef.neuerKnecht(knechte[i]); + for i:=length(knechte)-1 downto 0 do begin + for j:=0 to length(chefs)-1 do + knechte[i].neuerChef(chefs[j],true); + knechte[i].entferneChef(self); end; setLength(knechte,0); - if assigned(chef) then begin - chef.entferneKnecht(self); - chef:=nil; - end; + for i:=length(chefs)-1 downto 0 do + entferneChef(chefs[i]); inherited destroy; end; @@ -119,12 +121,12 @@ begin end; end; -procedure tKnownValues.add(val: tKnownValue); +procedure tKnownValues.add(val: tKnownValue; ignoriereWennBereitsVorhanden: boolean = false); begin - add(val.name,val.value); + add(val.name,val.value,ignoriereWennBereitsVorhanden); end; -procedure tKnownValues.add(nam: string; val: extended); +procedure tKnownValues.add(nam: string; val: extended; ignoriereWennBereitsVorhanden: boolean = false); var i: longint; begin @@ -133,7 +135,10 @@ begin i:=length(kvs); setLength(kvs,length(kvs)+1); kvs[i].name:=nam; - end; + end + else + if ignoriereWennBereitsVorhanden then + exit; kvs[i].value:=val; end; @@ -160,10 +165,12 @@ begin i:=finde(nam); result:=i>=0; if result then - val:=kvs[i].value - else - if assigned(chef) then - result:=chef.extract(nam,val); + val:=kvs[i].value; + i:=0; + while (not result) and (i