There is no serial control in Delphi, so you first need to add the ActiveX control MSCOMM to the component palette. This is a very good control that it can not only operate the serial port, but also control MODEM. By following a specific example, how to develop serial communication programs with MSCOMM controls. Create a Communication.dpr project, change the Name property of the form to Commform, change the title to the Communication Test, select File / Save AS to store the new form as CommFrm.PAS.
Its corresponding code is as follows:
Variable Description Varcommform: Tcommform; SS: String; Savef, Readf: file of char; i, j: longint; initialization procedure tcommform.form.formcreate (sender: Tobject); beginmscomm.commport: = 1; mscomm.Settings: = '9600, N, 8, 1 '; mscomm.inputlen: = 1; mscomm.inbuffercount: = 0; mscomm.portopen: = true; ss: =' '; i: = 0; J: = 0; assignfile (Savef,' Save1 '); rewrite (savef); assignfile (readf,' read1 '); reset (readf); end; disposed determining procedure TCommForm.btnConfirmClick (Sender: TObject); beginif mscomm.portopen thenmscomm.portopen: = false; mscomm.commport : = strtoint (edtCommport.text); mscomm.settings: = edtCommsetting.Text; end; transmission event procedure TCommForm.MSCommComm (Sender: TObject); varfilenrc: char; buffer: variant; s1: string; c: char; begincase mscomm .commmevent off (EOF)) DOBEGINREAD (READF, FILENRC); mscomm.output: = filenrc; j: = j 1; lbldisplay.caption: = INTOSTOSTR (j); if mscomm.outbuffercount> = 2 THENBREAK; End; End; ComeVreceive: BeginBuffer: = mscomm.input; s1: = buffer; c: = s1 [1]; ss: = ss c; i: = i 1; lbldisplay.caption: = C INTOSTR (i); Write (Savef, c); if (c = chr (10)) or (c = chr (13)) the Nbeginlbldisplay.caption: = 'Cr' INTOSTR (I); MEMDISPLAY.LINES.ADD (SS); SS: = '; End; end; end;