ProviderUnit.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. unit ProviderUnit;
  2. {
  3. This unit keeps the 'Options'-Form data like provider-servers,
  4. passwords for accessing the account and so on.
  5. ***** Attention ***** it is more than worth mentioning, that the
  6. passwords are visible and storead as clear text in this demo!
  7. Change this before you make a commercial product out of this!!!!
  8. (c)2005
  9. Jörg Meier (Bob)
  10. [email protected]
  11. }
  12. interface
  13. uses
  14. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  15. StdCtrls, ExtCtrls, Buttons, Mask;
  16. type
  17. TProviderForm = class(TForm)
  18. GroupBox1: TGroupBox;
  19. Panel1: TPanel;
  20. LanChk: TCheckBox;
  21. PhoneList: TComboBox;
  22. BitBtn1: TBitBtn;
  23. BitBtn2: TBitBtn;
  24. Label1: TLabel;
  25. Label2: TLabel;
  26. Label8: TLabel;
  27. Label9: TLabel;
  28. lbAccount: TLabel;
  29. lbPassword: TLabel;
  30. Label11: TLabel;
  31. Label12: TLabel;
  32. ConnLabel: TLabel;
  33. Pop3Name: TEdit;
  34. Pop3Port: TEdit;
  35. Pop3Accnt: TEdit;
  36. Pop3PWD: TEdit;
  37. SMTPName: TEdit;
  38. SMTPPort: TEdit;
  39. SMTPAccnt: TEdit;
  40. SMTPPwd: TEdit;
  41. SMTPLogin: TCheckBox;
  42. DelMail: TCheckBox;
  43. CheckMailTime: TEdit;
  44. Label3: TLabel;
  45. Label4: TLabel;
  46. procedure LanChkClick(Sender: TObject);
  47. procedure FormShow(Sender: TObject);
  48. procedure FormCreate(Sender: TObject);
  49. procedure BitBtn1Click(Sender: TObject);
  50. private
  51. { Private-Deklarationen }
  52. public
  53. { Public-Deklarationen }
  54. Function GetProviderList:tStringList;
  55. Procedure LoadValues;
  56. Procedure SaveValues;
  57. end;
  58. var
  59. ProviderForm: TProviderForm;
  60. implementation
  61. Uses RAS, IniFiles;
  62. {$R *.DFM}
  63. function TProviderForm.GetProviderList: tStringList;
  64. Var I : Integer;
  65. Sz : Integer;
  66. ASz : Integer;
  67. Bf : PArrayRasEntryName;
  68. Nr : Integer;
  69. R : Integer;
  70. begin
  71. Result := tStringList.Create;
  72. Result.Sorted := True;
  73. Result.Duplicates := dupIgnore;
  74. Nr := 0;
  75. Sz := SizeOf(TRasEntryName);
  76. GetMem(Bf,Sz);
  77. Bf^[0].dwSize := Sz;
  78. ASz := Sz;
  79. R := RasEnumEntries(nil,nil,Bf,ASz,NR);
  80. if (R <> 0) and (ASz > 0) then begin
  81. FreeMem(Bf,Sz);
  82. GetMem(Bf,ASz);
  83. Bf^[0].dwSize := Sz;
  84. RasEnumEntries(nil,nil,Bf,ASz,NR);
  85. end;
  86. {$R-}
  87. For I := 0 to Nr-1 do begin
  88. Result.Add(String(Bf^[I].SzEntryName));
  89. end;
  90. {$R+}
  91. freemem(Bf,ASz);
  92. end;
  93. procedure TProviderForm.LanChkClick(Sender: TObject);
  94. begin
  95. PhoneList.Enabled := Not LANChk.Checked;
  96. ConnLabel.Enabled := Not LANChk.Checked;
  97. end;
  98. procedure TProviderForm.FormShow(Sender: TObject);
  99. Var Sl : tStringList;
  100. begin
  101. // Fill Combobox with Providers
  102. Sl := GetProviderList;
  103. PhoneList.Items.Assign(Sl);
  104. SL.Free;
  105. LoadValues;
  106. end;
  107. procedure TProviderForm.LoadValues;
  108. Var Ini : tIniFile;
  109. Fn : String;
  110. begin
  111. Fn := ChangeFileExt(Application.ExeName,'.INI');
  112. Ini := tIniFile.Create(Fn);
  113. Try
  114. LanChk.Checked := Ini.ReadBool('Connection','LanChk',True);
  115. PhoneList.Text := Ini.ReadString('Connection','PhoneList','');
  116. DelMail.Checked := Ini.ReadBool('Pop3','DelMail',True);
  117. Pop3Name.Text := Ini.ReadString('Pop3','Pop3Name','pop3.gmx.us');
  118. Pop3Port.Text := Ini.ReadString('Pop3','Pop3Port','110');
  119. Pop3Accnt.Text := Ini.ReadString('Pop3','Pop3Accnt','[email protected]');
  120. Pop3PWd.Text := Ini.ReadString('Pop3','Pop3PWd','Top Secret');
  121. SMTPLogin.Checked := Ini.ReadBool('SMTP','SMTPLogin',True);
  122. SMTPName.Text := Ini.ReadString('SMTP','SMTPName','smtp.gmx.us');
  123. SMTPPort.Text := Ini.ReadString('SMTP','SMTPPort','25');
  124. SMTPAccnt.Text := Ini.ReadString('SMTP','SMTPAccnt','[email protected]');
  125. SMTPPWd.Text := Ini.ReadString('SMTP','SMTPPWd','Top Secret');
  126. CheckMailTime.Text := Ini.ReadString('Mailer','CheckMailTime','10');
  127. finally
  128. Ini.Free;
  129. End;
  130. end;
  131. procedure TProviderForm.SaveValues;
  132. Var Ini : tIniFile;
  133. Fn : String;
  134. begin
  135. Fn := ChangeFileExt(Application.ExeName,'.INI');
  136. Ini := tIniFile.Create(Fn);
  137. Ini.WriteBool('Connection','LanChk',LanChk.Checked);
  138. Ini.WriteString('Connection','PhoneList',PhoneList.Text);
  139. Ini.WriteString('Pop3','Pop3Name',Pop3Name.Text);
  140. try
  141. Ini.WriteInteger('Pop3','Pop3Port',StrToInt(Pop3Port.Text));
  142. except
  143. Ini.WriteInteger('Pop3','Pop3Port',110);
  144. end;
  145. Ini.WriteString('Pop3','Pop3Accnt',Pop3Accnt.Text);
  146. Ini.WriteString('Pop3','Pop3PWd',Pop3PWd.Text);
  147. Ini.WriteBool('Pop3','DelMail',DelMail.Checked);
  148. Ini.WriteBool('SMTP','SMTPLogin',SMTPLogin.Checked);
  149. Ini.WriteString('SMTP','SMTPName',SMTPName.Text);
  150. try
  151. Ini.WriteInteger('SMTP','SMTPPort',StrToInt(SMTPPort.Text));
  152. except
  153. Ini.WriteInteger('SMTP','SMTPPort',25);
  154. end;
  155. Ini.WriteString('SMTP','SMTPAccnt',SMTPAccnt.Text);
  156. Ini.WriteString('SMTP','SMTPPWd',SMTPPWd.Text);
  157. Try
  158. Ini.WriteInteger('Mailer','CheckMailTime',StrToInt(CheckMailTime.Text));
  159. Except
  160. Ini.WriteInteger('Mailer','CheckMailTime',10);
  161. end;
  162. Ini.Free;
  163. end;
  164. procedure TProviderForm.FormCreate(Sender: TObject);
  165. begin
  166. LoadValues;
  167. end;
  168. procedure TProviderForm.BitBtn1Click(Sender: TObject);
  169. begin
  170. SaveValues;
  171. end;
  172. end.