Q&A

  • 폼이 로드 되는데 시간이 너무 오래 걸려서 부탁 드립니다.
폼이 로드 되는데 시간이 너무 오래 걸려서,

고수님들께 의뢰 드립니다.



제가 보기에는 별 문제가 없어 보이는데,

프로그램이 실행되는데 시간이 너무 걸리네요.



DB에서 컨트롤의 정보를 읽어와서 동적으로 컨트롤을 생성 합니다.

DB는 ADO를 사용 하고요..

**********************************************************************************

procedure TDataModule3.DataModuleCreate(Sender: TObject);

begin

db.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +

'Data Source=' + ExtractFilePath(ParamStr(0)) +

'nopt_ion.mdb;Persist Security Info=False';

rs.Connection := db

end;

end.

**********************************************************************************



Form1이 실행되는데 약 15초.

Form1에서 Form2가 실행하는데 약 25초.



어느 부분을 잘못 했는지 알려 주시면 고맙겠습니다.

ADO로 접근 한것이 문제인지,동적으로 컨트롤을 생생하는것이 문제인지,

저로써는 전혀 이해를 못 하겠네요..



도움을 주소서...



Form1이 실행되는데 약 15초 소스

**********************************************************************************

program Project1;



uses

Forms,

Unit1 in 'Unit1.pas' {Form1},

Unit2 in 'Unit2.pas' {Form2},

Unit3 in 'Unit3.pas' {DataModule3: TDataModule};



{$R *.RES}



begin

Application.Initialize;

Application.CreateForm(TDataModule3, DataModule3);

Application.CreateForm(TForm1, Form1);

// Application.CreateForm(TForm2, Form2); //이곳이 안막혀 있다면

Application.Run; //시간이 많이 걸리더군요 약 35초

end.

**********************************************************************************



Form1의 FormCreate 부분 소스

**********************************************************************************

unit Unit1;



interface



uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

Db, ADODB, ExtCtrls, StdCtrls, ShellAPI, ComCtrls, Menus;



type

TForm1 = class(TForm)

Timer1: TTimer;

lbl_Chk: TLabel;

CDlg: TOpenDialog;

Last_cnt: TLabel;

MainMenu1: TMainMenu;

PasswordChange1: TMenuItem;

Option2: TMenuItem;

ProgramEnd1: TMenuItem;

Save_Chk: TLabel;

procedure FormCreate(Sender: TObject);

procedure Timer1Timer(Sender: TObject);

procedure Option2Click(Sender: TObject);

procedure ProgramEnd1Click(Sender: TObject);

procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);

private

//procedure WndProc(var Message: TMessage); override; ///

procedure Load_Control1;

procedure Db_Work(X_tmp: String);

function Find_name(S_tmp: string): string;

procedure NewChkClick(Sender: TObject);

procedure Delay(millisecs: longint);

procedure NewScroll_timeClick(Sender: TObject);

procedure NewScroll_minClick(Sender: TObject);

procedure NewLableMouseup(Sender: TObject; Button:

TMouseButton; Shift: TShiftState; X, Y: Integer);

{ Private declarations }

public

//procedure ChangeColor(Sender: TObject; Msg: Integer); ///

{ Public declarations }

end;

var

Form1: TForm1;

Bun_time: String;

db1 : tadoconnection;

rs : tadoquery;

implementation



uses Unit2, Unit3;

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);

begin

db1 := datamodule3.db;

rs := datamodule3.rs;

lbl_Chk.Caption := 'Start';



{db1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +

'Data Source=' + ExtractFilePath(ParamStr(0)) +

'nopt_ion.mdb;Persist Security Info=False';

rs.Connection := db1; }



Load_Control1;

timer1.Interval := 5000 ;



end;

procedure TForm1.Load_Control1;

var

rec : integer;

N_cnt : integer;

H_size: integer;

str : string;

NewChk: array of TCheckbox;

Newtxt_Time: array of Tedit;

NewScroll_time: array of TScrollBar;

Newtxt_Min: array of Tedit;

NewScroll_min: array of TScrollBar;

NewLable: array of TLabel;



begin

H_size := 30;

str := 'select daily,start_bun,start_cho,script,caption,visible from ' +

'opt_ion where visible = true';

rs.SQL.Clear;

rs.SQL.text := str;

rs.Open;

rec := rs.Recordset.Get_RecordCount;

SetLength(NewChk , rec);

SetLength(Newtxt_Time , rec);

SetLength(NewScroll_time, rec);

SetLength(Newtxt_Min , rec);

SetLength(NewScroll_min , rec);

SetLength(NewLable , rec);



if rec = 0 then begin

rs.close;

exit;

end;



rs.first;

for N_cnt := 0 to rec - 1 do begin

NewChk[n_cnt] := TCheckbox.Create(self);

Newtxt_Time[n_cnt] := Tedit.Create(self);

NewScroll_time[n_cnt] := TScrollBar.Create(self);

Newtxt_Min[n_cnt] := Tedit.Create(self);

NewScroll_min[n_cnt] := TScrollBar.Create(self);

NewLable[n_cnt] := TLabel.Create(self);



with NewChk[n_cnt] do begin

Parent := form1;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(30,H_size,195 ,18) ;

Caption := rs.FieldbyName('caption').AsString;

Checked := rs.FieldbyName('daily').Asboolean;

name := 'NewChk'+ inttostr(n_cnt);

visible := true;

OnClick := NewChkClick;

Show;

end;



with Newtxt_Time[n_cnt] do begin

Parent := form1;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(NewChk[n_cnt].Left +140 ,H_size,30,18) ;

Text := rs.FieldbyName('start_bun').AsString;

name := 'Newtxt_Time'+ inttostr(n_cnt);

visible := true;

Enabled := False;

Show;

end;

with NewScroll_time[n_cnt] do begin

Parent := form1;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(Newtxt_Time[n_cnt].left + 30,H_size+1,20,20) ;

min := 0;

max := 2;

name := 'NewScroll_time'+ inttostr(n_cnt);

Position := 1;

OnChange := NewScroll_timeClick;

Show;

end;

with Newtxt_Min[n_cnt] do begin

Parent := Form1;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(NewScroll_time[n_cnt].Left + 30,H_size,30,18) ;

Text := rs.FieldbyName('start_cho').AsString;

name := 'Newtxt_Min'+ inttostr(n_cnt);

visible := True;

Enabled := False;

Show;

end;



with NewScroll_min[n_cnt] do begin

Parent := Form1;

SetBounds(Newtxt_Min[n_cnt].left + 30,H_size+1,20,20) ;

min := 0;

max := 2;

name := 'NewScroll_min'+ inttostr(n_cnt);

Position := 1;

OnChange := NewScroll_minClick;

Show;

end;

with NewLable[n_cnt] do begin

Parent := form1;

SetBounds(NewScroll_min[n_cnt].left+25,H_size+5,100,20) ;

Caption := rs.FieldbyName('script').AsString;

name := 'NewLable'+ inttostr(n_cnt);

OnMouseUp := NewLableMouseup;

Show;

end;

rs.Next;

H_size := H_size + 30;

end; //'For end

form1.Height := NewLable[n_cnt-1].Top + 100;

rs.Close;

Last_cnt.Caption := Inttostr(rec -1);

NewChk := nil;

Newtxt_Time := nil;

NewScroll_time := nil;

Newtxt_Min := nil;

NewScroll_min := nil;

NewLable := nil;

end;

**********************************************************************************





Form2가 실행되는데 약 25초 소스

**********************************************************************************

procedure TForm1.Option2Click(Sender: TObject);



begin

form1.Destroy;

if Assigned(Form2) then

form2.show

else

Application.CreateForm(TForm2, Form2);

Application.Run;



end;

**********************************************************************************





Form2의 FormCreate 소스

**********************************************************************************

unit Unit2;



interface



uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls, Db, ADODB;



type

TForm2 = class(TForm)

Lbl_Chk: TLabel;

Button1: TButton;

procedure FormCreate(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);

private

procedure Combo_Fill;

procedure NewCheckClick(Sender: TObject);

procedure NewTextKeyPress(Sender: TObject; var Key: Char);

{ Private declarations }

public

{ Public declarations }

end;



var

Form2: TForm2;

db1 : tadoconnection;

rs : tadoquery;

implementation



uses Unit1, Unit3;



{$R *.DFM}



procedure TForm2.FormCreate(Sender: TObject);

var

rec,N_cnt : integer;

H_size : integer;

NewCheck : array of TCheckbox;

NewText : array of Tedit;

Txt_New_Name : TEdit;

Cmd_Add : TButton;

Cbo_Del : TComboBox;

Cmd_Del : TButton;

Lbl_Scr : TLabel;

str : string;

begin

db1 := datamodule3.db;

rs := datamodule3.rs;

SetLength(NewCheck , rec);

SetLength(NewText , rec);

h_size := 30;

lbl_Chk.Caption := 'Start';



str := 'select caption,visible from opt_ion';

rs.SQL.Clear;

rs.SQL.text := str;

rs.Open;

rec := rs.Recordset.Get_RecordCount;

rs.first;



for N_cnt := 0 to rec - 1 do begin

NewCheck[n_cnt] := TCheckbox.Create(self);

NewText[n_cnt] := TEdit.Create(self);



with NewCheck[n_cnt] do begin

Parent := form2;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(30,H_size,195 ,18) ;

visible := true;

OnClick := NewCheckClick;

Caption := rs.FieldbyName('caption').AsString;

Checked := rs.FieldbyName('visible').Asboolean;

name := 'NewChk'+ inttostr(n_cnt);

Show;

end;

with NewText[n_cnt] do begin

Parent := form2;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(NewCheck[n_cnt].left + 160,H_size,150 ,18) ;

visible := true;

OnKeyPress := NewTextKeyPress;

Text := rs.FieldbyName('caption').AsString;

name := 'NewText'+ inttostr(n_cnt);

Show;

end;

H_size:=H_size +30;

rs.Next

end; //for end

rs.Close;



Txt_New_Name := TEdit.Create(self);

with Txt_New_Name do begin

Parent := form2;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(NewCheck[n_cnt-1].left,H_size,100 ,18) ;

visible := true;

// OnClick := NewChkClick;

name := 'Txt_New_Name';

Text := '';

Show;

end;



Cmd_Add := TButton.Create(self);

with Cmd_Add do begin

Parent := form2;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(Txt_New_Name.left + Txt_New_Name.Width ,H_size,30 ,18) ;

visible := true;

// OnClick := NewChkClick;

Caption := 'ADD';

name := 'Cmd_Add';

Show;

end;



Cbo_Del := TComboBox.Create(self);

with Cbo_Del do begin

Parent := form2;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(NewText[n_cnt-1].Left ,H_size,150 ,18) ;

visible := true;

// OnClick := NewChkClick;

name := 'Cbo_del';

Text := '';

Show;

end;



Cmd_Del := TButton.Create(self);

with Cmd_Del do begin

Parent := form2;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(Cbo_Del.left + Cbo_Del.width ,H_size,30 ,18) ;

visible := true;

// OnClick := NewChkClick;

Caption := 'DEL';

name := 'Cmd_Del';

Show;

end;

H_size:=H_size +30;



Lbl_Scr := TLabel.Create(self);

with Lbl_Scr do begin

Parent := form2;

Font.Name := '돋움체';

Font.Size := 9;

SetBounds(30,H_size,195 ,18) ;

visible := true;

// OnClick := NewChkClick;

Caption := '스크립트 찾기';

name := 'Lbl_scr';

Show;

end;



form2.height := lbl_scr.top + 80;

Combo_Fill;

lbl_Chk.Caption := 'End';

NewCheck := nil;

NewText := nil;

end;

**********************************************************************************

