⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setcom.pas

📁 delphi 7.0 开发的cdma手机发短信程序
💻 PAS
字号:
unit SETCOM;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ComCtrls,comfun, ExtCtrls;

type
  TForm2 = class(TForm)
    Label1: TLabel;
    ComboBox1: TComboBox;
    Label2: TLabel;
    ComboBox2: TComboBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    mmoSend: TMemo;
    edtSend: TMemo;
    Timer1: TTimer;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    procedure SetSendButton ;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  //Post_Event: THandle;//创建事件同步对象的句柄
  hSend : THandle;//发送串口的句柄
  //hRecv : THandle;//接收串口的句柄
  //Read_os: Toverlapped;//重叠结构的变量
  //Receive: Boolean; //开关变量,代表是否接收
  GeTcomfun:Tcomfun;
  WritingcomThread:TCommThread;
implementation

{$R *.dfm}

//互置发送按钮和输入框的有效性
procedure TForm2.SetSendButton ;
begin
  ComboBox1.Enabled := not ComboBox1.Enabled ;
  ComboBox2.Enabled := not ComboBox2.Enabled ;
  Button1.Enabled := not Button1.Enabled ;
  Button2.Enabled := not Button2.Enabled ;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  //CommName := ComboBox1.Text;
  // 打开发送串口
  //GeTcomfun.OpenConnection(ComboBox1.Text,hSend);
  
  if (not GeTcomfun.Opencom(ComboBox1.Text)) then
   raise Exception.Create('设置'+ComboBox1.text+'错误');
  SetSendButton;
end;


procedure TForm2.FormCreate(Sender: TObject);
begin
GeTcomfun:=Tcomfun.Create;
ComboBox1.Text:='COM1';
ComboBox2.Text:='9600';
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
GeTcomfun.closecom();
SetSendButton;
end;

procedure TForm2.Button3Click(Sender: TObject);
var
wirtcomint1:boolean;
begin
//WritingcomThread:=TCommThread.Create();
//Timer1.Enabled:=true;
//GeTcomfun.wirtcom(edtSend.Text);

wirtcomint1:=GeTcomfun.wirtcom(edtSend.Text);
if wirtcomint1=true then
begin
mmoSend.Lines.Add('已发送:');//+intToStr(wirtcomint)+'个字节的数据');
end
else
begin
mmoSend.Lines.Add('发送数据失败');
//Application.MessageBox('发送数据失败','',MB_OK);
//EXIT;
end;
end;

procedure TForm2.Timer1Timer(Sender: TObject);
var
wirtcomint:boolean;
begin
//wirtcomint:=false;
wirtcomint:=GeTcomfun.wirtcom(edtSend.Text);
if wirtcomint=true then
begin
mmoSend.Lines.Add('已发送:');//+intToStr(wirtcomint)+'个字节的数据');
end
else
begin
mmoSend.Lines.Add('发送数据失败');
//Application.MessageBox('发送数据失败','',MB_OK);
//EXIT;
end;
end;

procedure TForm2.Button4Click(Sender: TObject);
begin
Timer1.Enabled:=false;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -