===== 谁给我改写一下一段简单的程序 ======(30分)

  • 主题发起人 主题发起人 visli
  • 开始时间 开始时间
V

visli

Unregistered / Unconfirmed
GUEST, unregistred user!
新建一个应用程序,加入edit1、edit2、button1三个控件,
下面是button1的单击事件。里面分为两部分,非常简单。
procedure TForm1.Button1Click(Sender: TObject);
var
edit_c:TEdit;
memo_c:TMemo;
begin
//第一部分
edit_c:=TEdit.Create(self);
edit_c.Text:=inttostr(random(16));
edit1.Text:=inttostr(random(strtoint(edit_c.Text)))+edit2.Text;
edit_c.Destroy;
//第二部分
memo_c:=TMemo.Create(self);
memo_c.Text:=inttostr(random(80));
edit1.Text:=inttostr(random(strtoint(memo_c.Text)))+edit2.Text;
memo_c.Destroy;
end;

因为我不太会线程。
所以请大家把这个事件改写成两个单独的线程。线程结构如下:
Type
...
MyThread=class(TThread)
...
Thread1=class(MyThread) //第一部分
...
Thread1=class(MyThread) //第二部分
...

注意:你写好后,请调试正确,并给出完整代码。
 
……你的算法还真有点那么……嘿嘿!
我得修改一下,不然我这老脸往哪儿搁呀?!
 
// D6 + SP2 / Win2k + SP3 下调试通过!
// Unit.pas
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
type
TMyThread = class(TThread)
protected
procedure Execute;
override;
end;

TEditThread = class(TMyThread)
private
proceduredo
Sync;
protected
procedure Execute;
override;
end;

TMemoThread = class(TMyThread)
private
proceduredo
Sync;
protected
procedure Execute;
override;
end;

{ TMyThread }
procedure TMyThread.Execute;
begin
inherited;
FreeOnTerminate := True;
// 自动释放
end;

{ TEditThread }
procedure TEditThread.DoSync;
begin
if Assigned(Form1) then
with Form1do
Edit1.Text := IntToStr(Random(Random(16))) + Edit2.Text;
end;

procedure TEditThread.Execute;
begin
inherited;
Synchronize(DoSync);
// 涉及VCL操作,必须同步
end;

{ TMemoThread }
procedure TMemoThread.DoSync;
begin
if Assigned(Form1) then
with Form1do
Edit1.Text := IntToStr(Random(Random(80))) + Edit2.Text;
end;

procedure TMemoThread.Execute;
begin
inherited;
Synchronize(DoSync);
// 涉及VCL操作,必须同步
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
TEditThread.Create(False);
// 立即执行
TMemoThread.Create(False);
// 立即执行
end;

end.

//**************************************************************
// Unit1.dfm
object Form1: TForm1
Left = 254
Top = 133
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 136
Top = 232
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object Edit1: TEdit
Left = 80
Top = 64
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit1'
end
object Edit2: TEdit
Left = 80
Top = 96
Width = 121
Height = 21
TabOrder = 2
Text = 'Edit2'
end
end
 
从上面的代码看, Edit_c和Memo_c 没有任何用处,定义一个S: String就ok了,
该成线程不是问题,
请把你的程序将清楚。
 
这段程序是干什么的?
我怎么看不懂?
仅是将EDIT2.TEXT中内容在前面加上一个随机值放到EDIT1.TEXT吗??
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
862
DelphiTeacher的专栏
D
后退
顶部