2  COMMENTS
  • Profile
    델피언 2000.09.21 19:58
    안녕하세요..

    지나는 길에 들렀습니다.



    일단은 소스를 전체적으로 보진 않았지만..

    어느 부분에서 시간이 많이 걸리는지를 알아내야 겠습니다.

    일단 소스로 봐서 (자세히 보진 않았지만..쩝~)

    DB연결부하고 동적생성부분을 검토해야 겠네여..



    break를 Database open하는곳에 걸고 이곳에 걸리면 F8을 눌러서 시간이 얼마나 소요 되는지

    보세요..DB연결부에서 가끔 시간이 많이 걸리는 경우도 있습니다.

    그리고

    break를 동적생성하는 프로지저(Load_Control1)에 걸고 F8을 눌러서 이 프로시저를 실행하는데 걸리는 시간을 체크 하세요..



    지금 다시 보니 Timer를 쓰시는데여..여기에 뭔가 걸려 있는듯 하네여..



    5초마다 어떤 작업을 하는지 모르겠지만 이곳도 검토 하시는 것이 좋을듯 싶네여..



    참고가 되셨는지



    그래도 문제가 해결 되지 않으면 멜 주세엽~

    즐코~



    지금 다시 보니 여러군데 성능 저하를 시키는 부분이 있네여..

    음~

    TQuery 를 open하고 나서 recordcount를 하게되면 레코드의 마지막으로 이동하는라고 시간이

    레코드수에 비례하게 됩니다.

    for 문을

    o_Query.first;

    while not o_Query.Eof do begin

    ...

    end;

    이런식으로 바꾸어 사용해 보세요..

    기타 등등

    즐코하세엽~



    이용 wrote:

    > 폼이 로드 되는데 시간이 너무 오래 걸려서,

    > 고수님들께 의뢰 드립니다.

    >

    > 제가 보기에는 별 문제가 없어 보이는데,

    > 프로그램이 실행되는데 시간이 너무 걸리네요.

    >

    > DB에서 컨트롤의 정보를 읽어와서 동적으로 컨트롤을 생성 합니다.

    > DB는 ADO를 사용 하고요..

    > **********************************************************************************

    > procedure TDataModule3.DataModuleCreate(Sender: TObject);

    > begin

    > db.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +

    > 'Data Source=' + ExtractFilePath(ParamStr(0)) +

    > 'nopt_ion.mdb;Persist Security Info=False';

    > rs.Connection := db

    > end;

    > end.

    > **********************************************************************************

    >

    > Form1이 실행되는데 약 15초.

    > Form1에서 Form2가 실행하는데 약 25초.

    >

    > 어느 부분을 잘못 했는지 알려 주시면 고맙겠습니다.

    > ADO로 접근 한것이 문제인지,동적으로 컨트롤을 생생하는것이 문제인지,

    > 저로써는 전혀 이해를 못 하겠네요..

    >

    > 도움을 주소서...

    >

    > Form1이 실행되는데 약 15초 소스

    > **********************************************************************************

    > program Project1;

    >

    > uses

    > Forms,

    > Unit1 in 'Unit1.pas' {Form1},

    > Unit2 in 'Unit2.pas' {Form2},

    > Unit3 in 'Unit3.pas' {DataModule3: TDataModule};

    >

    > {$R *.RES}

    >

    > begin

    > Application.Initialize;

    > Application.CreateForm(TDataModule3, DataModule3);

    > Application.CreateForm(TForm1, Form1);

    > // Application.CreateForm(TForm2, Form2); //이곳이 안막혀 있다면

    > Application.Run; //시간이 많이 걸리더군요 약 35초

    > end.

    > **********************************************************************************

    >

    > Form1의 FormCreate 부분 소스

    > **********************************************************************************

    > unit Unit1;

    >

    > interface

    >

    > uses

    > Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    > Db, ADODB, ExtCtrls, StdCtrls, ShellAPI, ComCtrls, Menus;

    >

    > type

    > TForm1 = class(TForm)

    > Timer1: TTimer;

    > lbl_Chk: TLabel;

    > CDlg: TOpenDialog;

    > Last_cnt: TLabel;

    > MainMenu1: TMainMenu;

    > PasswordChange1: TMenuItem;

    > Option2: TMenuItem;

    > ProgramEnd1: TMenuItem;

    > Save_Chk: TLabel;

    > procedure FormCreate(Sender: TObject);

    > procedure Timer1Timer(Sender: TObject);

    > procedure Option2Click(Sender: TObject);

    > procedure ProgramEnd1Click(Sender: TObject);

    > procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);

    > private

    > //procedure WndProc(var Message: TMessage); override; ///

    > procedure Load_Control1;

    > procedure Db_Work(X_tmp: String);

    > function Find_name(S_tmp: string): string;

    > procedure NewChkClick(Sender: TObject);

    > procedure Delay(millisecs: longint);

    > procedure NewScroll_timeClick(Sender: TObject);

    > procedure NewScroll_minClick(Sender: TObject);

    > procedure NewLableMouseup(Sender: TObject; Button:

    > TMouseButton; Shift: TShiftState; X, Y: Integer);

    > { Private declarations }

    > public

    > //procedure ChangeColor(Sender: TObject; Msg: Integer); ///

    > { Public declarations }

    > end;

    > var

    > Form1: TForm1;

    > Bun_time: String;

    > db1 : tadoconnection;

    > rs : tadoquery;

    > implementation

    >

    > uses Unit2, Unit3;

    > {$R *.DFM}

    > procedure TForm1.FormCreate(Sender: TObject);

    > begin

    > db1 := datamodule3.db;

    > rs := datamodule3.rs;

    > lbl_Chk.Caption := 'Start';

    >

    > {db1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +

    > 'Data Source=' + ExtractFilePath(ParamStr(0)) +

    > 'nopt_ion.mdb;Persist Security Info=False';

    > rs.Connection := db1; }

    >

    > Load_Control1;

    > timer1.Interval := 5000 ;

    >

    > end;

    > procedure TForm1.Load_Control1;

    > var

    > rec : integer;

    > N_cnt : integer;

    > H_size: integer;

    > str : string;

    > NewChk: array of TCheckbox;

    > Newtxt_Time: array of Tedit;

    > NewScroll_time: array of TScrollBar;

    > Newtxt_Min: array of Tedit;

    > NewScroll_min: array of TScrollBar;

    > NewLable: array of TLabel;

    >

    > begin

    > H_size := 30;

    > str := 'select daily,start_bun,start_cho,script,caption,visible from ' +

    > 'opt_ion where visible = true';

    > rs.SQL.Clear;

    > rs.SQL.text := str;

    > rs.Open;

    > rec := rs.Recordset.Get_RecordCount;

    > SetLength(NewChk , rec);

    > SetLength(Newtxt_Time , rec);

    > SetLength(NewScroll_time, rec);

    > SetLength(Newtxt_Min , rec);

    > SetLength(NewScroll_min , rec);

    > SetLength(NewLable , rec);

    >

    > if rec = 0 then begin

    > rs.close;

    > exit;

    > end;

    >

    > rs.first;

    > for N_cnt := 0 to rec - 1 do begin

    > NewChk[n_cnt] := TCheckbox.Create(self);

    > Newtxt_Time[n_cnt] := Tedit.Create(self);

    > NewScroll_time[n_cnt] := TScrollBar.Create(self);

    > Newtxt_Min[n_cnt] := Tedit.Create(self);

    > NewScroll_min[n_cnt] := TScrollBar.Create(self);

    > NewLable[n_cnt] := TLabel.Create(self);

    >

    > with NewChk[n_cnt] do begin

    > Parent := form1;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(30,H_size,195 ,18) ;

    > Caption := rs.FieldbyName('caption').AsString;

    > Checked := rs.FieldbyName('daily').Asboolean;

    > name := 'NewChk'+ inttostr(n_cnt);

    > visible := true;

    > OnClick := NewChkClick;

    > Show;

    > end;

    >

    > with Newtxt_Time[n_cnt] do begin

    > Parent := form1;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(NewChk[n_cnt].Left +140 ,H_size,30,18) ;

    > Text := rs.FieldbyName('start_bun').AsString;

    > name := 'Newtxt_Time'+ inttostr(n_cnt);

    > visible := true;

    > Enabled := False;

    > Show;

    > end;

    > with NewScroll_time[n_cnt] do begin

    > Parent := form1;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(Newtxt_Time[n_cnt].left + 30,H_size+1,20,20) ;

    > min := 0;

    > max := 2;

    > name := 'NewScroll_time'+ inttostr(n_cnt);

    > Position := 1;

    > OnChange := NewScroll_timeClick;

    > Show;

    > end;

    > with Newtxt_Min[n_cnt] do begin

    > Parent := Form1;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(NewScroll_time[n_cnt].Left + 30,H_size,30,18) ;

    > Text := rs.FieldbyName('start_cho').AsString;

    > name := 'Newtxt_Min'+ inttostr(n_cnt);

    > visible := True;

    > Enabled := False;

    > Show;

    > end;

    >

    > with NewScroll_min[n_cnt] do begin

    > Parent := Form1;

    > SetBounds(Newtxt_Min[n_cnt].left + 30,H_size+1,20,20) ;

    > min := 0;

    > max := 2;

    > name := 'NewScroll_min'+ inttostr(n_cnt);

    > Position := 1;

    > OnChange := NewScroll_minClick;

    > Show;

    > end;

    > with NewLable[n_cnt] do begin

    > Parent := form1;

    > SetBounds(NewScroll_min[n_cnt].left+25,H_size+5,100,20) ;

    > Caption := rs.FieldbyName('script').AsString;

    > name := 'NewLable'+ inttostr(n_cnt);

    > OnMouseUp := NewLableMouseup;

    > Show;

    > end;

    > rs.Next;

    > H_size := H_size + 30;

    > end; //'For end

    > form1.Height := NewLable[n_cnt-1].Top + 100;

    > rs.Close;

    > Last_cnt.Caption := Inttostr(rec -1);

    > NewChk := nil;

    > Newtxt_Time := nil;

    > NewScroll_time := nil;

    > Newtxt_Min := nil;

    > NewScroll_min := nil;

    > NewLable := nil;

    > end;

    > **********************************************************************************

    >

    >

    > Form2가 실행되는데 약 25초 소스

    > **********************************************************************************

    > procedure TForm1.Option2Click(Sender: TObject);

    >

    > begin

    > form1.Destroy;

    > if Assigned(Form2) then

    > form2.show

    > else

    > Application.CreateForm(TForm2, Form2);

    > Application.Run;

    >

    > end;

    > **********************************************************************************

    >

    >

    > Form2의 FormCreate 소스

    > **********************************************************************************

    > unit Unit2;

    >

    > interface

    >

    > uses

    > Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    > StdCtrls, Db, ADODB;

    >

    > type

    > TForm2 = class(TForm)

    > Lbl_Chk: TLabel;

    > Button1: TButton;

    > procedure FormCreate(Sender: TObject);

    > procedure Button1Click(Sender: TObject);

    > procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);

    > private

    > procedure Combo_Fill;

    > procedure NewCheckClick(Sender: TObject);

    > procedure NewTextKeyPress(Sender: TObject; var Key: Char);

    > { Private declarations }

    > public

    > { Public declarations }

    > end;

    >

    > var

    > Form2: TForm2;

    > db1 : tadoconnection;

    > rs : tadoquery;

    > implementation

    >

    > uses Unit1, Unit3;

    >

    > {$R *.DFM}

    >

    > procedure TForm2.FormCreate(Sender: TObject);

    > var

    > rec,N_cnt : integer;

    > H_size : integer;

    > NewCheck : array of TCheckbox;

    > NewText : array of Tedit;

    > Txt_New_Name : TEdit;

    > Cmd_Add : TButton;

    > Cbo_Del : TComboBox;

    > Cmd_Del : TButton;

    > Lbl_Scr : TLabel;

    > str : string;

    > begin

    > db1 := datamodule3.db;

    > rs := datamodule3.rs;

    > SetLength(NewCheck , rec);

    > SetLength(NewText , rec);

    > h_size := 30;

    > lbl_Chk.Caption := 'Start';

    >

    > str := 'select caption,visible from opt_ion';

    > rs.SQL.Clear;

    > rs.SQL.text := str;

    > rs.Open;

    > rec := rs.Recordset.Get_RecordCount;

    > rs.first;

    >

    > for N_cnt := 0 to rec - 1 do begin

    > NewCheck[n_cnt] := TCheckbox.Create(self);

    > NewText[n_cnt] := TEdit.Create(self);

    >

    > with NewCheck[n_cnt] do begin

    > Parent := form2;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(30,H_size,195 ,18) ;

    > visible := true;

    > OnClick := NewCheckClick;

    > Caption := rs.FieldbyName('caption').AsString;

    > Checked := rs.FieldbyName('visible').Asboolean;

    > name := 'NewChk'+ inttostr(n_cnt);

    > Show;

    > end;

    > with NewText[n_cnt] do begin

    > Parent := form2;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(NewCheck[n_cnt].left + 160,H_size,150 ,18) ;

    > visible := true;

    > OnKeyPress := NewTextKeyPress;

    > Text := rs.FieldbyName('caption').AsString;

    > name := 'NewText'+ inttostr(n_cnt);

    > Show;

    > end;

    > H_size:=H_size +30;

    > rs.Next

    > end; //for end

    > rs.Close;

    >

    > Txt_New_Name := TEdit.Create(self);

    > with Txt_New_Name do begin

    > Parent := form2;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(NewCheck[n_cnt-1].left,H_size,100 ,18) ;

    > visible := true;

    > // OnClick := NewChkClick;

    > name := 'Txt_New_Name';

    > Text := '';

    > Show;

    > end;

    >

    > Cmd_Add := TButton.Create(self);

    > with Cmd_Add do begin

    > Parent := form2;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(Txt_New_Name.left + Txt_New_Name.Width ,H_size,30 ,18) ;

    > visible := true;

    > // OnClick := NewChkClick;

    > Caption := 'ADD';

    > name := 'Cmd_Add';

    > Show;

    > end;

    >

    > Cbo_Del := TComboBox.Create(self);

    > with Cbo_Del do begin

    > Parent := form2;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(NewText[n_cnt-1].Left ,H_size,150 ,18) ;

    > visible := true;

    > // OnClick := NewChkClick;

    > name := 'Cbo_del';

    > Text := '';

    > Show;

    > end;

    >

    > Cmd_Del := TButton.Create(self);

    > with Cmd_Del do begin

    > Parent := form2;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(Cbo_Del.left + Cbo_Del.width ,H_size,30 ,18) ;

    > visible := true;

    > // OnClick := NewChkClick;

    > Caption := 'DEL';

    > name := 'Cmd_Del';

    > Show;

    > end;

    > H_size:=H_size +30;

    >

    > Lbl_Scr := TLabel.Create(self);

    > with Lbl_Scr do begin

    > Parent := form2;

    > Font.Name := '돋움체';

    > Font.Size := 9;

    > SetBounds(30,H_size,195 ,18) ;

    > visible := true;

    > // OnClick := NewChkClick;

    > Caption := '스크립트 찾기';

    > name := 'Lbl_scr';

    > Show;

    > end;

    >

    > form2.height := lbl_scr.top + 80;

    > Combo_Fill;

    > lbl_Chk.Caption := 'End';

    > NewCheck := nil;

    > NewText := nil;

    > end;

    > **********************************************************************************

  • Profile
    이용 2000.09.22 12:03


    > > Form2의 FormCreate 소스

    > > **********************************************************************************

    > > procedure TForm2.FormCreate(Sender: TObject);

    > > var

    > > rec,N_cnt : integer;

    > > H_size : integer;

    > > NewCheck : array of TCheckbox;

    > > NewText : array of Tedit;

    > > Txt_New_Name : TEdit;

    > > Cmd_Add : TButton;

    > > Cbo_Del : TComboBox;

    > > Cmd_Del : TButton;

    > > Lbl_Scr : TLabel;

    > > str : string;

    > > begin

    > > db1 := datamodule3.db;

    > > rs := datamodule3.rs;

    SetLength(NewCheck , rec); //여기

    SetLength(NewText , rec); //여기에 문제가 있었네요..

    > > h_size := 30;

    > > lbl_Chk.Caption := 'Start';

    > >

    > > str := 'select caption,visible from opt_ion';

    > > rs.SQL.Clear;

    > > rs.SQL.text := str;

    > > rs.Open;

    > > rec := rs.Recordset.Get_RecordCount;

    SetLength(NewCheck , rec); // 이리로 옮기니 잘 되네요..

    SetLength(NewText , rec); // 당연 한거였는데..

    > > rs.first;



    그런데 윗 부분에서 배열의 값을 정의할때 rec의 값이 0 이 아닐런지,

    integer를 선언하면 기본값으로 0 이 되지 않나요?



    그런데 궁금한것은 바꾸기 전처럼 해도(비록 속도는 느리지만) 실행이 되네요.



    배열의 값에 0 이 들어간 상태에서 어떻게 rec := 7 인 경우

    이 값이 생성되서 콘트롤이 생성 되었는지..쩝



    어렵네요..