Autor Beitrag
ebi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Di 12.11.02 21:33 
Ich habe folgende Procedure geschreiben:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
procedure TForm1.ClientsErstellen();
var i: integer;
begin

  for i := 1 to maxBenutzer do
  begin
    Client [i].Free;
  end;

  for i := 1 to ClientAnzahl do
  begin
    Client [i] := TClientSocket.Create(Form1);
    Client [i].Port := Port;
    Client [i].Address := Benutzer[i].IP;

    Client [i].Name := 'Client' + IntToStr(i);

    Client [i].OnError := ClientError ;

    Client [i].Open;

  end;

end;



wenn ich einen Benutzer hinzufüge und wieder diese Prozedur aufrufe, ist das kein Problem.
ABER: wenn ich einen Benutzer weniger habe als vorher und dann wieder diese Prozedur aufrufe macht der mir einen Fehler (EAccessViolation).


Was muß ich anders machen, damit dieser Fehler nicht entsteht???

_________________
Greetings EBI
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Mi 13.11.02 07:39 
Hi
Aus'm Stehgreif heraus würde ich sagen, du solltest mal deine Variable maxBenutzer prüfen. Eventuell ist die immer noch im 1 zu hoch und wenn du dann versuchst das Client[i].Free auszuführen, kracht's.
Ausserdem siehts so aus, als würden maxBenutzer und ClientAnzahl jeweils die gleichen Werte darstellen. Warum zwei unterschiedliche Variablen.

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
ebi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Mi 13.11.02 16:46 
MaxBenutzer ist eine Konstante!!!

Wieso sagt mir keiner sofort, dass ich nicht Komponenten.free anwenden kann, wenn die Komponenten nicht vorhanden sind?
In der Hilfe stand Delphi würde prüfen ob die Komp. vorhanden sind und dann eventuell diese freigeben.


Die Procedur funzt:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure TForm1.ClientsErstellen(); 
var i: integer; 
begin 

  for i := 1 to {------}ClientAnzahlAlt {------} do 
  begin 
    Client [i].Free; 
  end; 

  for i := 1 to ClientAnzahl do 
  begin 
    Client [i] := TClientSocket.Create(Form1); 
    Client [i].Port := Port; 
    Client [i].Address := Benutzer[i].IP; 

    Client [i].Name := 'Client' + IntToStr(i); 

    Client [i].OnError := ClientError ; 

    Client [i].Open; 

  end; 

  {------} ClientAnzahlAlt := ClientAnzahl; {-----} 

end;



Trotzdem an alle danke!

_________________
Greetings EBI
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mi 13.11.02 17:08 
Zitat:
wenn ich einen Benutzer hinzufüge und wieder diese Prozedur aufrufe, ist das kein Problem.


:shock: :?: Wie soll man denn das verstehen? Rufst du so eine Prozedur auf, wenn ein Client dazukommt?

Ich würde dir erst einmal raten, in einer Prozedur ClientsErstellen keine Clients freizugeben. Das eine hat mit dem anderen nix zu tun.

Cu,
Udontknow