Q&A

  • 동적으로 생성한 스트링그리드의 명칭알기


동적으로 생성한 탭쉬트에 동적으로 생성한 스트링그리드의 명칭을

알고 싶습니다.



여러개의 탭쉬트를 동적으로 생성할때마다 스트링그리드를 한개씩 생성하였습니다.

var Tsg : TstringGrid;

i_Page_Count : integer;

begin

with PageControl1 do

begin

with TTabSheet.Create(Self) do

begin

PageControl := PageControl1;

Name := 'tabsheet' + inttostr(i_Page_Count);



TSg := TStringGrid.Create(self);

TSg.parent := PageControl1.Pages[i_Page_Count-1];

TSg.Name := 'Sg' + inttostr(i_Page_Count);

TSg.Align := alClient;

end;



이렇게 해서 5개의 탭과 그리드를 추가한 후에

3번째 탭쉬트와 그리드를 삭제하고 싶습니다.

탭 삭제는 쉽게 되는데, 그리드의 명칭을 알아야

되는데 알 방법이 없습니다.



고수님들의 명언 바랍니다.

4  COMMENTS
  • Profile
    최용일 2001.12.06 22:17
    안녕하세요. 최용일입니다.



    탭쉬트삭제가 쉽게 된다면 굳이 스트링그리드의 이름을 알필요는 없을거 같군요.



    탭쉬트나 판넬같은 컨테이너클래스들은 Coltrols란 배열속성에 자식컨트롤을 넣어두니까



    이걸 검색해서 삭제하시면 되겠네요...



    var

    I: Integer;

    begin // TabSheet3 = 세번째탭쉬트

    for I := TabSheet3.ControlCount - 1 downto 0 do

    if TabSheet3.Controls[I] is TStringGrid then

    TabSheet3.Controls[I].Free;

    end;



    탭쉬트에 스트링그리드 하나뿐이라면 for문 돌릴필요도 없겠네요...



    TabSheet3.Controls[0].Free;



    ^^ 항상 즐코하세요...



    BLUE wrote:

    >

    > 동적으로 생성한 탭쉬트에 동적으로 생성한 스트링그리드의 명칭을

    > 알고 싶습니다.

    >

    > 여러개의 탭쉬트를 동적으로 생성할때마다 스트링그리드를 한개씩 생성하였습니다.

    > var Tsg : TstringGrid;

    > i_Page_Count : integer;

    > begin

    > with PageControl1 do

    > begin

    > with TTabSheet.Create(Self) do

    > begin

    > PageControl := PageControl1;

    > Name := 'tabsheet' + inttostr(i_Page_Count);

    >

    > TSg := TStringGrid.Create(self);

    > TSg.parent := PageControl1.Pages[i_Page_Count-1];

    > TSg.Name := 'Sg' + inttostr(i_Page_Count);

    > TSg.Align := alClient;

    > end;

    >

    > 이렇게 해서 5개의 탭과 그리드를 추가한 후에

    > 3번째 탭쉬트와 그리드를 삭제하고 싶습니다.

    > 탭 삭제는 쉽게 되는데, 그리드의 명칭을 알아야

    > 되는데 알 방법이 없습니다.

    >

    > 고수님들의 명언 바랍니다.

  • Profile
    BLUE 2001.12.07 02:45
    스트링 그리드를 새로 생성한 것의 DrawCellEvent를 적용시키기가

    너무 어려워서 다시 질문을 드립니다.

    일반적으로 디자인시 생성한 그리드는 OnDrawCell Event에 아래와 같이 사용합니다.



    /////////////////////////////////////////////////////////////////////////

    procedure TFKE_INSERT.SG1DrawCell(Sender: TObject; ACol, ARow: Integer;

    Rect: TRect; State: TGridDrawState);

    var

    OldAlign : Word;

    t_pos : Integer;

    title : String;

    i, j : Integer;

    begin

    title := (Sender as TStringGrid).Cells[ACol,ARow];



    if (gdFixed in State) then

    begin

    with (Sender as TStringGrid).Canvas do

    begin

    // Title Setting

    Brush.Color := $00C08000; //clTeal;

    Font.Color := clWhite;

    end

    end;



    // 선택된 Cell을 표시

    if gdSelected in State then

    begin

    with(Sender as TStringGrid).Canvas do

    begin

    Brush.Color := clYellow;

    Font.Color := clBlack;

    end;

    end;



    // Fixed Cell이 아닌 경우

    if not (gdFixed in State) then

    begin

    OldAlign := SetTextAlign((Sender as TStringGrid).Canvas.handle, TA_LEFT);

    (Sender as TStringGrid).Canvas.TextRect(Rect, Rect.Left+8, Rect.Top+6,

    (Sender as TStringGrid).Cells[ACol, ARow]);

    SetTextAlign((Sender as TStringGrid).Canvas.handle, OldAlign);

    end;



    // 문자열을 뿌린다.

    with(Sender as TStringGrid).Canvas do

    begin

    t_pos := (Rect.Right-Rect.Left-TextWidth(title)) Div 2 +Rect.Left;

    FillRect(Rect);

    TextRect(Rect,t_pos,Rect.Top + 4,title);

    end;



    end;

    ////////////////////////////////////////////////////////////////////////



    근데 새로 동적 생성된 스트링그리드는 가장 기본적인 ButtonFace 색상에

    정열도 되지 않은 그대로 나타납니다.

    인위적으로 그리드 생성과 자료를 뿌린 후에 for 문으로 넘겨줘도 되질 않습니다.



    var theRect : Trect

    begin

    for i := 0 to Tsg.RowCount - 1 do

    begin

    for j := 0 to Tsg.ColCount - 1 do

    begin

    TSGDrawCell(Tsg,j,i,theRect,[gdSelected, gdFocused, gdFixed]);

    //위의 DrawCell과 동일함.

    end;//for j

    end;//for i

    end;

    조언 바랍니다....



  • Profile
    최용일 2001.12.07 02:54
    이해할수 없는 코딩이네요... 쩝~~~



    동적으로 생성하나 디자인타임시에 생성하나 스트링그리드를 커스터마이징하게 그리는



    것은 OnDrawCell이벤트에서 합니다. 동적으로 생성했다고 따로 코딩으로 OnDrawCell



    이벤트를 호출해서 그려줄 필요는 없습니다.



    단지 이벤트만 연결시켜주시면 됩니다...



    begin

    tsg := TStringGrid.Create(Self);

    ......

    tsg.OnDrawCell := TSGDrawCell; // TSGDrawCell = OnDrawCell event method

    // 이부분을 디자인타임시에는 속성창에서 하는거죠...

    // 이렇게 해야지 tsg란 동적으로 생성된 스트링그리드가 필요할때 알아서

    // 커스터마이징하게 그려주는 겁니다.

    end;



    ^^ 항상 즐코하세요...



    BLUE wrote:

    > 스트링 그리드를 새로 생성한 것의 DrawCellEvent를 적용시키기가

    > 너무 어려워서 다시 질문을 드립니다.

    > 일반적으로 디자인시 생성한 그리드는 OnDrawCell Event에 아래와 같이 사용합니다.

    >

    > /////////////////////////////////////////////////////////////////////////

    > procedure TFKE_INSERT.SG1DrawCell(Sender: TObject; ACol, ARow: Integer;

    > Rect: TRect; State: TGridDrawState);

    > var

    > OldAlign : Word;

    > t_pos : Integer;

    > title : String;

    > i, j : Integer;

    > begin

    > title := (Sender as TStringGrid).Cells[ACol,ARow];

    >

    > if (gdFixed in State) then

    > begin

    > with (Sender as TStringGrid).Canvas do

    > begin

    > // Title Setting

    > Brush.Color := $00C08000; //clTeal;

    > Font.Color := clWhite;

    > end

    > end;

    >

    > // 선택된 Cell을 표시

    > if gdSelected in State then

    > begin

    > with(Sender as TStringGrid).Canvas do

    > begin

    > Brush.Color := clYellow;

    > Font.Color := clBlack;

    > end;

    > end;

    >

    > // Fixed Cell이 아닌 경우

    > if not (gdFixed in State) then

    > begin

    > OldAlign := SetTextAlign((Sender as TStringGrid).Canvas.handle, TA_LEFT);

    > (Sender as TStringGrid).Canvas.TextRect(Rect, Rect.Left+8, Rect.Top+6,

    > (Sender as TStringGrid).Cells[ACol, ARow]);

    > SetTextAlign((Sender as TStringGrid).Canvas.handle, OldAlign);

    > end;

    >

    > // 문자열을 뿌린다.

    > with(Sender as TStringGrid).Canvas do

    > begin

    > t_pos := (Rect.Right-Rect.Left-TextWidth(title)) Div 2 +Rect.Left;

    > FillRect(Rect);

    > TextRect(Rect,t_pos,Rect.Top + 4,title);

    > end;

    >

    > end;

    > ////////////////////////////////////////////////////////////////////////

    >

    > 근데 새로 동적 생성된 스트링그리드는 가장 기본적인 ButtonFace 색상에

    > 정열도 되지 않은 그대로 나타납니다.

    > 인위적으로 그리드 생성과 자료를 뿌린 후에 for 문으로 넘겨줘도 되질 않습니다.

    >

    > var theRect : Trect

    > begin

    > for i := 0 to Tsg.RowCount - 1 do

    > begin

    > for j := 0 to Tsg.ColCount - 1 do

    > begin

    > TSGDrawCell(Tsg,j,i,theRect,[gdSelected, gdFocused, gdFixed]);

    > //위의 DrawCell과 동일함.

    > end;//for j

    > end;//for i

    > end;

    > 조언 바랍니다....

    >

  • Profile
    BLUE 2001.12.07 03:19
    연결을 못해서 못하다니 정말 챙피하고 감사합니다..

    tsg.OnDrawCell := TSGDrawCell; // TSGDrawCell = OnDrawCell event method