Код:
unit FrmMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IniFiles, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Button3: TButton;
Edit6: TEdit;
Button4: TButton;
Edit7: TEdit;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
FIntegrSecurity : String;
FPersistSecInfo : String;
FInitialCatalog : String;
FDataSource : String;
FProvider : String;
procedure ParseStr(const AStr: String; var AProvider, AIntegrSecurity,
APersistSecInfo, AInitialCatalog, ADataSource: String);
// procedure CombineStr(var AStr: String; const AProvider, AIntegrSecurity,
// APersistSecInfo, AInitialCatalog, ADataSource: String);
procedure CombineStr(var AStr: String; const AProvider,
AInitialCatalog, ADataSource: String);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
SIntegrSecurity = 'Integrated Security';
SPersistSecInfo = 'Persist Security Info';
SInitialCatalog = 'Initial Catalog';
SDataSource = 'Data Source';
SProvider = 'Provider';
SDelim = ';';
SEqual = '=';
procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Ini: TIniFile;
S: String;
begin
Ini := TIniFile.Create('c:\a.ini');
try
S := Ini.ReadString('CONNECT', 'ConStr', '');
Edit6.Text := S;
finally
if Assigned(Ini) then Ini.Free;
end;
end;
{
procedure TForm1.CombineStr(var AStr: String; const AProvider,
AIntegrSecurity, APersistSecInfo, AInitialCatalog, ADataSource: String);
begin
AStr := Format('%s=%s;%s=%s;%s=%s;%s=%s;%s=%s', [SProvider, AProvider,
SIntegrSecurity, AIntegrSecurity, SPersistSecInfo, APersistSecInfo,
SInitialCatalog, AInitialCatalog, SDataSource, ADataSource]);
end;
}
procedure TForm1.CombineStr(var AStr: String; const AProvider,
AInitialCatalog, ADataSource: String);
begin
AStr := Format('%s=%s;%s=%s;%s=%s', [SProvider, AProvider,
SInitialCatalog, AInitialCatalog, SDataSource, ADataSource]);
end;
procedure TForm1.ParseStr(const AStr: String; var AProvider,
AIntegrSecurity, APersistSecInfo, AInitialCatalog, ADataSource: String);
procedure ExtractParamAndValue(const Str: String; var Param, Value: String);
var
I: Integer;
begin
Param := ''; Value := '';
I := Pos(SEqual, Str);
if (I > 0) and (I < Length(Str)) then
begin
Param := copy(Str, 1, I - 1);
Value := copy(Str, I + 1, MAXINT);
end;
end;
var
I: Integer;
S, S1, S2: String;
begin
S := AStr;
repeat
I := Pos(SDelim, S);
if I > 0 then
begin
ExtractParamAndValue(copy(S, 1, I - 1), S1, S2);
S := copy(S, I + 1, MAXINT);
end
else
begin
ExtractParamAndValue(S, S1, S2);
S := '';
end;
if S1 = SProvider then FProvider := S2 else
if S1 = SIntegrSecurity then AIntegrSecurity := S2 else
if S1 = SPersistSecInfo then APersistSecInfo := S2 else
if S1 = SInitialCatalog then AInitialCatalog := S2 else
if S1 = SDataSource then ADataSource := S2;
until I <= 0
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ParseStr(Edit6.Text, FProvider, FIntegrSecurity, FPersistSecInfo,
FInitialCatalog, FDataSource);
Edit1.Text := FProvider;
Edit2.Text := FIntegrSecurity;
Edit3.Text := FPersistSecInfo;
Edit4.Text := FInitialCatalog;
Edit5.Text := FDataSource;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
S: String;
begin
self.CombineStr(S, Edit1.Text, Edit5.Text, Edit4.Text);
Edit7.Text := S;
end;
end.