Shape와 StaticText를 여러개 원하는만큼 만들었거든요?
만들면서 StaticText의 Caption은 만든 순서대로 넘버링 시켰어요.
여기서 Shape 하나를 distroy 시켰을 경우에 destroy된 이후의
StaticText의 Caption을 1씩 빼주려고 하는데 안되는군요.
(Shape와 StaticText는 항상 쌍으로 생성되고 삭제됩니다.)
아래 소스는 aTag를 인수로 받아서 그와 같은 Tag를 가진 Shape와 StaticText를 삭제한후 StaticText의 Caption을 1씩 빼주는 Procedure입니다.
Procedure TfrmAuto.OneShapeSText_Delete(aTag: Integer);
var
i: Integer;
begin
//=============================================================// 선택된 Shape와 StaticText를 삭제
//=============================================================
// Shape의 삭제와 Tag재정립
for i := ComponentCount - 1 downto 0 do
if Components[i] is TShape then
begin
if Components[i].Tag = aTag then
Components[i].Destroy;
if Components[i].Tag > aTag then
Components[i].Tag := Components[i].Tag - 1;
end;
// StaticText의 삭제와 Tag재정립
for i := ComponentCount - 1 downto 0 do
if Components[i] is TStaticText then
begin
if Components[i].Tag = aTag then
Components[i].Destroy;
if Components[i].Tag > aTag then
Components[i].Tag := Components[i].Tag - 1;
end;
end;
이렇게 하면 Shape와 Static의 Tag가 aTag인 것을 삭제한후 Tag도 정리가 싹 다 되거든요?
근데 StaticText의 Caption을 어떻게 바꿔주어야할지... ㅜㅜ
Components[i].Caption이란것도 없고
TStaticText(Sender).Caption을 건드리면 될듯한데 Sender를 어떻게 바꿀수 없나요??
형변환하세요...
.............
// StaticText의 삭제와 Tag재정립
for i := ComponentCount - 1 downto 0 do
if Components[i] is TStaticText then
begin
if Components[i].Tag = aTag then
Components[i].Destroy;
if Components[i].Tag > aTag then
begin
TStaticText(Components[i]).Caption := IntToStr( StrToInt(TStaticText(Components[i]).Caption) - 1);
Components[i].Tag := Components[i].Tag - 1;
end;
^^ 항상 즐코하세요...
이지인 wrote:
> Shape와 StaticText를 여러개 원하는만큼 만들었거든요?
> 만들면서 StaticText의 Caption은 만든 순서대로 넘버링 시켰어요.
> 여기서 Shape 하나를 distroy 시켰을 경우에 destroy된 이후의
> StaticText의 Caption을 1씩 빼주려고 하는데 안되는군요.
> (Shape와 StaticText는 항상 쌍으로 생성되고 삭제됩니다.)
>
> 아래 소스는 aTag를 인수로 받아서 그와 같은 Tag를 가진 Shape와 StaticText를 삭제한후 StaticText의 Caption을 1씩 빼주는 Procedure입니다.
>
> Procedure TfrmAuto.OneShapeSText_Delete(aTag: Integer);
> var
> i: Integer;
> begin
> //=============================================================// 선택된 Shape와 StaticText를 삭제
> //=============================================================
>
> // Shape의 삭제와 Tag재정립
> for i := ComponentCount - 1 downto 0 do
> if Components[i] is TShape then
> begin
> if Components[i].Tag = aTag then
> Components[i].Destroy;
> if Components[i].Tag > aTag then
> Components[i].Tag := Components[i].Tag - 1;
> end;
>
> // StaticText의 삭제와 Tag재정립
> for i := ComponentCount - 1 downto 0 do
> if Components[i] is TStaticText then
> begin
> if Components[i].Tag = aTag then
> Components[i].Destroy;
> if Components[i].Tag > aTag then
> Components[i].Tag := Components[i].Tag - 1;
> end;
> end;
>
> 이렇게 하면 Shape와 Static의 Tag가 aTag인 것을 삭제한후 Tag도 정리가 싹 다 되거든요?
> 근데 StaticText의 Caption을 어떻게 바꿔주어야할지... ㅜㅜ
>
> Components[i].Caption이란것도 없고
> TStaticText(Sender).Caption을 건드리면 될듯한데 Sender를 어떻게 바꿀수 없나요??
>
>