Q&A

  • registry 값을 삭제한 후 다시 읽었을때 화면에 변함이 없는이유?
안녕하세요..

이곳 홈페이지를 통하여 많은 도움을 얻고 있는 델파이 초보자 입니다. 오늘도 역시 궁금한 점이 있어서 고수님들의 도움을 듣고자 글을 올립니다.

제가 궁금한 점은 다음과 같습니다.

stringgrid를 이용하여 registry의 특정 key값들을 나타냈습니다. 나타낸 내용중에 사용자가 하나 또는 그 이상의 셀을 선택하여 삭제를 하였을 경우 당연히 registry의 내용이 지워져야 할 것이고 그리고 삭제된 registry 내용 즉, 변화된 registry의 내용을 화면에 다시 나타내야 하는데..

regiedit를 통하여 보면 삭제된것은 확인이 되었으나 실질적으로 화면에서는 그대로 남아있거나 제일 마지막 row의 registry정보가 추가되어 나타납니다. 물론 삭제 후에 조회 버튼을 trigger 시켜 다시 stringgrid에 나타나게 하였으나 잘 되지 않네요..

제가 생각을 못 한 부분이 있는지 ..

고수님들의 생각 또는 방법을 알고 싶습니다.

registry 내용을 조회하는 부분과 삭제하는 부분의 source는 다음과 같습니다.

//**********************************************************************

procedure TForm1.BitBtn1Click(Sender: TObject);



var

Reg: TRegistry;

Val:TStringList;

I:Integer;

rtnRowCount: Integer;

DataType: TRegDataType;

StringValue: String;

RegKeyInfo: TRegKeyInfo;

SystemTime: TSystemTime;

StringDate: String;





begin

Reg:=TRegistry.Create;



BitBtn2.Enabled := TRUE;

rtnRowCount := 1;

StringGrid1.RowCount := 2;

StringGrid1.Cells[0, 0] := '프로그램 이름';

StringGrid1.Cells[1, 0] := '데이터';

StringGrid1.Cells[2, 0] := '레지스트리 path';



try

Val:=TStringList.Create;

try

Reg.RootKey:=HKEY_LOCAL_MACHINE;

if not Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRun',False) then

else

begin

Reg.GetValueNames(Val);



for I:=0 to Val.Count-1 do

begin



if StringGrid1.RowCount = rtnRowCount then

StringGrid1.RowCount := rtnRowCount + 10;



Reg.GetKeyInfo(RegKeyInfo);

FileTimeToSystemTime(RegKeyInfo.FileTime, SystemTime);

DateTimeToString(StringDate, 'mm/dd/yyyy hh:mmAM/PM', SystemTimeToDateTime(SystemTime));





StringGrid1.Cells[0, rtnRowCount] := Val.Strings[I];

StringGrid1.Cells[1, rtnRowCount]:= Reg.ReadString(Val.Strings[I]);

StringGrid1.Cells[2, rtnRowCount] := 'HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionRun';

// row의 값을 하나씩 증가 시킨다.

Inc(rtnRowCount);

end;

end;

finally

Val.Free;

end;

finally

Reg.Free;

end;





end;



procedure TForm1.BitBtn2Click(Sender: TObject);

var

dReg: TRegistry;

I: Integer;

Msg: String;

Count: Integer;

Selection: TGridRect;

RootKey: Longint;

Path: String;

str : string;

dir : string;

test : boolean;







begin

dReg:=TRegistry.Create;

Selection := StringGrid1.Selection;

Count := Selection.Bottom - Selection.Top + 1;

RootKey := HKEY_LOCAL_MACHINE;

Path := 'SoftwareMicrosoftWindowsCurrentVersionRun';



if Count = 1 then

Msg := '레지스트리에서 선택된 키를 삭제하시겠습니까?'

else

Msg := '레지스트리에서 현재 선택된 키 ' +

IntToStr(Selection.Bottom - Selection.Top + 1) +

' 개를 삭제하시겠습니까?';



if MessageDlg(Msg, mtWarning, [mbYes,mbNo], 0) = mrYes then

begin

for I := Selection.Top to Selection.Bottom do

begin

dReg.RootKey := RootKey;



if not dReg.OpenKey(Path, FALSE) then

raise Exception.Create('키 '+Path+'를 열 수 없습니다.' );



test := dReg.DeleteValue(StringGrid1.Cells[0, I]);



if test then showmessage('success');

end;



// 삭제후 리스캔

BitBtn1Click(self);

end;

end;

//**********************************************************************





0  COMMENTS