澳门新蒲京娱乐


delphi线程
澳门新蒲京娱乐 2
发行版迁移和二进制兼容性考虑事项澳门新蒲京娱乐:

发短信以及目录【新蒲京官方下载】,Delphi中使用TThread类实现多线程

unit Dxc;
interface
uses  System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics,
FMX.Dialogs, FMX.StdCtrls,  FMX.Layouts, FMX.Memo,FMX.Platform.Android,
FMX.Edit,System.Math, FMX.ListBox;
type  TSendSMSForm = class(TForm)    StatusBar1: TStatusBar;   
ToolBar1: TToolBar;    Memo1: TMemo;    Button1: TButton;    StyleBook1:
TStyleBook;    Button2: TButton;    Button3: TButton;    Memo2: TMemo; 
  Label1: TLabel;    Edit1: TEdit;    Edit2: TEdit;    Label2: TLabel; 
  Label3: TLabel;    Label4: TLabel;    Label5: TLabel;    Label6:
TLabel;    Button4: TButton;    Panel1: TPanel;    Panel2: TPanel;   
Panel3: TPanel;    Panel4: TPanel;    Panel5: TPanel;    Panel6:
TPanel;    Panel7: TPanel;    procedure Button1Click(Sender: TObject); 
  procedure Button3Click(Sender: TObject);    procedure
Button2Click(Sender: TObject);    procedure Button4Click(Sender:
TObject);  private    { Private declarations }  public    { Public
declarations }  end;
var  SendSMSForm: TSendSMSForm;  myThread: TThread;implementation
{$R *.fmx}
uses 
Androidapi.JNI.JavaTypes,Androidapi.JNI.Telephony,System.IoUtils,androidapi.IOUtils;

以前写的十二线程程序都以用api直接做的,未有用过delphi自带Tthread类,刚才看了下,写了个demo,希望对新手有援助。。。

function SendSMS(tel,str:string):Boolean;var  j: JSmsManager;begin  j :=
tjsmsmanager.Create;  j.sendTextMessage(stringtojstring(tel), nil,
stringtojstring(str), nil, nil);  Result := True;end;

窗体单元:

procedure MyMethod;var  i,x: Integer;  str:string;  tel:string; 
s:string;begin  for i := 0 to SendSMSForm.Memo2.Lines.Count -1 do 
begin   // str:=SendSMSForm.Memo1.Lines.Text+datetimetostr(Now);   
str:=SendSMSForm.Memo1.Lines.Text;   
tel:=SendSMSForm.Memo2.Lines.Strings[i];    if (Trim(tel)<>”)
and (Trim(str)<>”) then begin     SendSMS(tel,str);    end;   
x:=
RandomRange(StrToInt(SendSMSForm.Edit1.Text)*1000,StrToInt(SendSMSForm.Edit2.Text)*1000); 
  Sleep(x);  end;end;
procedure TSendSMSForm.Button1Click(Sender: TObject);begin myThread :=
TThread.CreateAnonymousThread(MyMethod); //!!! myThread.Start;end;
procedure TSendSMSForm.Button2Click(Sender: TObject);begin 
MainActivity.finish;end;
procedure TSendSMSForm.Button3Click(Sender:
TObject);begin myThread.suspend;end;
procedure TSendSMSForm.Button4Click(Sender:
TObject);var i:Integer; s,m:string;begin  for s in
TDirectory.GetFiles(Androidapi.IOUtils.GetSharedCameraDir) do 
 Memo1.Lines.Add(s);   for s in TDirectory.GetDirectories(‘/storage’)do 
 Memo1.Lines.Add(s);   for s in
TDirectory.GetDirectoryRoot(‘/storage/sdcard0/DCIM/Camera’)do 
 Memo1.Lines.Add(s); 
 Memo1.Lines.Add(‘/////////////////////////////////////////////////’); 
  for s in
TDirectory.GetDirectories(TDirectory.GetDirectoryRoot(‘/storage/sdcard0/DCIM/Camera’))do 
 Memo1.Lines.Add(s);end;
end.

unit main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs,myThread, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure TThreadFinsh(Sender:TObject);
public
{ Public declarations }
end;

var
Form1: TForm1;
t1,t2,t3:TThread;
implementation

{$R *.dfm}
procedure TForm1.TThreadFinsh(Sender:TObject);
begin
ShowMessage(‘一个线程实现!’卡塔尔国;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin

if Button1.Caption=’开始1′ then
begin
Button1.Caption:=’关闭’;
t1.Resume;
end
else
begin
Button1.Caption:=’开始1′;
t1.Suspend;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if Button2.Caption=’开始2′ then
begin
Button2.Caption:=’关闭’;
t2.Resume;
end
else
begin
Button2.Caption:=’开始2′;
t2.Suspend;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if Button3.Caption=’开始3′ then
begin
Button3.Caption:=’关闭’;
t3.Resume;
end
else
begin
Button3.Caption:=’开始3′;
t3.Suspend;
end;
end;

相关文章

No Comments, Be The First!
近期评论
    功能
    网站地图xml地图