Delphi 控件交换数据

一:GUI 界面: 

       

 代码如下:

unit Unit3_3;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    CheckListBox1: TCheckListBox;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Button1: TButton;
    Button3: TButton;
    Button2: TButton;
    Edit1: TEdit;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
  private
      { Private declarations }

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.SpeedButton1Click(Sender: TObject);
var i:integer;
begin
i:=CheckListBox1.Items.Count-1;
while i>=0 do
  begin
    if CheckListBox1.Checked[i] then
       ListBox1.Items.Add(CheckListBox1.Items.Strings[i]);
    i:=i-1;
  end;

end;


procedure TForm1.Button2Click(Sender: TObject);
begin
if Edit1.Text<>'' then
CheckListBox1.Items.Add(Edit1.Text);
edit1.Text:='';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Close;
end;

procedure TForm1.Button3Click(Sender: TObject);
var i:integer;
begin
i:=ListBox1.Items.Count-1;
while i>=0 do
  begin
   ListBox1.Items.Delete(i);
   i:=i-1;
  end;
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
var i:integer;
begin
i:=CheckListBox1.Items.Count-1;
while i>=0 do
  begin
    if CheckListBox1.Checked[i] then
       CheckListBox1.Items.Delete(i);
    i:=i-1;
  end;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
var i,k:integer;
begin
k:=CheckListBox1.Items.Count-1;
i:=0;
while i<=k do
  begin
   ListBox1.Items.Add(CheckListBox1.Items.Strings[i]);
   i:=i+1;
  end;
end;
procedure TForm1.SpeedButton4Click(Sender: TObject);
var i:integer;
begin
i:=ListBox1.Items.Count-1;
while i>=0 do
  begin
    if ListBox1.Selected[i] then
        ListBox1.Items.Delete(i);
    i:=i-1;
  end;

end;

end.

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Delphi 10.2中的SPComm件是一个串口通信组件,使开发者能够直接通过串口与硬件设备通信。该件提供了一系列的方法和事件,方便开发者在应用程序中实现串口通信功能。 SPComm件可以用于读取和写入串口数据,它提供了读取和写入方法,开发者可以使用这些方法向串口发送数据或从串口接收数据。 该件还提供了一些事件,如OnReceiveData事件,当从串口接收到数据时触发,开发者可以在该事件中处理接收到的数据。还有OnSendData事件,在向串口发送数据时触发,开发者可以在该事件中执行一些逻辑代码。 此外,SPComm件还提供了一些属性,可以设置串口的相关参数,如波特率、数据位、校验位等。开发者可以根据实际需求设置这些参数来实现与外部设备的正确通信。 Delphi 10.2中的SPComm件简化了串口通信的开发,提供了一种简单、方便的方法来实现与硬件设备的连接和数据交互。开发者可以在其基础上快速开发出各种串口通信功能的应用程序。 ### 回答2: Delphi是一种编程语言,它允许开发人员使用面向对象的方式创建Windows应用程序。Delphi自带了一些常用的件,如SPComm件。 SPComm件是Delphi开发环境中一个串口通信件,它可以帮助我们轻松实现串口通信功能。通过SPComm件,我们可以连接到串口设备(如打印机、传感器等),并发送和接收数据。 SPComm件提供了许多属性和方法,让我们可以对串口进行各种配置和操作。例如,我们可以设置波特率、数据位、停止位和校验位等串口参数,还可以发送数据、接收数据和监听串口事件等。 使用SPComm件的步骤大致如下: 1. 在Delphi开发环境中创建一个新项目。 2. 将SPComm件添加到项目中的工具栏或窗体中。 3. 配置串口参数,例如设置波特率为9600、数据位8位、停止位1位和无校验位。 4. 在代码中使用SPComm件的方法来发送和接收数据,例如使用Open方法打开串口,使用Write方法发送数据,使用OnReceive事件接收数据。 5. 运行程序,测试串口通信功能。 需要注意的是,在使用SPComm件之前,我们需要先安装SPComm件库,并将其引入到Delphi开发环境中。另外,我们还需要了解一些串口通信的基础知识,例如不同串口设备的通信协议和数据格式等。 总之,Delphi 10.2 SPComm件是Delphi开发环境中的一个串口通信件,它可以帮助我们实现串口通信功能,并提供了丰富的属性和方法来配置和操作串口。通过学习和使用SPComm件,我们可以方便地开发串口通信相关的应用程序。 ### 回答3: Delphi 10.2 spcomm件是Delphi编程语言的一个串行通信件,用于在Windows操作系统上进行串行通信。它提供了一种简单而强大的方式来实现与串行设备(如串口、蓝牙设备等)的通信。 使用spcomm件,我们可以轻松地与串行设备进行数据交换。它提供了一组易于使用的方法和事件,使我们能够发送和接收数据,设置串行端口的属性(如波特率、数据位、校验位等),以及处理通信错误和事件。 在使用spcomm件时,我们首先需要实例化一个spcomm对象,然后设置串行端口的属性,如端口号、波特率等。然后,我们可以使用spcomm对象的方法,如Open、Close、Write、Read等来打开、关闭、写入和读取串行端口的数据。 此外,spcomm件还提供了一些事件,如OnReceive、OnSend、OnError等,可以用来处理接收数据、发送数据和错误事件。我们可以在这些事件中编写自定义的代码来实现特定的功能或业务逻辑。 总的来说,Delphi 10.2 spcomm件是一个功能强大且易于使用的串行通信件,可以帮助我们方便地进行与串行设备的数据交换。无论是连接到串口还是蓝牙设备,它都可以提供可靠和高效的通信功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值