大家来帮忙,100分相送。老是出错,我要自杀了!·!!! (100分)

  • 主题发起人 主题发起人 留香客
  • 开始时间 开始时间

留香客

Unregistered / Unconfirmed
GUEST, unregistred user!
老是出现Variable Required.错误。
源码如下:
代码:
unit qUnit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls;
type
  TForm1 = class(TForm)
    SpeedButton1: TSpeedButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure SpeedButton1Click(Sender: TObject);
  private
    procedure a(per: pointer);
    procedure b(per: pointer);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  i,ii:integer;
  hthreada,hthreadb:integer;
  ThreadID1,ThreadID2:cardinal;
implementation
{$R *.dfm}
procedure tform1.a(per:pointer);
begin
repeat
label1.Caption :=inttostr(i);
i:=i+1;
until i>1000
end;
procedure tform1.b(per:pointer);
begin
repeat
Label2.caption:=inttostr(ii);
ii:=ii+1;
until ii>1000
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
hthreada,hthreadb:thandle;
ThreadID1,ThreadID2:dword;
begin
hthreada:=begin
Thread(nil,0,@a,nil,0,ThreadID1);
hthreadb:=begin
Thread(nil,0,@b,nil,0,ThreadID2);
end ;
end.
 
缺少变量
帮你提提
 
代码:
unit qUnit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, Buttons, StdCtrls;
type
 TForm1 = class(TForm)
   SpeedButton1: TSpeedButton;
   Label1: TLabel;
   Label2: TLabel;
   procedure SpeedButton1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;
 i,ii:integer;
 hthreada,hthreadb:integer;
 ThreadID1,ThreadID2:cardinal;
implementation
{$R *.dfm}
procedure a(per:pointer);
begin
repeat
form1.label1.Caption :=inttostr(i);
i:=i+1;
until i>1000
end;
procedure b(per:pointer);
begin
repeat
form1.Label2.caption:=inttostr(ii);
ii:=ii+1;
until ii>1000
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
hthreada,hthreadb:thandle;
ThreadID1,ThreadID2:dword;
begin
hthreada:=begin
Thread(nil,0,@a,nil,0,ThreadID1);
hthreadb:=begin
Thread(nil,0,@b,nil,0,ThreadID2);
end ;
end.

a, b要求不是靜態的變量
所以a. b 不能聲明在form1裡面
改成這樣
就沒有你那個問題
多縣程不懂.....
 
这是TThreadFunc类型的定义:
type TThreadFunc = function(Parameter: Pointer): Integer;
你的a和b都是对象的过程,当然不行啦。
最好用TThread类来写线程。
 
unit qUnit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls;
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
Label1: TLabel;
Label2: TLabel;
procedure SpeedButton1Click(Sender: TObject);
private
[red] Function a(per: pointer): Integer;
Function b(per: pointer): Integer;[/red]//将声明定义为同TThreadFunc的定义相同
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
i,ii:integer;
hthreada,hthreadb:integer;
ThreadID1,ThreadID2:cardinal;
implementation
{$R *.dfm}
[red]Function tform1.a(per:pointer): Integer;[/red]
begin
repeat
label1.Caption :=inttostr(i);
i:=i+1;
until i>1000
end;
[red]Function tform1.b(per:pointer): Integer;[/red]
begin
repeat
Label2.caption:=inttostr(ii);
ii:=ii+1;
until ii>1000
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
hthreada,hthreadb:thandle;
ThreadID1,ThreadID2:dword;
begin
hthreada:=begin
Thread(nil,0,@a,nil,0,ThreadID1);
hthreadb:=begin
Thread(nil,0,@b,nil,0,ThreadID2);
end ;
end.
 
更正一下,将a,b函数的定义移到TForm1定义的外部来,我这里的运行结果就是正确的,如下:
unit qUnit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls;
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
Label1: TLabel;
Label2: TLabel;
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
[red] Function a(per: pointer): Integer;
Function b(per: pointer): Integer;//将声明定义为同TThreadFunc的定义相同[/red]
var
Form1: TForm1;
i,ii:integer;
hthreada,hthreadb:integer;
ThreadID1,ThreadID2:cardinal;
implementation
{$R *.dfm}
[red]
Function a(per:pointer): Integer;[/red]
begin
repeat
[red]Form1.label1.Caption :=inttostr(i);[/red]
i:=i+1;
until i>1000
end;
[red]
Function b(per:pointer): Integer;[/red]
begin
repeat
[red]Form1.Label2.caption:=inttostr(ii);[/red]
ii:=ii+1;
until ii>1000
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
hthreada,hthreadb:thandle;
ThreadID1,ThreadID2:dword;
begin
hthreada:=begin
Thread(nil,0,@a,nil,0,ThreadID1);
hthreadb:=begin
Thread(nil,0,@b,nil,0,ThreadID2);
end ;
end.
 
lightstar,
函数是这样定义
实际用的时候可以用procedure
你试一试
没问题的
 
谢谢,分不多,请笑纳.
 

Similar threads

回复
3
查看
362
迷惘的人
Q
回复
4
查看
370
穿越沦陷的爱
穿
后退
顶部