procedure TfMian.mBeginSerchClick(Sender: TObject);
var
MyList: TStringListUTF8; // To store the registry key names
MyRegistry: TRegistry;
s: string;
i : integer;
// p: Integer; // MyList2 declared as a global variable
Str: string;
N:integer; // Write in the list of base
begin
Cursor:= crHourGlass;
bSearch.Visible:=False; // Hide the button to start search
// Clear the old contents
SQLQuery1.Close; // Table in the purification, in which
SQLQuery1.SQL.Text := 'delete from install'; // Recorded programs list
SQLQuery1.ExecSQL;
SQLTransaction1.CommitRetaining;
MyList2:=TStringListUTF8.Create;
MyRegistry:=TRegistry.Create(KEY_WOW64_64KEY);
MyList:=TStringListUTF8.Create;
then begin
with MyRegistry do
begin
RootKey:=HKEY_LOCAL_MACHINE;
OpenKeyReadOnly('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\');
GetKeyNames(MyList);
CloseKey;
for i:=0 to MyList.Count-1 do
begin
RootKey:=HKEY_LOCAL_MACHINE;
OpenKeyReadOnly('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\'+
MyList[i]);
Str:=ReadString('DisplayName');
if Str<>'' then
MyList2.Add(CP1251ToUTF8(ReadString('DisplayName')));
CloseKey;
end;
RootKey:=HKEY_LOCAL_MACHINE;
OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Uninstall\');
GetKeyNames(MyList);
CloseKey;
for i:=0 to MyList.Count-1 do
begin
RootKey:=HKEY_LOCAL_MACHINE;
OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Uninstall\'+
MyList[i]);
Str:=ReadString('DisplayName');
if Str<>'' then
MyList2.Add(CP1251ToUTF8(ReadString('DisplayName')));
CloseKey;
end;
end;
SQLQuery1.Close;
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add('insert into install(text)'); // Write the resulting list to the database program
SQLQuery1.SQL.Add('Values (:pText)');
for N := 0 to MyList2.Count - 1 do
begin
SQLQuery1.ParamByName('pText').AsString := MyList2[N];
SQLQuery1.ExecSQL;
end;
SQLTransaction1.CommitRetaining;
//новый вариант
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Text:='select text from install';
SQLQuery1.Open;
SQLQuery1.First;
MyList2.clear; // I tried from the database to obtain a list of programs
while not SQLQuery1.Eof do
begin
MyList2.Add(SQLQuery1.FieldByName('text').AsString);
SQLQuery1.Next;
end;
SQLQuery1.Close;
//Try removing quotes
MyList2.Text := StringReplace(MyList2.Text, '"', '', [rfReplaceAll, rfIgnoreCase]);
with MyList2.Create do
try
MyList2.StrictDelimiter := true;
// UTF8Delete(FiltrStr,Pos('ver',FiltrStr),Length(FiltrStr));
s := '';
for i := 0 to MyList2.Count - 1 do if Trim(MyList2.Strings[i]) <> '' then
s := s + Format('%s(name LIKE "%s")', [IfThen(i = 0, '', ' OR '), MyList2.Strings[i]]);
s := 'SELECT * FROM program WHERE ' + s + ' ORDER BY id';
finally
// Free; // I do not release, because it is used in other procedures
end;
// everything is stored in the s request, and it is used to retrieve data from the database
// Showmessage(s);
MyList.Free;
SQLQuery1.Close;
SQLQuery1.Active:=false;
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add(s);
SQLQuery1.Active:=true;
SQLQuery1.Open;
// Fill the column headings and changing the column width
DBGrid1.Columns[1].Title.Caption:='Название';
DBGrid1.Columns[2].Title.Caption:='Тип ПО';
DBGrid1.Columns[3].Title.Caption:='Лицензия';
DBGrid1.Columns[4].Title.Caption:='Стоимость';
DBGrid1.Columns[5].Title.Caption:='Замена';
DBGrid1.Columns[1].Width:= 200;
DBGrid1.Columns[2].Width:= 150;
DBGrid1.Columns[3].Width:= 110;
DBGrid1.Columns[4].Width:= 90;
DBGrid1.Columns[5].Width:= 150;
end;