我的意思如下:
if x =1 then
do procedure1
if x= 2 then
do procedure2
repeat
procedure1 或 procedure2
until .......
请问怎么实现,在线等,解决马上给分!
if x =1 then
do procedure1
if x= 2 then
do procedure2
repeat
procedure1 或 procedure2
until .......
请问怎么实现,在线等,解决马上给分!
你定义一个过程数组吧
procdedure[i]
YourChoice=false:boolean;
end;
.......
procedure ????.?????(???);
begin
if 符合条件 then YourChoice:=true else YourChoice:=false;
end;
.......
.......
if (YourChoice) then
do procedure1
else
do procedure2
repeat
procedure1 或 procedure2
until ...........
....
end.
比方说,如果x=1,repeat中间执行的过程就是procedure1,如果x=2,repeat中间执行的过程就是procedure2。我说明白了吗?
public
YourChoicePro1=false:boolean;
YourChoicePro2=false:boolean;
end;
.......
procedure procedure1(???);
begin
if 符合条件 then YourChoicePro1:=true else YourChoicePro1:=false;
end;
procedure procedure2(???);
begin
if (condition) then YourChoicePro2:=ture else YourChoicePro2:=false;
end;
.......
.......
if (YourChoicePro1) then
begin
repeat
procedure1
until .......
end;
if (YourChoicePro2) then
begin
repeat
procedure2
until .......
end;
....
....
end.
我觉得sy_315(白骆驼) 是完全明白了我的意思了的。
var prc:procedure;case x of
1: prc:=procedure1;
2: prc:=procedure2;
...
end;repeat
prc;
until
Windows, Messages,dialogs, SysUtils, Classes, Graphics, Controls, Forms,
StdCtrls;type Tpro = procedure (i,j: integer) of object; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure get1(i,j: integer);
procedure get2(i,j: integer); { Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.get1(i, j: integer);
begin
showmessage(inttostr(i) + ',' + inttostr(j));
end;procedure TForm1.get2(i, j: integer);
begin
showmessage(inttostr(i) + ';' + inttostr(j));
end;procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
ts: Tpro;
begin
i:= 2;
if i = 1 then
ts := get1
else
ts := get2;
ts(3,3);
end;end.
我理解的应该是这样的吧/
1: P:=procedure1;
2: P:=procedure2;
end;
@P;
repeat
@P
until
condition;
如果你的参数不同是不行的。
但可以用其它办法解决。把各种参数定义成record.然后只传递 指针。
在不同的进程中解释参数。
type
pRecord1=^record1;
record1=record
x,y:integer;
end; pRecord2=^record2;
record2=record
s:string;
end;procedure prc1(p:pRecord1);
Begin
p.x:=518;
end;
procedure prc2(p:pRecord2);
Begin
p.s:='xiaoxiao_8';
End;procedure main;
var prc:procedure (p:pointer);
p:pointer;
d1:record1;
d2:record2;
Begin
case x of
1: begin
d1.y:=0;
p:=@d1;
prc:=@prc1;
end;
2: begin
d2.s:='I am ...';
p:=@d2;
prc:=@prc2;
end;
...
end;repeat
prc(p);
until
end;
TMyProc = procedure (Mode: Word); //根据需要设定参数
procedure MyProc1(Mode: Word);
procedure MyProc2(Mode: Word);var
Form1: TForm1;implementation{$R *.dfm}procedure MyProc1(Mode: Word);
begin
end;procedure MyProc2(Mode: Word);
begin
end;procedure TForm1.Button1Click(Sender: TObject);
var
x: Integer;
Proc: TMyProc;
begin
x := 3;
case x of
1: Proc := MyProc1;
2: Proc := MyProc2;
else Proc := nil;
end;
repeat
if @Proc <> nil
then Proc(x);
until 1=1;
end;—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————
还有,我现在的过程参数根本不一样的。
我去44 xiaoxiao_8(小小_8) 的方法看行不~不过我只能照扒,意思不怎么懂, xiaoxiao_8(小小_8) 如果看到了帮讲一下好吗?
如果不是很多的话,没必要这么做。
如果你的不同的procedure 只不过几个而已,也没有必要这么做。执行效率提高不了多少。多写个100行语句,程序也不会有太多的开销(当然不包括循环)
TO:xiaoxiao_8(小小_8),有的时候执行的次数是很多,如果把判断和过程都加在repeat 和until之间我想要重复判断很多次执行哪个过程,所以想到了传递过程。这是问题1,其2,我原来写过程的时候里面的参数是var类型的,因为我在repeat和until里该过程的后面要对这个参数+1,如果把参数写成记录的话,那我的要求不知道怎么实现?