Autor Beitrag
Finn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43



BeitragVerfasst: Mi 02.03.05 19:25 
Hallo Delphi-Freunde,

weiß einer von euch wie man einen Befehl x-mal hintereinander ausführen (wiederholen) kann
(x soll eine berechnete Variable sein)?

Der Befehl der wiederholt welden soll lautet:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
OpenCOM(1);
SetBaudRate(9600);
SendString('#rmd'+chr(0)+chr(1));
CloseCOM;

OpenCOM(1);
SetBaudRate(9600);
SendString('#rmz'+chr(0)+chr(5)+chr(0));
CloseCOM;


Wäre euch dankbar für ein kleines Beispiel wie mans macht.

Viele Grüße
Finn
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mi 02.03.05 19:35 
Wie wärs mit einer Schleife? for, while, repeat... gibt's haufenweise Beispiele in der OH

AXMD
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 02.03.05 19:39 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
x:= 10//Wie oft
for i:= 1 to X do //X ist die anzahl, i ist ein integer;
  begin
    OpenCOM(1);  
    SetBaudRate(9600);  
    SendString('#rmd'+chr(0)+chr(1));  
    CloseCOM;  
 
    OpenCOM(1);  
    SetBaudRate(9600);  
    SendString('#rmz'+chr(0)+chr(5)+chr(0));  
    CloseCOM; 
  end;
Finn Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43



BeitragVerfasst: Mi 02.03.05 20:11 
Hallo,

danke für die schnelle Antwort. Ich habe noch eine Frage:
Wie kann ich bei folgendem Befehl für xxx eine variable Zahl einsetzen ohne dass der Compiler jammert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
OpenCOM(1);
SetBaudRate(9600);
SendString('#rmz'+chr(0)+chr(xxx)+chr(0));
CloseCOM;


wenn ich eine Stringvariable einsetze sagt er:
Return Value of function 'Send String' might be undefined.

Gruß
Finn
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 02.03.05 20:12 
weil du einen string in einen char umwandeln willst, du kannst bytes oder integer 1..255 in chars umwandeln.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 02.03.05 20:14 
@F34r0fTh3D4rk: plus die Null. Finn wollte gar keinen String in ein Char verwandeln. ;)

"Return Value of function 'Send String' might be undefined" das ist nicht das Problem. Das ist nur eine Compiler-Warnung. Die kommt, weil die Funktion SendString nicht so sauber programmiert wurde.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var i : integer;
// ...
OpenCOM(1);  
SetBaudRate(9600);  
SendString('#rmz'+chr(0)+chr(i)+chr(0));  
CloseCOM;


sollte kein Problem sein.