大哥们请看这段代码:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
var s:string;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
s:='terminal';
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
case s of
'terminal': showmessage('111');
'cometo': showmessage('222');
end;
end.现在我欲将这两个过程写成函数,别人在引用我写的函数的时候,必须使用s这个全局变量,那么我的函数该怎么表达那个变量s啊? 我真可怜! 大家帮帮我吧! 见贴给分!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
var s:string;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
s:='terminal';
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
case s of
'terminal': showmessage('111');
'cometo': showmessage('222');
end;
end.现在我欲将这两个过程写成函数,别人在引用我写的函数的时候,必须使用s这个全局变量,那么我的函数该怎么表达那个变量s啊? 我真可怜! 大家帮帮我吧! 见贴给分!
function MyFunc(.....): integer;//or other;var
Form1: TForm1;
var s:string;implementation
{$R *.dfm}function MyFunc(...): integer;
begin
//只要这里面有s就行了
end;
begin
if LowerCase(s) = 'terminal' then
ShowMessage('111')
else if LowerCase(s) = 'cometo' then
ShowMessage('222');
end;其他的,不知所云?
这个procedure TForm1.Timer1Timer(Sender: TObject) 过程中只要发现s有变化而且是'terminal'的时候就会showmessage 在其他的.pas 中 也需要使用s
这时候我应该在哪里定义s呢?该怎么定义呢?
{ Public declarations }
s : String ;
--------------
其他窗体用的时候就
form1.s;还有
case 不能用于
无序的类型
case --integer可以
case --string 不行
case -- char 可以