type
TCPUType =
(cpu_none,
cpu_avrtiny,
cpu_avrxmega3
);
var
cputype : TCPUType;
const
arr:array [TCPUType] of Byte = (1, 2, 3);
begin
for cputype in TCPUType do WriteLn(arr[??]); // wie geht's ?
end;
Mit Lazarus sehe ich grün
Mit Java und C/C++ sehe ich rot
type
TCPUType =
(cpu_none,
cpu_avrtiny,
cpu_avrxmega3
);
var
cputype : TCPUType;
i: Integer;
const
arr:array [TCPUType] of Byte = (7, 8, 9);
begin
i := 0;
for cputype in TCPUType do begin
Memo1.Lines.Add(arr[TCPUType(i)].ToString);
inc(i);
end;
Mit Lazarus sehe ich grün
Mit Java und C/C++ sehe ich rot
type
TCPUType =
(cpu_none,
cpu_avrtiny,
cpu_avrxmega3
);
var
cputype : TCPUType;
const
arr:array [TCPUType] of Byte = (7, 8, 9);
begin
for cputype in TCPUType do begin
Memo1.Lines.Add(arr[cputype].ToString);
end;
end;
MfG Socke
Ein Gedicht braucht keinen Reim//Ich pack’ hier trotzdem einen rein
var
cputype: TCPUType;
l: integer;
const
arr: array [TCPUType] of byte = (7, 8, 9);
begin
for cputype in TCPUType do begin
Memo1.Lines.Add(arr[cputype].ToString);
end;
l := Length(TCPUType); // geht nicht
l := Length(cputype); // geht nicht
procedure TForm1.Button3Click(Sender: TObject);
type
tcputype =
(cpu_none,
cpu_avrtiny,
cpu_avrxmega3
);
const
cpuInfo : array[tcputype] of string =
('cpu_none','cpu_avrtiny','cpu_avrxmega3');
var
cputype : tcputype;
begin
for cputype in Tcputype do showMessage (CpuInfo[cputype]);
showMessage (IntToStr(length(cpuInfo)));
end;
uses ....................., typinfo;
....
procedure TForm1.Button3Click(Sender: TObject);
type
tcputype =
(cpu_none,
cpu_avrtiny,
cpu_avrxmega3
);
var
cputype : tcputype;
len : integer;
begin
for cputype in Tcputype do showMessage (GetEnumName(TypeInfo(TCpuType), Ord(cputype)));
len := ord(high(TCputype)) - ord(low(TCpuType)) + 1;
showMessage (IntToStr(len));
end;
Eine unit mehr und ne ganze Menge Hirnschmalz und Tippen weniger.