![]() |
[Delphi 2010] Interner Fehler
Hallo,
ich habe eine funktion von c# nach delphi übersetzt und benutzte dazu "TDictionary<TKey,TValue>", kompilieren lässt sich das ganze ohne probleme. beim linken kommt dann: [DCC Fataler Fehler] F2084 Interner Fehler: L1737. jemand ne idee woran das liegen kann? :gruebel: auslöser scheinen die folgenden zeilen zu sein:
Delphi-Quellcode:
P.S. Update 4 hab ich drauf.dictionary := Generics.Collections.TDictionary<Char, Cardinal>.Create; dictionary2 := Generics.Collections.TDictionary<Integer, Cardinal>.Create; gruß, cookie |
Re: [Delphi 2010] Interner Fehler
hm.
Versuche mal, die Namespaces wegzulassen:
Delphi-Quellcode:
Das sollte funktionieren.
dictionary := TDictionary<Char, Cardinal>.Create;
dictionary2 := TDictionary<Integer, Cardinal>.Create; //edit: Also folgender Code compiliert, linkt und startet bei mir wie erwartet:
Delphi-Quellcode:
procedure Tfrm_Main.Test;
var dictionary : TDictionary<Char, Cardinal>; dictionary2 : TDictionary<Integer, Cardinal>; begin dictionary := Generics.Collections.TDictionary<Char, Cardinal>.Create; dictionary2 := Generics.Collections.TDictionary<Integer, Cardinal>.Create; end; |
Re: [Delphi 2010] Interner Fehler
namespaces weglassen bringt nix, habs gerade getestet.
bei mir startet das auch wenn ich die funktion nirgens benutze, wenn ich die funktion irgenwo benutze kommt der fehler. |
Re: [Delphi 2010] Interner Fehler
Dann zeig mal den Zugriff
|
Re: [Delphi 2010] Interner Fehler
Versuch mal einen eigenen Typ für "TDictionary<Char, Cardinal>" zu machen und benutze diesen.
|
Re: [Delphi 2010] Interner Fehler
also ich mache das folgendermassen.
hier das original in c#:
Code:
das hab ich mir mit hilfe von refector daraus zusammen gereimt. meine c# kenntnisse sind = 0, das muss ich dazu sagen.
public static uint EstimatePasswordBits(char[] vPasswordChars)
{ bool bChLower = false, bChUpper = false, bChNumber = false; bool bChSimpleSpecial = false, bChExtSpecial = false, bChHigh = false; bool bChEscape = false; Dictionary<char, uint> vCharCounts = new Dictionary<char, uint>(); Dictionary<int, uint> vDifferences = new Dictionary<int, uint>(); double dblEffectiveLength = 0.0; Debug.Assert(vPasswordChars != null); if(vPasswordChars == null) throw new ArgumentNullException("vPasswordChars"); for(int i = 0; i < vPasswordChars.Length; i++) // Get character types { char tch = vPasswordChars[i]; if(tch < ' ') bChEscape = true; if((tch >= 'A') && (tch <= 'Z')) bChUpper = true; if((tch >= 'a') && (tch <= 'z')) bChLower = true; if((tch >= '0') && (tch <= '9')) bChNumber = true; if((tch >= ' ') && (tch <= '/')) bChSimpleSpecial = true; if((tch >= ':') && (tch <= '@')) bChExtSpecial = true; if((tch >= '[') && (tch <= '`')) bChExtSpecial = true; if((tch >= '{') && (tch <= '~')) bChExtSpecial = true; if(tch > '~') bChHigh = true; double dblDiffFactor = 1.0; if(i >= 1) { int iDiff = (int)tch - (int)vPasswordChars[i - 1]; if(vDifferences.ContainsKey(iDiff) == false) vDifferences.Add(iDiff, 1); else { vDifferences[iDiff] = vDifferences[iDiff] + 1; dblDiffFactor /= (double)vDifferences[iDiff]; } } if(vCharCounts.ContainsKey(tch) == false) { vCharCounts.Add(tch, 1); dblEffectiveLength += dblDiffFactor; } else { vCharCounts[tch] = vCharCounts[tch] + 1; dblEffectiveLength += dblDiffFactor * (1.0 / (double)vCharCounts[tch]); } } uint charSpace = 0; if(bChEscape) charSpace += (uint)CharSpaceBits.Escape; if(bChUpper) charSpace += (uint)CharSpaceBits.Alpha; if(bChLower) charSpace += (uint)CharSpaceBits.Alpha; if(bChNumber) charSpace += (uint)CharSpaceBits.Number; if(bChSimpleSpecial) charSpace += (uint)CharSpaceBits.SimpleSpecial; if(bChExtSpecial) charSpace += (uint)CharSpaceBits.ExtendedSpecial; if(bChHigh) charSpace += (uint)CharSpaceBits.High; if(charSpace == 0) return 0; double dblBitsPerChar = Math.Log((double)charSpace) / Math.Log(2.0); return (uint)Math.Ceiling(dblBitsPerChar * dblEffectiveLength); }
Delphi-Quellcode:
function EstimatePasswordBits(vPasswordChars: string): Cardinal;
var flag, flag2, flag3, flag4, flag5, flag6, flag7: Boolean; dictionary: TDictionary<Char, Cardinal>; dictionary2: TDictionary<Integer, Cardinal>; i, num, num3, num4, num5 : Integer; num6 : Extended; key: Char; begin flag := False; flag2 := False; flag3 := False; flag4 := False; flag5 := False; flag6 := False; flag7 := False; num := 0; dictionary := TDictionary<Char, Cardinal>.Create; dictionary2 := TDictionary<Integer, Cardinal>.Create; if (vPasswordChars = '') then raise ArgumentNullException.Create('vPasswordChars'); i := 0; while i < Length(vPasswordChars) do begin key := vPasswordChars[i]; if (key < ' ') then flag7 := True; if ((key >= 'A') and (key <= 'Z')) then flag2 := True; if ((key >= 'a') and (key <= 'z')) then flag := True; if ((key >= '0') and (key <= '9')) then flag3 := True; if ((key >= ' ') and (key <= '/')) then flag4 := True; if ((key >= ':') and (key <= '@')) then flag5 := True; if ((key >= '[') and (key <= '`')) then flag5 := True; if ((key >= '{') and (key <= '~')) then flag5 := True; if (key > '~') then flag6 := True; num3 := 1; if (i >= 1) then begin num4 := (Ord(key) - Ord(vPasswordChars[i - 1])); if (not dictionary2.ContainsKey(num4)) then dictionary2.Add(num4, 1) else begin dictionary2.Items[num4] := dictionary2.Items[num4] + 1; num3 := num3 div (dictionary2.Items[num4]) end end; if (not dictionary.ContainsKey(key)) then begin dictionary.Add(key, 1); inc(num, num3) end else begin dictionary.Items[key] := dictionary.Items[key] +1; inc(num, (num3 * (1 div (dictionary.Items[key] )))) end; inc(i) end; num5 := 0; if (flag7) then inc(num5, 60); if (flag2) then inc(num5, $1A); if (flag) then inc(num5, $1A); if (flag3) then inc(num5, 10); if (flag4) then inc(num5, $10); if (flag5) then inc(num5, $11); if (flag6) then inc(num5, $70); if (num5 = 0) then begin Result := 0; exit end; num6 := round(Math.LogN(1, (num5))) / round(Math.LogN(1, 2)); begin Result := Math.Ceil(num6 * num); exit end end;
Delphi-Quellcode:
...
var s: string; bits: cardinal; begin ... bits := EstimatePasswordBits(s); ... end; wie gesagt compilieren lässt sich das, nur nicht aufrufen. |
Re: [Delphi 2010] Interner Fehler
Und wo knallt es genau?
|
Re: [Delphi 2010] Interner Fehler
Zitat:
|
Re: [Delphi 2010] Interner Fehler
Hast du mal bei EM bei den Bug Reports geschaut, ob schon jemnad den Fehler gemeldet hat bzw. ihn gemeldet?
|
Re: [Delphi 2010] Interner Fehler
Delphi-Quellcode:
Divison durch 0.
var num6 : Extended;
-.. num6 := round(Math.LogN(1, (num5))) / round(Math.LogN(1, 2)); |
Re: [Delphi 2010] Interner Fehler
Zitat:
edit: so hab eben bei em geschaut, da gibt es einen bug report. das passiert wenn man generics in eine andere unit auslagert. wenn ichs in die unit packe in der ichs aufrufe gehts. |
Re: [Delphi 2010] Interner Fehler
Math.LogN(1, 2)
Stellt den Logarithmus von 2 zur Basis 1 dar. Man kann einen Log zur beliebigen Basis einfach berechnen :
Delphi-Quellcode:
Rechne mal jeden einzelen Term aus mit beliebigen Werten für n, jedoch Basis = 1.
Log(basis, n) = logk(n) / logk(basis);
Dabei ist logk ein beliebiger Logarithmus (z.b. 2 (=ln) oder auch 10) |
Re: [Delphi 2010] Interner Fehler
Delphi-Quellcode:
so?
num6 := LN(num5) / LN(2);
|
Re: [Delphi 2010] Interner Fehler
Was macht denn die Zeile im Hinblick darauf, was die Funktion zurückliefern soll?
|
Re: [Delphi 2010] Interner Fehler
steht doch weiter oben.
|
Re: [Delphi 2010] Interner Fehler
Diese Berechnung in der einen Zeile hat einen eindeutigen Sinn. Welcher ist das? Weißt du es?
|
Re: [Delphi 2010] Interner Fehler
Delphi-Quellcode:
ging hier um den natürlichen log. hatte das in math.pas gesucht und nicht gefunden. war in systems.pas.
num6 := LN(num5) / LN(2);
so gehts alles in ordnung. :) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:21 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz