Q&A

  • 동적생성에 관해 다시 질문드립니다. 제발 도와주세요...
델파이4, win98



Table1을 open하고 preview를 했을때 레코드에 따라 QRLabel을



로 동적생성하여 test.dat에 있는 내용을 찍어 주는 프로그램 입니다.



레코드가 이동하면 QLabel을 Free 시키고,



다시 QLabel로 내용을 찍어 주려고 합니다.



QLabel.Free 부분에서 에러가 나는데 제대로 소멸시키고 생성하는



방법이 없을까요? 고수님들의 도움 부탁드립니다.







<< 소스 >>



type

TForm1= class(TForm)

QuickRep1: TQuickRep;

QRBand2: TQRBand;

DetailBand1: TQRBand;

Table1: TTable;

QRL_No1: TQRLabel;

QRL_No2: TQRLabel;

QRL_No3: TQRLabel;



:

:



QRL_No18: TQRLabel;

QRL_No19: TQRLabel;

QRL_No20: TQRLabel;



:

private

{ Private declarations }

T_file : string;

In_File : TextFile;

Str : string;

L_cn : integer;

procedure Title_Sentence(Sentence:String; LineNo:integer);

:



var

Form1 : TForm1;

QLabel : TQRLabel;

QR_number : TQRLabel;

implementation



{$R *.DFM}



procedure TForm1.Table1AfterScroll(DataSet: TDataSet);

var

Sentence : String;

LineNo : integer;

begin

if Assigned(QLabel) then

begin

QLabel.Free;

QLabel := nil;

end;



:

:



T_file := 'test.dat';

if Fileexists(T_file) = True then

Begin

AssignFile(In_File, T_File);

Reset(In_file);

while not Eof(In_File) do

begin

Readln(In_File,Str);

if copy(str,1,1) = Table1.Fields[0].asstring then

Title_Sentence(str, l_cn);



l_cn := l_cn + 1;

end;

CloseFile(In_file);

end;



end;



procedure TForm1.Title_Sentence(Sentence:String; LineNo:integer);

begin

QR_number := TQRLabel(FindComponent('QRL_No' + inttostr(LineNo)));



QLabel := TQRLabel(DetailBand1.FindComponent('QP_' + inttostr(LineNo)));



if not Assigned(QLabel) then

begin

QLabel := TQRLabel.create(DetailBand1);

with QLabel do

begin

enabled := false;

name := 'QP_'+ inttostr(LineNo);

parent := DetailBand1;

caption := Sentence;

left := 15;

top := TQRLabel(QR_number).Top ;

width := 140;

height := 40;

autosize := false;

wordwrap := true;

enabled := true;

end;

end;

end;

1  COMMENTS
  • Profile
    전철호 2001.12.05 23:25
    천상천하 wrote:

    > 델파이4, win98

    >

    > Table1을 open하고 preview를 했을때 레코드에 따라 QRLabel을

    >

    > 로 동적생성하여 test.dat에 있는 내용을 찍어 주는 프로그램 입니다.

    >

    > 레코드가 이동하면 QLabel을 Free 시키고,

    >

    > 다시 QLabel로 내용을 찍어 주려고 합니다.

    >

    > QLabel.Free 부분에서 에러가 나는데 제대로 소멸시키고 생성하는

    >

    > 방법이 없을까요? 고수님들의 도움 부탁드립니다.

    >

    >

    >

    > << 소스 >>

    >

    > type

    > TForm1= class(TForm)

    > QuickRep1: TQuickRep;

    > QRBand2: TQRBand;

    > DetailBand1: TQRBand;

    > Table1: TTable;

    > QRL_No1: TQRLabel;

    > QRL_No2: TQRLabel;

    > QRL_No3: TQRLabel;

    >

    > :

    > :

    >

    > QRL_No18: TQRLabel;

    > QRL_No19: TQRLabel;

    > QRL_No20: TQRLabel;

    >

    > :

    > private

    > { Private declarations }

    > T_file : string;

    > In_File : TextFile;

    > Str : string;

    > L_cn : integer;

    > procedure Title_Sentence(Sentence:String; LineNo:integer);

    > :

    >

    > var

    > Form1 : TForm1;

    > QLabel : TQRLabel;

    > QR_number : TQRLabel;

    > implementation

    >

    > {$R *.DFM}

    >

    > procedure TForm1.Table1AfterScroll(DataSet: TDataSet);

    > var

    > Sentence : String;

    > LineNo : integer;

    > begin

    > if Assigned(QLabel) then

    > begin

    > QLabel.Free;

    > QLabel := nil;

    > end;

    >

    > :

    > :

    >

    > T_file := 'test.dat';

    > if Fileexists(T_file) = True then

    > Begin

    > AssignFile(In_File, T_File);

    > Reset(In_file);

    > while not Eof(In_File) do

    > begin

    > Readln(In_File,Str);

    > if copy(str,1,1) = Table1.Fields[0].asstring then

    > Title_Sentence(str, l_cn);

    >

    > l_cn := l_cn + 1;

    > end;

    > CloseFile(In_file);

    > end;

    >

    > end;

    >

    > procedure TForm1.Title_Sentence(Sentence:String; LineNo:integer);

    > begin

    > QR_number := TQRLabel(FindComponent('QRL_No' + inttostr(LineNo)));

    >

    > QLabel := TQRLabel(DetailBand1.FindComponent('QP_' + inttostr(LineNo)));

    >

    > if not Assigned(QLabel) then

    > begin

    > QLabel := TQRLabel.create(DetailBand1);

    > with QLabel do

    > begin

    > enabled := false;

    > name := 'QP_'+ inttostr(LineNo);

    > parent := DetailBand1;

    > caption := Sentence;

    > left := 15;

    > top := TQRLabel(QR_number).Top ;

    > width := 140;

    > height := 40;

    > autosize := false;

    > wordwrap := true;

    > enabled := true;

    > end;

    > end;

    > end;

    // QLabel을 처음에 초기화로

    // QLabel := nil; 로 준 다음

    // 다음 부분을 이렇게 바꿔보세요..

    if QLabel <> nil then <- if Assigned(QLabel) then

    begin

    QLabel.Free;

    QLabel := nil;

    end;