I have an open source program that I want to use & associate with my New program. Started the new program with FileNewApplication. I then added the unit SerialNGBasic. When compiling I get an error (halts) in procedure TForm1.Button1Click(Sender: TObject); of Unit1/Main form.

Any hints?

Tks Vern

Attached is the two Units:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    SerialPortNG1: TSerialPortNG;
    SendBtn: TButton;
    Terminal: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SendBtnClick(Sender: TObject);
    procedure SerialPortNG1RxClusterEvent(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

Uses
  SerialNGBasic;


{$R *.dfm}


procedure AddHexString(S : String; Lines : TStrings );
var AddS, HexS, CopyS : String;
    i : Integer;
const SLen = 8;
begin
  form1.Memo1.Lines.Add(S);
  while Length(S) > 0 do
    begin
      AddS := Copy(S,1,SLen);
      HexS := '';
      Delete(S,1,SLen);
      for i := 1 to SLen do
        begin
          CopyS := Copy(AddS,i,1);
          if CopyS <> '' then
            HexS := HexS + ' ' + Format('%2.2x',[Byte(CopyS[1])]) //
          else
            HexS := HexS + '   ';
        end;
       while Length(AddS) < SLen do
         AddS := AddS + ' ';
       for i := 1 to SLen do
         case AddS[i] of
           #0..#31 : AddS[i] := '.';
           #127    : AddS[i] := '.';
         end;
       Lines.Add(HexS+' : '+AddS);
    end;
end;

procedure TForm1.SendBtnClick(Sender: TObject);
var SendStr : String;
begin          
  Terminal.Lines.Add(FormatDateTime('" Snd  " dd.mm.yy hh:mm:ss" :"', Now));
  Sendstr := #$00 + #$00 + #$00 + #$00 + #$10;
  SerialPortNG1.SendString(SendStr);
 end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SerialPortNG1.ClearRxDQueue;
  SerialNGBasic.SetDLGData(SerialPortNG1);
  if SerialNGBasic.ShowModal = mrOK then SerialNGBasicDLG.GetDLGData(SerialPortNG1);
end;

procedure TForm1.SerialPortNG1RxClusterEvent(Sender: TObject);
begin
  if SerialPortNG1.NextClusterSize >= 0 then
    begin
      if SerialPortNG1.NextClusterCCError = 0 then
        Terminal.Lines.Add(FormatDateTime('" Rec  " dd.mm.yy hh:mm:ss" :"', Now))
      else
        Terminal.Lines.Add(FormatDateTime('" RecX " dd.mm.yy hh:mm:ss" :"', Now));
      AddHexString(SerialPortNG1.ReadNextClusterAsString,Terminal.Lines);
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SerialPortNG1.Active := True;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  SerialPortNG1.Active := False;
end;


end.

------------------------

unit SerialNGBasic;

interface

uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  StdCtrls,
  Buttons,
  ExtCtrls,
  SerialNG;

type
  TSerialNGBasicDLG = class(TForm)
    OKBtn: TButton;
    CancelBtn: TButton;
    Bevel1: TBevel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    CBPort: TComboBox;
    CBBaud: TComboBox;
    CBData: TComboBox;
    CBStop: TComboBox;
    CBParity: TComboBox;
    CBFlow: TComboBox;
    ComboBox1: TComboBox;
  private
    { Private declarations }
  public
    { Public declarations }
    procedure SetDLGData(SerialPortNG : TSerialPortNG);
    procedure GetDLGData(SerialPortNG : TSerialPortNG);
  end;

var
  SerialNGBasicDLG: TSerialNGBasicDLG;

implementation

uses
  Unit1;

{$R *.DFM}

procedure TSerialNGBasicDLG.SetDLGData(SerialPortNG : TSerialPortNG);
var i : Integer;
begin
  i := CBPort.Items.IndexOf(SerialPortNG.CommPort);

  if i >= 0 then
    CBPort.ItemIndex := 4
  else
    CBPort.ItemIndex := 1; 

  i := CBBaud.Items.IndexOf(IntToStr(SerialPortNG.BaudRate));
  if i >= 0 then
    CBBaud.ItemIndex := i
  else
    CBBaud.ItemIndex := 5;

  CBData.ItemIndex := 3; 

  CBStop.ItemIndex := SerialPortNG.StopBits;

  CBParity.ItemIndex := SerialPortNG.ParityType;
  CBParity.ItemIndex := 2;

  CBFlow.ItemIndex := 0;  
end;     

procedure TSerialNGBasicDLG.GetDLGData(SerialPortNG : TSerialPortNG);
begin
  SerialPortNG.CommPort := 'COM4';
  SerialPortNG.BaudRate :=  4800; 
  SerialPortNG.DataBits := 8;
  SerialPortNG.StopBits := 2; 
  SerialPortNG.ParityType := 0; 
  SerialPortNG.FlowControl := 0; 
  SerialPortNG.Active := True;
end;

end.

Problem solved! Type error.

Tks for listening.

Vern

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.