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: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174:
                   |                                     unit COM_EInstellungen;
  interface
  uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, StdCtrls,registry;
  type   TCOM_Dialog = class(TForm)     COMbox: TGroupBox;     COM1Button: TRadioButton;     COM2Button: TRadioButton;     Com3Button: TRadioButton;     COM4Button: TRadioButton;     EinstellungenBox: TGroupBox;     BaudBox: TComboBox;     DatenBox: TComboBox;     ParitaetBox: TComboBox;     StopBox: TComboBox;     ProtBox: TComboBox;     Baudrate: TLabel;     Datenbits: TLabel;     Paritaet: TLabel;     Stopbits: TLabel;     Protokoll: TLabel;     OK: TButton;     Abbrechen: TButton;     Uebern: TButton;     procedure COM1ButtonClick(Sender: TObject);     procedure COM2ButtonClick(Sender: TObject);     procedure Com3ButtonClick(Sender: TObject);     procedure COM4ButtonClick(Sender: TObject);     procedure FormActivate(Sender: TObject);     procedure UebernClick(Sender: TObject);     procedure OKClick(Sender: TObject);     procedure AbbrechenClick(Sender: TObject);   private     { Private declarations }   public     { Public declarations }   end;
  var   COM_Dialog: TCOM_Dialog;   regist : Tregistry;   Cport,b,d : integer;   s : single;   p,o   : string;   x : pchar;
  implementation
  {$R *.dfm}
  procedure TCOM_Dialog.COM1ButtonClick(Sender: TObject); begin  Cport := 1;  X := 'COM1'; end;
  procedure TCOM_Dialog.COM2ButtonClick(Sender: TObject); begin  Cport := 2;  X := 'COM2'; end;
  procedure TCOM_Dialog.Com3ButtonClick(Sender: TObject); begin  Cport := 3;  X := 'COM3'; end;
  procedure TCOM_Dialog.COM4ButtonClick(Sender: TObject); begin  Cport := 4;  X := 'COM4'; end;
  procedure TCOM_Dialog.FormActivate(Sender: TObject); begin  regist:=TRegistry.Create;  regist.RootKey:=HKEY_CLASSES_ROOT;  regist.Openkey('Delphin\Einstellungen',true);  Cport := regist.ReadInteger('Comport');  b := regist.ReadInteger('Baudrate');  s := regist.ReadFloat('Stopbit');  d := regist.ReadInteger('Datenbits');  p := regist.ReadString('Parität');  o := regist.ReadString('Protokoll');  Baudbox.Text := inttostr(b);  Stopbox.Text := floattostr(s);  DatenBox.Text := inttostr(d);  ParitaetBox.Text := p;  ProtBox.Text := O;  regist.Destroy;  if cport = 1 then   com1button.Checked := true;  if cport = 2 then   com2button.Checked := true;  if cport = 3 then   com3button.Checked := true;  if cport = 4 then   com4button.Checked := true;
  end;
  procedure TCOM_Dialog.UebernClick(Sender: TObject); var Handle :THandle;     dcb : TDCB;     s1 : byte;     OSVersion : TOSVersionInfo;     cc : TCommConfig;     hComm : hFile; begin  b := strtoint(Baudbox.Text);  s := strtofloat(StopBox.Text);  d := strtoint(Datenbox.Text);  P := Paritaetbox.Text;  O := ProtBox.Text;  regist:=TRegistry.Create;  regist.RootKey:=HKEY_CLASSES_ROOT;  regist.Openkey('Delphin\Einstellungen',true);  regist.WriteInteger('Comport',cport);  regist.WriteInteger('Baudrate',b);  regist.WriteFloat('Stopbit',s);  regist.WriteInteger('Datenbits',D);  regist.WriteString('Parität',P);  regist.WriteString('Protokoll',O);  regist.Destroy;  Handle := CreateFile(X,GENERIC_READ OR GENERIC_WRITE,                       0,                       nil,                       OPEN_EXISTING,                       FILE_ATTRIBUTE_NORMAL OR FILE_FLAG_OVERLAPPED,                       0);  if s = 1 then s1 := 0;  if (s = 1.5) then s1 := 1;  if s = 2 then s1 := 2;  OSVersion.dwOSVersionInfoSize:= SizeOf(OSVersion);  FillMemory(@CC,SizeOf(CC),0);  CC.dwSize:= SizeOf(cc);  GetVersionEx(OSVersion);  if (OSVersion.dwPlatformId=VER_PLATFORM_WIN32_NT) and (OSVersion.dwMajorVersion < 4) then   BuildCommDCB('baud=9600 parity=N Data=8 stop=1',DCB)  else  begin   GetDefaultCommConfig(x,cc,cc.dwsize);   DCB :=CC.DCB;  end;  GETCOMMSTATE(handle,DCB);  with DCB do   begin    BaudRate := B;    ByteSize := D;    Parity :=  p1;    StopBits := s1;   end;  SETCommState(handle,DCB);
 
  end;
  procedure TCOM_Dialog.OKClick(Sender: TObject); begin  close; end;
  procedure TCOM_Dialog.AbbrechenClick(Sender: TObject); begin  close; end;
  end.                                      |