Autor Beitrag
wic_zocker
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Sa 12.06.10 11:22 
Hallo,

komme ganz gut mit c/cpp zurecht, da lassen sich aber Fensterchen schwer generieren. Delphi ist da einfach intuitiv, jedoch hab ich es mit der Syntax noch nicht so verstanden.

Fehler:
[Error] Unit1.pas(540): Constant expression expected
[Error] Unit1.pas(551): Constant expression expected

ausblenden volle Höhe Delphi-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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
// command states
const TP_ERROR = 1;
const TP_OK = 2;
// branch states
const TP_BR_INVALID = 0;
const TP_BR_NULL = 1;
const TP_BR_LOW = 2;
const TP_BR_GOOD = 3;
const TP_BR_HIGH = 4;

function TMain.GetState(n:integer):integer;
var
  st_code, br :integer;
begin
  case (ar_tppoints[1][n].cmd_color) of  // of type TColor
    clBlue:  // command off
      for br := 1 to ar_tppoints[1][n].branches do begin
        if br = 1 then
          st_code := GetStateCode(ar_tppoints[1][n].val_branch[br])
        else
          st_code := st_code and GetStateCode(ar_tppoints[1][n].val_branch[br]);
      end;
      if (st_code = TP_BR_NULL) then
        Result := TP_OK
      else
{540}   Result := TP_ERROR;
    clRed:  // command on
      for br := 1 to ar_tppoints[1][n].branches do begin
        if br = 1 then
          st_code := GetStateCode(ar_tppoints[1][n].val_branch[br])
        else
          st_code := st_code and GetStateCode(ar_tppoints[1][n].val_branch[br]);
      end;
      if (st_code = TP_BR_GOOD) then
        Result := TP_OK
      else
{551}   Result := TP_ERROR;
  else
    Result := TP_ERROR;
  end;
end;


Ich versteh einfach nicht was er von mir will?! Kann mir da jemand bitte weiterhelfen. Danke im voraus

Gruss in die weite Welt!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 12.06.10 11:29 
Hallo und :welcome: ;-)

Da fehlt ein begin..end um die beiden Blöcke im case. Bei Delphi ist es anders als in anderen Sprachen nicht so, dass man einfach mehrere Befehle hinschreiben kann und dann ggf. wegspringt.

Delphi ist da strenger, da muss man direkt sagen was zusammengehört:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
case a of
  b:
    begin
      c;
      d;
    end;
  e:
    f;
end;
wic_zocker Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Sa 12.06.10 11:34 
Jop das wars! Steht halt nix davon in der Hilfe (case statements) bei Delphi 5, da kann man hingucken wie man will.

Vielen Dank!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 12.06.10 15:21 
Das liegt an der unterschiedlichen Logik. In Delphi müssen mehrere Befehle auch in einem begin..end stehen. (Einzige Ausnahme sind initialization/finalization.)

In C-Sprachen wird hingegen der Case-Block als bereits geschlossenes Gebilde betrachtet, so dass darin keine Blöcke mehr notwendig sind. (Außerdem wird das mit mehrfach auftretendem Code auch anders gemacht, siehe das ggf. notwendige break nach jedem Block.)