From 8e406ec976debaf8f0af6ae167d91f537f5fca20 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 28 Jan 2016 15:40:31 +0100 Subject: Editieren der ausgewählten Lösung nun möglich MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unit2.pas | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 204 insertions(+), 46 deletions(-) (limited to 'unit2.pas') diff --git a/unit2.pas b/unit2.pas index e75d847..edd6b70 100644 --- a/unit2.pas +++ b/unit2.pas @@ -24,6 +24,7 @@ type function count: longint; procedure add(x: extended; cnt: longint); overload; procedure add(x: string; cnt: longint); overload; + function toStr(llNum: longint): string; procedure dump(sl: tStrings); property inhalt[i: longint]: extended read rInhalt; default; @@ -59,10 +60,14 @@ type write wFrequenz; function ordnungNichtDirektEinstellen: boolean; inline; procedure anzeigen(sl: tStrings); + procedure uebersicht(sl: tStrings); + procedure sortenreinAnzeigen(rsl,csl: tStrings); function dump: string; function weite: longint; function cWaehlen(idx: longint; var nutzen: extended): boolean; // Erfolg? - function rsWaehlen(idx: longint): boolean; dynamic; abstract; // Erfolg? + function rsWaehlen(idx: longint): boolean; dynamic; abstract; // Erfolg? + procedure allesZurueckLegen; + function findeRsZuAnderenCs(_cs,_rs: tStrings): boolean; // Erfolg? end; tHochpass = class(tFilter) function rsWaehlen(idx: longint): boolean; override; @@ -86,6 +91,7 @@ type function ordnungsSchritt: boolean; function auswahlSchritt(minNutzen: extended; callBack: tNotifyEvent): boolean; procedure anzeigen(sl: tStrings); + procedure filterUebersicht(sl: tStrings); function dump: string; function dumpWeite: string; end; @@ -101,6 +107,8 @@ type function minNutzen(cnt: longint): extended; end; +function strToScientific(s: string): extended; inline; +function scientificToStr(x: extended): string; inline; function liesExtendedArray(sl: tStrings): tMyExtendedArray; overload; function liesExtendedArray(sl: tStrings; suf: string): tMyExtendedArray; overload; procedure liesExtendedArray(sl: tStrings; suf: string; var arr: tMyExtendedArray); overload; @@ -201,25 +209,17 @@ begin end; procedure tMyExtendedArray.add(x: string; cnt: longint); -const - edg: array[0..13] of string = ('k','M','G','T','P','E','m','µ','n','p','f','a','y','z'); - fak: array[0..13] of extended = (1e3,1e6,1e9,1e12,1e15,1e18,1e-3,1e-6,1e-9,1e-12,1e-15,1e-18,1e-21,1e-24); -var - i: longint; - c: char; begin - if decimalseparator='.' then - c:=',' - else - c:='.'; - while pos(c,x)>0 do - x[pos(c,x)]:=decimalseparator; - for i:=0 to length(edg)-1 do - if pos(edg[i],x)>0 then begin - add(strtofloat(trim(leftStr(x,pos(edg[i],x)-1)))*fak[i],cnt); - exit; - end; - add(strtofloat(trim(x)),cnt); + add(strToScientific(x),cnt); +end; + +function tMyExtendedArray.toStr(llNum: longint): string; +begin + if (llNum<0) or (llNum>=length(zahlen)) then begin + result:='nan ('+inttostr(llNum)+') '; + exit; + end; + result:=scientificToStr(zahlen[llNum]) end; procedure tMyExtendedArray.dump(sl: tStrings); @@ -335,16 +335,7 @@ var i: longint; begin if _ordnung<>o then begin - for i:=0 to length(Rs)-1 do - if Rs[i].i>=0 then begin - inc(ars.anzahlen[Rs[i].i]); - Rs[i].i:=-1; - end; - for i:=0 to length(Cs)-1 do - if Cs[i]>=0 then begin - inc(acs.anzahlen[Cs[i]]); - Cs[i]:=-1; - end; + allesZurueckLegen; _ordnung:=o; if assigned(gegenstueck) then @@ -375,28 +366,39 @@ end; procedure tFilter.anzeigen(sl: tStrings); var - s: string; i: longint; +begin + uebersicht(sl); + for i:=0 to ordnung-1 do + sl.add( + ' R'+inttostr(i+1)+' = '+scientificToStr(Rs[i].x)+'Ω von '+ars.toStr(Rs[i].i)+'Ω,'+ + ' C'+inttostr(i+1)+' = '+acs.toStr(Cs[i])+'F' + ); +end; + +procedure tFilter.uebersicht(sl: tStrings); +var + s: string; begin if self is tHochpass then s:='Hochpass' else s:='Tiefpass'; if assigned(gegenstueck) then s:=s+''''; - sl.add(s+' '+inttostr(ordnung)+'. Ordnung ('+floattostr(frequenz)+' Hz)'); - for i:=0 to ordnung-1 do begin - s:=' R'+inttostr(i+1)+' = '+floattostr(Rs[i].x)+' Ω von '; - if (Rs[i].i>=0) and - (Rs[i].i=0 then begin + inc(ars.anzahlen[Rs[i].i]); + Rs[i].i:=-1; + end; + for i:=0 to length(Cs)-1 do + if Cs[i]>=0 then begin + inc(acs.anzahlen[Cs[i]]); + Cs[i]:=-1; + end; +end; + +function tFilter.findeRsZuAnderenCs(_cs,_rs: tStrings): boolean; +var + tmpArs,tmpAcs: tMyExtendedArray; + tmpRs: tExtendedLongintArray; + tmpCs: tLongintArray; + tmpVals: array of extended; + i: longint; +begin + result:=true; + + tmpArs:=ars; // kleiner Hack + tmpAcs:=acs; + + setlength(tmpRs,length(Rs)); + for i:=0 to length(tmpRs)-1 do + tmpRs[i]:=Rs[i]; + setlength(tmpCs,length(Cs)); + for i:=0 to length(tmpCs)-1 do + tmpCs[i]:=Cs[i]; + + ars:=tMyExtendedArray.create; + for i:=0 to length(Rs)-1 do // Widerstände nach Soll generieren + if Rs[i].i>=0 then begin + ars.add(tmpArs.zahlen[Rs[i].i],1); + Rs[i].i:=-1; + end; + + if ars.count<>ordnung then begin + _rs.add('Ich habe '+inttostr(ars.count)+' Widerstände zur Verfügung statt erwarteter '+inttostr(ordnung)+'.'); + result:=false; + end; + + setlength(tmpVals,0); + acs:=tMyExtendedArray.create; + for i:=0 to _cs.count-1 do // Kondensatoren aus Tabelle auslesen + if rightStr(trim(_cs[i]),1)='F' then begin + if length(tmpVals)>=ordnung then begin + _rs.add('zu viele Kondensatoren!'); + result:=false; + break; + end; + setlength(tmpVals,length(tmpVals)+1); + tmpVals[length(tmpVals)-1]:=strToScientific(leftStr(_cs[i],length(_cs[i])-1)); + acs.add(tmpVals[length(tmpVals)-1],1); + end; + if length(tmpVals)0 do + s[pos(c,s)]:=decimalseparator; + for i:=0 to length(edg)-1 do + if pos(edg[i],s)>0 then begin + result:=strtofloat(trim(leftStr(s,pos(edg[i],s)-1)))*fak[i]; + exit; + end; + result:=strtofloat(trim(s)); +end; + +function scientificToStr(x: extended): string; +var + f: extended; + i: longint; +begin + f:=1; + while abs(x)>=0.99e3 do begin + x:=x*1e-3; + f:=f*1e3; + end; + if x<>0 then + while abs(x)<0.99 do begin + x:=x*1e3; + f:=f*1e-3; + end; + for i:=0 to length(fak)-1 do + if abs(f/fak[i]-1)<0.1 then begin + result:=floattostr(x); + if length(result)-pos(decimalSeparator,result+decimalSeparator)>3 then + delete(result,pos(decimalSeparator,result+decimalSeparator)+4,length(result)); + result:=result+' '+edg[i]; + exit; + end; + result:=floattostr(x*f); + if length(result)-pos(decimalSeparator,result+decimalSeparator)>3 then + delete(result,pos(decimalSeparator,result+decimalSeparator)+4,length(result)); + result:=result+' '; +end; + function liesExtendedArray(sl: tStrings): tMyExtendedArray; begin result:=liesExtendedArray(sl,''); -- cgit v1.2.3-54-g00ecf