Autor Beitrag
kad_we
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 78


D6; Turbo Delphi 2006
BeitragVerfasst: Sa 17.01.04 17:59 
gibt es soetwas, wie Variablen für Operatoren?
z.B.:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var op: operator;
                i,j: real;
begin
for op:= + to / do
showmessage(floattostr(i op j));
end;

oder so ähnlich... ist das möglich?

Moderiert von user profile iconPeter Lustig: Topic Verschoben
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: Sa 17.01.04 18:03 
Nein, Operatorvariablen gibt es nicht. Ich nehme mal an, dass du einen Parser für Formeln coden willst.

Das einzige, was mir einfallen würde, wäre es mit Strings zu versuchen. Das würde zwar in einer etwas größeren Case-Verzweigung enden, aber mehr fällt mir so auf die Schnelle nicht ein. Sorry. :?

_________________
Viele Grüße
Jakob
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 17.01.04 18:08 
Hallo!

Nicht ganz dasselbe, aber vielleicht hilft es Dir:
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:
type
  tMyOpFunc = function(const a, b : Real) : Real;

const
  n = 2;

var
  Form1: TForm1;
  myFuncs : Array[0..n-1of TMyOpFunc;

implementation

{$R *.dfm}

function add(const a, b : Real) : Real;
begin
  result := a+b;
end;

function divide(const a, b : Real) : Real;
begin
  result := a/b;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  myFuncs[0] := add;
  myFuncs[1] := divide;
end;


procedure TForm1.Button1Click(Sender: TObject);
VAR c, d : Real;
    i : Integer;
begin
  c := 4; d := 2;

  for i:=0 TO n-1 do
    ShowMessage(FloatToStr(myFuncs[i](c,d)));
end;


MfG
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".