Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 07.10.10 07:24 
Hi, Delpher,
(wie) kann ich in der folgenden Proc den Zählerwert 6 allgemein mit componentcount übergeben?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TBuchMain.abelleverbergen1Click(Sender: TObject);
var  n  : Byte;  // oder shortint, integer ist viel zu groß;
    dbg : TComponent;
begin
  for n := 1 to 6 do    //componentcount?
  begin
    dbg := FindComponent('DBGrid'+ inttostr(n));
    with TDBGrid(dbg) do visible := false;
  end;
  if dbedit1.Visible then dbedit1.Visible := false;
  if maskedit1.visible then maskedit1.Visible := false;

  if groupbox8.Visible then KlassenMatrixSchliessen(Self)     // Klassenlisten
  else
  if groupbox4.Visible then                                   // and. Tabellen
  begin
    groupbox4.Visible := false;
    groupbox2.Visible := true;  {groupbox2.Height := splitter1.MinSize; splitter1.Visible := true;}
  end;
  labelAnz.Caption := '0'; label45.Caption := '0'; groupbox4.caption := '';
  if tntStringgrid4.Visible = false then tntStringgrid4.Visible := true;
end;


Danke, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Do 07.10.10 07:43 
Ja, aber dann prüfen, ob Components[i] auch ein TDBGrid ist
ausblenden Delphi-Quelltext
1:
If Components[i] is TDBGrid then					

Ich packe übrigens die zu verbergenden Controls auf ein Panel und schalte dieses Panel um.
Weiterhin brauchst Du nicht zu prüfen, ob ein Control sichtbar ist. Mach es einfach unsichtbar.

Noch besser: Schreibe eine Methode, die deine Controls an bzw. ausschaltet.

Noch viel besser: Wenn es geht, verberge die Controls nicht, sondern setze sie auf 'Enabled := False'. Der Anwender sollte nicht durch Zauberei verwirrt (sichtbar/unsichtbar) werden. Leider klappt das nicht mit allen Controls, weil einige sich partout weigern, ihren Status visuell anzuzeigen, z.B. durch graue Schrift o.ä.

_________________
Na denn, dann. Bis dann, denn.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 07.10.10 09:09 
Hi, Alzi,
danke für deine schnelle Antwort!
ich habe jetzt den folgenden Code (mit der Fehlermeldung: Listenindex überschreitet das Maximum 1).

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TBuchMain.abelleverbergen1Click(Sender: TObject);
var  n  : Byte;  // oder shortint, integer ist viel zu groß;
    dbg : TComponent;
    FoMain : TForm;
begin
  FoMain := TForm.Create(self);
  for n := 0 to FoMain.ComponentCount-1 do  // z.B. 6
  begin
    if (FoMain.Components[n+1is TDBGrid) then
    begin
      dbg := FindComponent('DBGrid'+ inttostr(n+1));
      with TDBGrid(dbg) do visible := false;
    end;
  end;
....


Kannnst noch mal nachhelfen?
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 07.10.10 09:22 
statt FoMain.Components[n+1] FoMain.Components[n]
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 07.10.10 09:25 
Hi, Bummi,
leider jetzt mit der Fehlermeldung:
Listenindex überschreitet das Maximum 0.
Ups, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 07.10.10 09:52 
1.) nimm einen Integer für n der kennt negative Werte
2.) vereinfache
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button1Click(Sender: TObject);

var  n  : Integer;  // oder shortint, integer ist viel zu groß;
    FoMain : TForm2;
begin
  FoMain := TForm2.Create(self);
  for n := 0 to FoMain.ComponentCount-1 do  // z.B. 6
  begin
    if (FoMain.Components[n] is TDBGrid) then
    begin
      TDBGrid(FoMain.Components[n]).visible := false;
    end;
  end;

end;
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 07.10.10 10:17 
Hi, bummi,
jetzt klappt es.
ich habe noch 2 Fragen: Wieso TForm2 und -
wie kann ich dir ein "Danke" aussprechen?
Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 07.10.10 10:21 
1.) TForm2 war bei mir zum Debuggen drin, Du nimmst natürlich Deine klasse Tform oder TMeinDBGridEnthaltendes Form
2.) keine Ahnung ;-)

Für diesen Beitrag haben gedankt: D. Annies
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 07.10.10 10:39 
okay,
nun hast du aber schon 10 danke erhalten und es soll gern das 11. werden.
mal sehen, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Do 07.10.10 10:49 
Unten rechts in jedem Beitrag befindet sich ein "Danke" Button ;)

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 07.10.10 11:16 
alter Schwede, ich sehe es nicht. Kannst du nochmal helfen?
Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Do 07.10.10 14:14 
user profile iconbummi hat folgendes geschrieben Zum zitierten Posting springen:
1.) nimm einen Integer für n der kennt negative Werte

Nicht, dass das jetzt irgendwas damit zu tun hätte... in 0..5 sind eher wenige negative Zahlen.
Das größte "Problem" was man sich damit einhandelt dürfte wohl sein, dass Byte-Zugriffe auf 32-Bit-CPUs langsam sind. Und auf 64bit erst...

user profile iconD. Annies hat folgendes geschrieben Zum zitierten Posting springen:
alter Schwede, ich sehe es nicht. Kannst du nochmal helfen?
Gruß, Detlef

Der ist da nur, wenn du im Profil AJAX aktiviert hast. (Einstellungen->Erweitert->ziemlich weit unten)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."

Für diesen Beitrag haben gedankt: D. Annies
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 07.10.10 16:56 
@Martok

for n := 0 to FoMain.ComponentCount-1

gibt bei ein
Var n:Byte

durchaus sein beschriebenes Problem wenn Componentcount 0 ist

SIM:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var
  n:Byte;
  x:Integer;
begin
   x := -1;
   for n := 0 to x do memo1.Lines.add(IntToStr(n));

end;
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Do 07.10.10 17:06 
Oh. Stimmt, da hast du recht.
Ist zwar hier etwas konstruiert, aber man will ja eigentlich robusten Code schreiben.

Wie auch immer: ohne Not Byte verwenden ist eh Quatsch. Offenbar sogar aus mehreren Gründen ;)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Fr 08.10.10 04:54 
user profile iconMartok hat folgendes geschrieben Zum zitierten Posting springen:
Ist zwar hier etwas konstruiert, aber man will ja eigentlich robusten Code schreiben.
Leere Form?

_________________
Na denn, dann. Bis dann, denn.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 08.10.10 14:40 
user profile iconalzaimar hat folgendes geschrieben Zum zitierten Posting springen:
user profile iconMartok hat folgendes geschrieben Zum zitierten Posting springen:
Ist zwar hier etwas konstruiert, aber man will ja eigentlich robusten Code schreiben.
Leere Form?
Auf der Form im Anfangsposting war noch ganz viel anderes Zeugs drauf...

Stimmt, im letzten Code sind dann gar keine Komponenten mehr, nur noch ein leeres TForm. Wer lesen kann... :roll:

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."