Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Zugriffsverletzung ??? Ich kappiers nicht! (https://www.delphipraxis.net/22186-zugriffsverletzung-ich-kappiers-nicht.html)

faux 13. Mai 2004 18:57


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.

MathiasSimmack 13. Mai 2004 19:01

Re: Zugriffsverletzung ??? Ich kappiers nicht!
 
Vielleicht solltest du vor dem Zugriff prüfen ob das Array überhaupt entsprechend viele Einträge hat.

IngoD7 13. Mai 2004 19:03

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?

faux 13. Mai 2004 19:03

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... ^^

faux 13. Mai 2004 19:04

Re: Zugriffsverletzung ??? Ich kappiers nicht!
 
Zitat:

Zitat von IngoD7
Ist der "doppelte Index" an der Stelle Absicht?

Ja, weil ich auf das erste Zeichen des Strings zugreifen will, aber ohne dem Doppelarray also mitCommands[1] gehts genau so wenig... :?

glkgereon 13. Mai 2004 19:04

Re: Zugriffsverletzung ??? Ich kappiers nicht!
 
witzbold! :-)

du versuchst einen eindimenionalen array zweidimensional anzusprechen!

mirage228 13. Mai 2004 19:05

Re: Zugriffsverletzung ??? Ich kappiers nicht!
 
Zitat:

Zitat von glkbkk
witzbold! :-)

du versuchst einen eindimenionalen array zweidimensional anzusprechen!

Nein, er versucht auf das erste Zeichen im String der ersten Array-Stelle zuzugreifen :mrgreen:

faux 13. Mai 2004 19:05

Re: Zugriffsverletzung ??? Ich kappiers nicht!
 
Zitat:

Zitat von glkbkk
witzbold! :-)

du versuchst einen eindimenionalen array zweidimensional anzusprechen!

nein, einen zweidimensionalen array würde man mit [1,1] ansprechen...

faux 13. Mai 2004 19:08

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
---------------------------

glkgereon 13. Mai 2004 19:08

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.


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:23 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz