Delphi利用字符串序列号对象

今天因为工作需要,原先调用动态库的方法已经写死了,只有两个字符串参数,现在想把串口对象传到动态库里面去,在动态库里面直接收发数据,经过百度一番,重要出了下面的解决方案,不多说 上源码

Q群 Delphi Home 235236282,欢迎delphi 爱好者加入,一起学习、进步。

unit umain;

interface

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

type
  TForm1 = class(TForm)
    cm1: TComm;
    btn1: TButton;
    btn2: TButton;
    btn3: TButton;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure btn3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  lsHandle: string;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
begin
  lsHandle := IntToStr(THandle(cm1));
end;

procedure TForm1.btn2Click(Sender: TObject);
var
  cm: TComm;
  lihandle: Integer;
begin
  lihandle := StrToInt(lsHandle);
  cm := TComm(lihandle);
  ShowMessage(inttostr(cm.BaudRate));
  cm.BaudRate:=7200;
end;

procedure TForm1.btn3Click(Sender: TObject);
begin
    ShowMessage(inttostr(cm1.BaudRate));
end;

end.

 

object Form1: TForm1
  Left = 192
  Top = 130
  Width = 272
  Height = 170
  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 btn1: TButton
    Left = 56
    Top = 8
    Width = 75
    Height = 25
    Caption = '保存句柄'
    TabOrder = 0
    OnClick = btn1Click
  end
  object btn2: TButton
    Left = 56
    Top = 40
    Width = 75
    Height = 25
    Caption = '还原对象'
    TabOrder = 1
    OnClick = btn2Click
  end
  object btn3: TButton
    Left = 56
    Top = 72
    Width = 169
    Height = 25
    Caption = '验证是否同一个对象'
    TabOrder = 2
    OnClick = btn3Click
  end
  object cm1: TComm
    CommName = 'COM2'
    BaudRate = 4800
    ParityCheck = False
    Outx_CtsFlow = False
    Outx_DsrFlow = False
    DtrControl = DtrEnable
    DsrSensitivity = False
    TxContinueOnXoff = True
    Outx_XonXoffFlow = True
    Inx_XonXoffFlow = True
    ReplaceWhenParityError = False
    IgnoreNullChar = False
    RtsControl = RtsEnable
    XonLimit = 500
    XoffLimit = 500
    ByteSize = _8
    Parity = None
    StopBits = _1
    XonChar = #17
    XoffChar = #19
    ReplacedChar = #0
    ReadIntervalTimeout = 100
    ReadTotalTimeoutMultiplier = 0
    ReadTotalTimeoutConstant = 0
    WriteTotalTimeoutMultiplier = 0
    WriteTotalTimeoutConstant = 0
    Left = 16
    Top = 8
  end
end

Q群 Delphi Home 235236282,欢迎delphi 爱好者加入,一起学习、进步。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值