Не могу себе позволить не обратиться к вам еще раз потому что сам не вытягиваю - знаний мало. Значит намудрил я здоровенный клас и его конструкторы-деструктори:
| Код | type CTableField = class //Клас, який описує поле для вводу Lab:TLabel; Ed:TControl; field_name:string[20]; description:string[50]; field_type:string[20]; field_class:string[20]; destructor Destroy; override; end;
type CTableFieldCollecton = class(TObjectList) public constructor Create(InputParent:TWinControl; Section:string); destructor Destroy; override; end;
type FMainTableForm = class //клас який описує форму головної таблиці MainTableFormName:TComponentName; MainPanel:TPanel; TopPanel:TPanel; CloseExpandButton:TSpeedButton; MainScroll:TScrollBox; ScrollPanel:TPanel; BottomPanel:TPanel; SaveButton:TButton; FieldCollection:CTableFieldCollecton; public constructor Create(AOwner:TWinControl;Section:string; Main:boolean); destructor Destroy; override; procedure SaveButtonClick(Sender:TObject); procedure CloseExpandButtonButtonClick(Sender:TObject); end;
var IniFile:TIniFile; // Всім відомий іні-файл CTableFields:TObjectList; // Список полів для форми які беруться з іні-файлу //TableFieldCollection:CTableFieldCollecton; TableField:CTableField; //Поле яке створюється і додається в список полів MainTableForm:FMainTableForm; //Форма для головної таблиці //SubTableForm:FSubTableForm; //Форма для додаткович, звязаних таблиць implementation
destructor CTableFieldCollecton.Destroy; var i:cardinal; begin for i := 0 to Count - 1 do Items[i].Destroy; inherited; end;
destructor CTableField.Destroy; begin if Lab<>nil then Lab.Free; if Ed<>nil then Ed.Free; inherited; end;
destructor FMainTableForm.Destroy; begin FreeAndNil(FieldCollection); if CloseExpandButton<>nil then CloseExpandButton.Free; if TopPanel<>nil then TopPanel.Free; SaveButton.Free; ScrollPanel.Free; BottomPanel.Free; MainScroll.Free; MainPanel.Free; inherited; end;
procedure FMainTableForm.SaveButtonClick(Sender:TObject); begin MainTableForm.Destroy; end;
constructor FMainTableForm.Create(AOwner:TWinControl; Section:string; Main:boolean); begin
MainTableFormName:=Section; MainPanel:=TPanel.Create(AOwner); MainPanel.Parent:=AOwner; MainPanel.Align:=alClient; MainPanel.Visible:=True; if not(Main) then begin TopPanel:=TPanel.Create(MainPanel); TopPanel.Parent:=MainPanel; TopPanel.Align:=alTop; TopPanel.Height:=15; TopPanel.Visible:=True;
CloseExpandButton:=TSpeedButton.Create(TopPanel); CloseExpandButton.Parent:=TopPanel; CloseExpandButton.Height:=15; CloseExpandButton.Width:=60; CloseExpandButton.Anchors:=[akLeft,akTop]; CloseExpandButton.Top:=0; CloseExpandButton.Left:=20; CloseExpandButton.OnClick:=CloseExpandButtonButtonClick; end;
MainScroll:=TScrollBox.Create(MainPanel); MainScroll.Parent:=MainPanel; MainScroll.Align:=alClient; MainScroll.Visible:=True;
ScrollPanel:=TPanel.Create(MainScroll); ScrollPanel.Parent:=MainScroll; ScrollPanel.Align:=alTop; ScrollPanel.Height:=400; ScrollPanel.Visible:=True;
FieldCollection:=CTableFieldCollecton.Create(ScrollPanel,Section);
BottomPanel:=TPanel.Create(MainPanel); BottomPanel.Parent:=MainPanel; BottomPanel.Align:=alBottom; BottomPanel.Height:=40; BottomPanel.Visible:=True;
SaveButton:=TButton.Create(BottomPanel); SaveButton.Parent:=BottomPanel; SaveButton.Width:=100; SaveButton.Height:=20; SaveButton.Anchors:=[akRight,akTop]; SaveButton.Top:=10; SaveButton.Left:=400; SaveButton.Caption:='"Save"'; SaveButton.Visible:=True; SaveButton.OnClick:=SaveButtonClick; end;
constructor CTableFieldCollecton.Create(InputParent:TWinControl; Section:string); var sections:TStringList; st:string; res:widestring; i,p,duz1,duz2,field_size,top_value,top_offset:cardinal; visible_field:boolean; begin try IniFile:=TIniFile.Create(ExtractFilePath(paramstr(0))+'ini\setup.ini'); with IniFile do begin if SectionExists(Section+'_ALL') then begin try sections:=TStringList.Create; ReadSectionValues(Section+'_ALL',sections); res:=''; top_value:=50; for i:=0 to sections.Count-1 do begin st:=sections.Strings[i];
visible_field:=true; p:=pos('*',st); if p>0 then begin visible_field:=false; System.Delete(st,p,1); end;
p:=pos('=',st); TableField:=CTableField.Create; TableField.field_name:=copy(st,1,p-1); System.delete(st,1,p); p:=pos('^',st); TableField.description:=copy(st,1,p-1); System.delete(st,1,p); p:=pos('^',st); if p>0 then begin TableField.field_type:=copy(st,1,p-1); TableField.field_class:=copy(st,p+1,Length(st)-(p)); end else TableField.field_type:=copy(st,1,Length(st));//TableFields[i].field_type:=copy(st,1,Length(st)); // res:=res+'"'+ TableField.field_name+'"'+TableField.description+'"'+TableField.field_type+'"'+TableField.field_class+'"'+chr(13)+chr(10); if pos('VARCHAR2',TableField.field_type)>0 then begin duz1:=pos('(',TableField.field_type); duz2:=pos(')',TableField.field_type); if (duz1>0)and(duz2>0)and(duz2>duz1) then begin field_size:=StrToInt(copy(TableField.field_type,duz1+1,duz2-duz1-1)); end else field_size:=15; if field_size<=40 then begin TableField.Ed:=TEdit.Create(InputParent); with TEdit(TableField.Ed) do begin if visible_field then top_offset:=25; //top_value:=top_value+25; Width:=field_size*9; Height:=20; Text:=IntToStr(field_size); end; end else begin TableField.Ed:=TMemo.Create(InputParent); with TMemo(TableField.Ed) do begin //Задаю свойства if visible_field then top_offset:=Height+5;
end; end; end else if pos('NUMBER',TableField.field_type)>0 then begin TableField.Ed:=TSpinEdit.Create(InputParent); with TSpinEdit(TableField.Ed) do begin //Задаю свойства if visible_field then top_offset:=25;
end; end else if pos('DATE',TableField.field_type)>0 then begin TableField.Ed:=TMaskEdit.Create(InputParent); with TMaskEdit(TableField.Ed) do begin //Задаю свойства if visible_field then top_offset:=25; end; end else begin //BLOB TableField.Ed:=TEdit.Create(InputParent); with TEdit(TableField.Ed) do begin if visible_field then top_offset:=25; //Задаю свойства end; end; if visible_field then begin TableField.Lab:=TLabel.Create(InputParent); with TableField.Lab do begin //Задаю свойства end; end; with TableField.Ed do begin Name:=TableField.field_name; Left:=230; Top:=top_value; if visible_field then top_value:=top_value+top_offset; Parent:=InputParent; Visible:=visible_field; end; InputParent.Height:=top_value+20; Add(TableField); end; finally sections.Free; //ShowMessage(res); end; end; end; finally IniFile.Free; end; end;
|
Код читает ини-файл выбирает свойства обьектов и зоздает форму для ввода. Все это работает. Я в главной форме двумя кнопками создаю обьекты з разными параметрами:
| Код | procedure TMainForm.BtnObjektClick(Sender: TObject); begin if MainTableForm<>nil then MainTableForm.free; MainTableForm:=FMainTableForm.Create(MainForm,'T_Objekt',False); end;
procedure TMainForm.BtnOsobaClick(Sender: TObject); begin if MainTableForm<>nil then MainTableForm.free; MainTableForm:=FMainTableForm.Create(MainForm,'T_Osoba',True); end;
|
если я жму на кнопки на основной форме, даже по несколько раз - формы переключаються или пеперисовываються и как-будто все нормально, но если я нажимаю на кнопку которую создал в класе SaveButtonClick - форма исчезает (ну да, так задуманно) но при клике на кнопках для создания вилетает Инвалид Поинтер Оператион. Очень прошу помочь! |