Dziwny problem: Panel i ComponentCount...

0

Cześć wszystkim...

Na Panel1-u mam kilka komponentów Edit...
Zastanawiam się dlaczego kompilator nie wchodzi mi w taką oto pętlę..

  for i := 0 to Panel1.ComponentCount - 1 do
    if Components[i] is TEdit then
      TEdit(Components[i]).Enabled := False;

Z Form.Panel1 też próbowałem...
Pzdr

0

Cześć wszystkim...

Na Panel1-u mam kilka komponentów Edit...
Zastanawiam się dlaczego kompilator nie wchodzi mi w taką oto pętlę..

  for i := 0 to Panel1.ComponentCount - 1 do
    if Components[i] is TEdit then
      TEdit(Components[i]).Enabled := False;

Z Form.Panel1 też próbowałem...
Pzdr

Spróbuj po THEN dać coś takiego:

(components[i] as TEdit).Enabled:=false
0
for i := 0 to Panel1.ComponentCount - 1 do
    if Panel1.Components[i] is TEdit then
      TEdit(Panel1.Components[i]).Enabled := False;
0

albo, nawiązując do Juhasa,

for i := 0 to Panel1.ComponentCount - 1 do
    if Panel1.Components[i] is TEdit then
      (Panel1.Components[i] as Tedit).Enabled := False; 

efekt ten sam

0

Mam podobny problem. Tak dla testów do innego programu unieściłem sobie na formatce panel a w nim 3 edity. Program ma sprawdzać czy są one wypełnione, czyli czy nie są puste. Kod wygląda tak:

procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
for i:=0 to Panel1.ComponentCount-1 do
begin
if Panel1.Components[i] is TEdit then
if (Panel1.Components[i] as TEdit).Text = '' then ShowMessage('wypelnij edity');
end;
end;

Nie rozumiem dlaczego program nie wchodzi w petle for ... co jest nie tak ??

0

Zrób tak:

procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
  for i:=0 to ComponentCount-1 do

    if (Components[i] is TEdit) then
      if (Components[i] as TEdit).Text = '' then ShowMessage('wypelnij edity');
    end;

Nie wpisuj

Panel.ComponentCount-1 tylko samo ComponentCount-1

i analogicznie w innych miejscach tak samo zrób. Pozdro... [browar]

0

Zrób tak:

procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
  for i:=0 to ComponentCount-1 do

    if (Components[i] is TEdit) then
      if (Components[i] as TEdit).Text = '' then ShowMessage('wypelnij edity');
    end;

Nie wpisuj

Panel.ComponentCount-1 tylko samo ComponentCount-1

i analogicznie w innych miejscach tak samo zrób. Pozdro... [browar]

raczej Panel1 dobrze że jest bo tak wyszuka komponenty na całej formie a chyba chodzi o komponenty z Panelu 1, a tak nawiasem ja bym dał ShowMessage w begin
i do niego dopisał jeszcze exit; bo inaczej jeśli wszystkie edity będą puste to alert wyświetli się 3 razy, zamiast raz

0

Dzięki za rady, nic jednak w ten sposób nie mogłem wskórać. Zrobiłem to tak:

for i := 0 to Form1.ComponentCount-1 do
  begin
    if Form1.Components[i] is TLabeledEdit then
      if (Form1.Components[i] as TLabeledEdit).Text = '' then
        if (Form1.Components[i] as TLabeledEdit).Parent = Panel1 then
        begin
          MessageDlg('Nie wypelnione pole ' + (Form1.Components[i] as TLabeledEdit).EditLabel.Caption, mtInformation, [mbOK], 0);
          pusty_edit := true;
        end;
  end;

Piszę tak dla formalności :D

0

Sorki, wiem, że trochę po czasie, ale wydaje mi się, ze tak jest poprawnie

for i:=0 to Panel1.ControlCount-1 do
(Panel1.Controls[i] as TEdit).enabled:=false;

zamiast componentcount użyjcie controlcount

1 użytkowników online, w tym zalogowanych: 0, gości: 1