1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
unit Unit1;
interface
uses
Windows,
Messages,
SysUtils,
Variants,
...,
CPort;
type
TForm1 = class(TForm)
Panel1: TPanel;
..
procedure FormActivate(Sender: TObject);
...
private
{ Déclarations privées }
public
procedure LOGS( HH : boolean );
procedure WWT;
{ Déclarations publiques }
end;
var
Form1: TForm1;
Com12_ : TComPort; // composant non créé au start
implementation
uses Grids,
Printers,
...;
{$R *.dfm}
...
function Connect_com_12 : boolean;
begin
with COM12_ do
begin
if connected then
clearbuffer(true,true)
else
open;
Connect_com_12:= connected
end
end;
function Un_connect_com_12 : boolean;
begin
with COM12_ do
begin
if connected then
close;
Un_connect_com_12 := not connected
end;
end;
procedure TForm1.FormActivate(Sender: TObject); //////
var b : boolean;
begin
getdir(0,Cur_Dir);
...
COM12_ := TComPort.Create(form1);
if COM12_ <> nil then
begin
with COM12_ do
begin
BaudRate := br9600;
Port := 'COM1';
Parity.Bits := prNone;
StopBits := sbOneStopBit;
DataBits := dbEight;
Events := [evRxChar, evTxEmpty, evRxFlag, evRing, evBreak, evCTS, evDSR, evError, evRLSD, evRx80Full];
FlowControl.OutCTSFlow := False;
FlowControl.OutDSRFlow := False;
FlowControl.ControlDTR := dtrDisable;
FlowControl.ControlRTS := rtsDisable;
FlowControl.XonXoffOut := False;
FlowControl.XonXoffIn := False;
OnRxChar := Com12RxChar;
OnTxEmpty := Com12TxEmpty;
end;
if not Connect_com_12 then
ShowMessage('Impossible de connecter le port');
end
else
showmessage('Impossible de créer le composant');
end;
end;
end;
...
initialization
COM12_:=nil;
...
end. |
Partager