Основной вопрос в этих двух строках
Result:= WideCompareText(UTF8ToSys(s), UTF8ToSys(d));
if not Result=(0) then break
Тут я пытаюсь сравнить две переменные, в которые считывает строки из текстового файла, и соответственно результат сравнения присваиваем переменной Result. Прочитал, что 0 означает совпадение. И далее пытался сделать условие, что если совпало, тогда записываем в таблицу.
Суть проблемы в том, что с Result=(0) он ничего не записывает в таблицу, если поставить 1 или -1, тогда он просто либо всё подряд записывает, либо случайным образом.
Ниже приведу полностью код процедуры
- Код: Выделить всё
procedure TfMian.Button1Click(Sender: TObject);
var
MyList: TStringList;
MyRegistry: TRegistry;
i: Integer;
Str: string;
install: TextFile;
TempStr: String;
//копипаст для заполнения таблицы
s: WideString; // читаем из install
d: WideString; // читаем из NameProgramm в d
f: string; // читаем из Rasprost
g: string; // читаем из License
h: string; // читаем из Stoimost
j: string; // читаем из Zamena
k: integer; // для заполнения данных
Result: integer; // для сравнения
for1: integer;
begin
Cursor:= crHourGlass;
bSearch.Visible:=False;
Button1.Visible:=False;
//Получаем список установленных программ
MyRegistry:=TRegistry.Create;
MyList:=TStringList.Create;
AssignFile(install, UTF8ToSys('install.txt'));
ReWrite(install);
with MyRegistry do
begin
RootKey:=HKEY_LOCAL_MACHINE;
if OpenKey('Software\Microsoft\Windows\CurrentVersion\Uninstall',
False)=True then GetKeyNames(MyList); // получает ключи в переменную mylist
TempStr := MyList.Text; // преобразуем в string
Writeln(install, TempStr); //записываем в файл
CloseKey;
end;
CloseFile(install);
try
// подключаем текстовые файлы для дальнейшей работы с ними
AssignFile(install, UTF8ToSys('install.txt'));
Reset(install);
AssignFile(NameProgramm, UTF8ToSys('NameProgramm.txt'));
Reset(NameProgramm);
AssignFile(Rasprost, UTF8ToSys('Rasprost.txt'));
Reset(Rasprost);
AssignFile(License, UTF8ToSys('License.txt'));
Reset(License);
AssignFile(Stoimost, UTF8ToSys('Stoimost.txt'));
Reset(Stoimost);
AssignFile(Zamena, UTF8ToSys('Zamena.txt'));
Reset(Zamena);
//делаем, пока не конец файла:
while not Eof(install) do begin
Cursor:= crHourGlass;
Readln(install, s); //читаем в s очередную строку
Readln(NameProgramm, d);
Readln(Rasprost, f); //читаем в f очередную строку
Readln(License, g);
Readln(Stoimost, h);
Readln(Zamena, j);
//пытаемся сравнить, и результат записать
Result:= WideCompareText(UTF8ToSys(s), UTF8ToSys(d));
if not Result=(0) then break
else begin
// далее нужно записать что нашли в таблицу
StringGrid1.RowCount:= StringGrid1.RowCount + 1;
k:= StringGrid1.RowCount;
SetLength(d, (k * 15));
StringGrid1.Cells[0, StringGrid1.RowCount-1]:= s;
StringGrid1.Cells[1, StringGrid1.RowCount-1]:= f;
StringGrid1.Cells[2, StringGrid1.RowCount-1]:= g;
StringGrid1.Cells[3, StringGrid1.RowCount-1]:= h;
StringGrid1.Cells[4, StringGrid1.RowCount-1]:= j;
end;
end;
finally
CloseFile(install);
CloseFile(NameProgramm);
CloseFile(Rasprost);
CloseFile(License);
CloseFile(Stoimost);
CloseFile(Zamena);
Cursor:= crDefault;
end; //try
end;
Заранее благодарен!