Qosai_DBA
asked on
Accepting Data from Telephone Central via MSComm
Hi all,
I'm trying to write a program to accept data from Telephon Central via MSComm, to Insert these data to a database.
before write a procedure to insert the data to the database, I want to write the data to a text file just for try.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, MSCommLib_TLB;
type
TForm1 = class(TForm)
MSComm1: TMSComm;
Edit1: TEdit;
Memo1: TMemo;
procedure FormShow(Sender: TObject);
procedure MSComm1Comm(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
MyFile: TextFile;
Line: String[80];
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender:TOb ject);
begin
Line:= '';
AssignFile(MyFile, 'c:\TryMSComm2.txt');
Append(MyFile);
Form1.MSComm1.PortOpen:= True;
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
var InputData: String;
begin
InputData:= Form1.MSComm1.Input;
if((InputData = #19)or(InputData = #17)or(InputData = #13))then
// Do Nothing
else if(InputData = #10)then
begin
Writeln(MyFile, Line);
Line:= '';
end
else
Line:= Line + InputData;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
CloseFile(MyFile);
Form1.MSComm1.PortOpen:= False;
end;
end.
and use a value 1 as an InputLen of MSComm property to accept only one char.
Each line of data contain 80 character.
This code is working succesfully, but when I frequently open the text file while the program is running to see what happend I see that at each write to the text file It write 124 character
mean one line and a half and when "just" close the program the remaining half line is writen.
I changed the Input buffer size more than one but the problem still exist.
Can any one help me how to solve this problem.
Thanks,
Khalid.
I'm trying to write a program to accept data from Telephon Central via MSComm, to Insert these data to a database.
before write a procedure to insert the data to the database, I want to write the data to a text file just for try.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, MSCommLib_TLB;
type
TForm1 = class(TForm)
MSComm1: TMSComm;
Edit1: TEdit;
Memo1: TMemo;
procedure FormShow(Sender: TObject);
procedure MSComm1Comm(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
MyFile: TextFile;
Line: String[80];
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender:TOb
begin
Line:= '';
AssignFile(MyFile, 'c:\TryMSComm2.txt');
Append(MyFile);
Form1.MSComm1.PortOpen:= True;
end;
procedure TForm1.MSComm1Comm(Sender:
var InputData: String;
begin
InputData:= Form1.MSComm1.Input;
if((InputData = #19)or(InputData = #17)or(InputData = #13))then
// Do Nothing
else if(InputData = #10)then
begin
Writeln(MyFile, Line);
Line:= '';
end
else
Line:= Line + InputData;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
CloseFile(MyFile);
Form1.MSComm1.PortOpen:= False;
end;
end.
and use a value 1 as an InputLen of MSComm property to accept only one char.
Each line of data contain 80 character.
This code is working succesfully, but when I frequently open the text file while the program is running to see what happend I see that at each write to the text file It write 124 character
mean one line and a half and when "just" close the program the remaining half line is writen.
I changed the Input buffer size more than one but the problem still exist.
Can any one help me how to solve this problem.
Thanks,
Khalid.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.