![]() |
Zugriffsverletzung ??? Ich kappiers nicht!
Hallo!
Also ich hab grad ein totales Blackout! Ich kappiers nicht. Wiso tritt denn da eine Zugriffsverletzung auf?
Delphi-Quellcode:
unit Unit2;
interface uses SysUtils, AgentObjects_TLB; const LMax = 2; type TCommandAction = (ccTrue, ccFalse, ccNoCommand); function Inizialize(const Command: String; AgentItem: IAgentCtlCharacterEx): TCommandAction; function ActCommand(Commands: Array of String; AgentItem: IAgentCtlCharacterEx): TCommandAction; implementation function Inizialize(const Command: String; AgentItem: IAgentCtlCharacterEx): TCommandAction; var Commands: Array[1..LMax] of String; i, j: Integer; begin j := 0; if Length(Command) > 0 then begin for i := 0 to Length(Command) - 1 do if Command[i] <> ' ' then Commands[j] := Commands[j] + Command[i] else if j < Lmax then inc(j) else break; Result := ActCommand(Commands, AgentItem); end else Result := ccFalse; end; function ActCommand(Commands: Array of String; AgentItem: IAgentCtlCharacterEx): TCommandAction; begin if Commands[1][1] = ':' then //Hier tritt sie auf.... hm.... begin result := ccTrue; end else result := ccNoCommand; end; end. |
Re: Zugriffsverletzung ??? Ich kappiers nicht!
Vielleicht solltest du vor dem Zugriff prüfen ob das Array überhaupt entsprechend viele Einträge hat.
|
Re: Zugriffsverletzung ??? Ich kappiers nicht!
Ist der "doppelte Index" an der Stelle Absicht?
//edit: Schlecht ausgedrückt .... Ich vermute der String ist leer. Kann das sein? |
Re: Zugriffsverletzung ??? Ich kappiers nicht!
Ja aber der Array der übergeben wird is ja mit [1..2] deklariert, also muss das Element [1] ja verfügbar sein... ^^
|
Re: Zugriffsverletzung ??? Ich kappiers nicht!
Zitat:
|
Re: Zugriffsverletzung ??? Ich kappiers nicht!
witzbold! :-)
du versuchst einen eindimenionalen array zweidimensional anzusprechen! |
Re: Zugriffsverletzung ??? Ich kappiers nicht!
Zitat:
|
Re: Zugriffsverletzung ??? Ich kappiers nicht!
Zitat:
|
Re: Zugriffsverletzung ??? Ich kappiers nicht!
Die Fehlermeldung lautet übrigens so:
Code:
---------------------------
Benachrichtigung über Debugger-Exception --------------------------- Im Projekt Project1.exe ist eine Exception der Klasse EAccessViolation aufgetreten. Meldung: 'Zugriffsverletzung bei Adresse 00473B03 in Modul 'Project1.exe'. Lesen von Adresse 00000000'. Prozess wurde angehalten. Mit Einzelne Anweisung oder Start fortsetzen. --------------------------- OK --------------------------- |
Re: Zugriffsverletzung ??? Ich kappiers nicht!
achso, aber ich weiss nict, ob das geht...
versuchs mal so:
Delphi-Quellcode:
unit Unit2;
interface uses SysUtils, AgentObjects_TLB; const LMax = 2; type TCommandAction = (ccTrue, ccFalse, ccNoCommand); function Inizialize(const Command: String; AgentItem: IAgentCtlCharacterEx): TCommandAction; function ActCommand(Commands: Array of String; AgentItem: IAgentCtlCharacterEx): TCommandAction; implementation function Inizialize(const Command: String; AgentItem: IAgentCtlCharacterEx): TCommandAction; var Commands: Array[1..LMax] of String; i, j: Integer; begin j := 0; if Length(Command) > 0 then begin for i := 0 to Length(Command) - 1 do if Command[i] <> ' ' then Commands[j] := Commands[j] + Command[i] else if j < Lmax then inc(j) else break; Result := ActCommand(Commands, AgentItem); end else Result := ccFalse; end; function ActCommand(Commands: Array of String; AgentItem: IAgentCtlCharacterEx): TCommandAction; var hilfsstring:string; begin //hier die änderung!! hilfsstring:=Commands[1]; if hilfsstring[1] = ':' then //Hier tritt sie auf.... hm.... begin result := ccTrue; end else result := ccNoCommand; end; end. |
Re: Zugriffsverletzung ??? Ich kappiers nicht!
Ist das abgefragte Feld an der Stelle vielleicht ein leerer String? Dann geht die Abfrage auf ein bestimmtes Zeichen des Strings in die Hose.
|
Re: Zugriffsverletzung ??? Ich kappiers nicht!
aarghh, ich idiot!!!
wahrscheinlich isses das: du hast 2 variablen Commands, er weiss nit, welche er nehmen soll wobei, stand nicht mal innem buch, das die lokale die globale übergeht? ausprobieren |
Re: Zugriffsverletzung ??? Ich kappiers nicht!
Delphi-Quellcode:
hab das ausgebessert. jetzt weiß ich wieso die zugriffsverletzung auftritt, der array ist leer... *gg*
unit Unit2;
interface uses SysUtils, AgentObjects_TLB; const LMax = 2; type TCommandAction = (ccTrue, ccFalse, ccNoCommand); function Inizialize(const Command: String; AgentItem: IAgentCtlCharacterEx): TCommandAction; function ActCommand(Commands: Array of String; AgentItem: IAgentCtlCharacterEx): TCommandAction; implementation function Inizialize(const Command: String; AgentItem: IAgentCtlCharacterEx): TCommandAction; var Commands: Array[1..LMax] of String; i, j: Integer; begin j := 0; //Hier ist EIN Fehler, weil der Array bei 1 beginnt, aber der ist anscheiden egal.. if Length(Command) > 0 then begin for i := 0 to Length(Command) - 1 do //ARG!! der index eines strings beginnt bei 1 und nicht bei 0!!! aber wieso gibz da keine exception? if Command[i] <> ' ' then Commands[j] := Commands[j] + Command[i] //hier, j ist 0 und er schreibt aber anstandslos auf den array, wie das? else if j < Lmax then inc(j) else break; Result := ActCommand(Commands, AgentItem); end else Result := ccFalse; end; function ActCommand(Commands: Array of String; AgentItem: IAgentCtlCharacterEx): TCommandAction; begin if Commands[1][1] = ':' then //Hier tritt sie auf.... hm.... begin result := ccTrue; end else result := ccNoCommand; end; end. |
Re: Zugriffsverletzung ??? Ich kappiers nicht!
Zitat:
1. mal sind beide variablen lokal und nicht global. denn die eine ist im var teil und die andere in der deklaration... 2. mal heißt eine commands und die andere nur command (ohne s)... *gg* |
Re: Zugriffsverletzung ??? Ich kappiers nicht!
hmmm, jetzt wo dus sagst seh ichs auch... :gruebel:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:47 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